#------------------------------------------------------------------------------
# The KallistiOS bootable-disc payload, for the CD-DA disc.
# You need to have KallistiOS installed and the KOS_BASE environment variable
# set to its root. Then run `make` here. See `../../README.md`.
#------------------------------------------------------------------------------

TARGET = kos_cdda.elf
OBJS = main.o

# Where tests/e2e/test_bootable_disc.cpp looks for it: the root of this
# environment's folder, beside cd_root rather than inside it. mkdcdisc writes
# the executable into the filesystem itself, under the name its IP.BIN header
# declares, so a copy in the -D tree as well would hand it the same file twice.
PAYLOAD = ../kos.elf

all: rm-elf $(TARGET) $(PAYLOAD)

include $(KOS_BASE)/Makefile.rules

# Only the build products here. $(PAYLOAD) is committed and is what the test
# runs against, so it is not something a clean should take away -- the next
# build replaces it anyway.
clean: rm-elf
	-rm -f $(OBJS)

rm-elf:
	-rm -f $(TARGET)

$(TARGET): $(OBJS)
	kos-cc -o $(TARGET) $(OBJS)

# Stripped, which costs the disc nothing and the repository a great deal less:
# mkdcdisc keeps only the PT_LOAD segments, which a strip leaves alone, so the
# bytes that reach the disc are the same either way -- 1.7 MB of symbols that
# would otherwise sit in every clone. The strip is applied to the copy, so the
# build product next door stays debuggable.
$(PAYLOAD): $(TARGET)
	cp $(TARGET) $(PAYLOAD)
	$(KOS_STRIP) $(PAYLOAD)
