# Scoundrel65 reference implementation makefile

PROJNAME=scoundrel
CFILES=scoundrel.c
PBTDIR=platform-build-tools
CCBUILD=cl65 --standard c89 -O -Os
Z80BUILD=zcc
BUILDDIR=build

$(PROJNAME): bdir
	$(CC) -std=c89 -O2 -o $(BUILDDIR)/scoundrel $(CFILES)

bdir:
	mkdir -p $(BUILDDIR)

a2-build: bdir
	$(CCBUILD) -t apple2 -C apple2-system.cfg -o $(BUILDDIR)/$(PROJNAME)-a2.bin $(CFILES)

a2: a2-build
	cp $(PBTDIR)/apple2/tpl.dsk $(PROJNAME)-a2.dsk
	java -jar $(PBTDIR)/apple2/ac.jar -p $(PROJNAME)-a2.dsk $(PROJNAME).system sys < $$(cl65 --print-target-path)/apple2/util/loader.system
	java -jar $(PBTDIR)/apple2/ac.jar -as $(PROJNAME)-a2.dsk $(PROJNAME) bin < $(BUILDDIR)/$(PROJNAME)-a2.bin
	mv $(PROJNAME)-a2.dsk $(BUILDDIR)/

a2e-build: bdir
	$(CCBUILD) -t apple2enh -C apple2enh-system.cfg -o $(BUILDDIR)/$(PROJNAME)-a2e.bin $(CFILES)

a2e: a2e-build
	cp $(PBTDIR)/apple2/tpl.dsk $(PROJNAME)-a2e.dsk
	java -jar $(PBTDIR)/apple2/ac.jar -p $(PROJNAME)-a2e.dsk $(PROJNAME).system sys < $$(cl65 --print-target-path)/apple2enh/util/loader.system
	java -jar $(PBTDIR)/apple2/ac.jar -as $(PROJNAME)-a2e.dsk $(PROJNAME) bin < $(BUILDDIR)/$(PROJNAME)-a2e.bin
	mv $(PROJNAME)-a2e.dsk $(BUILDDIR)/

atari8bit: bdir
	$(CCBUILD) -t atari -o $(BUILDDIR)/$(PROJNAME)-atari.bin $(CFILES)

c64: bdir
	$(CCBUILD) -t c64 -o $(BUILDDIR)/$(PROJNAME)-c64.bin $(CFILES)

c16: bdir
	$(CCBUILD) -t c16 -o $(BUILDDIR)/$(PROJNAME)-c16.bin $(CFILES)

c128: bdir
	$(CCBUILD) -t c128 -o $(BUILDDIR)/$(PROJNAME)-c128.bin $(CFILES)

pet: bdir
	$(CCBUILD) -t pet -o $(BUILDDIR)/$(PROJNAME)-pet.bin $(CFILES)

plus4: bdir
	$(CCBUILD) -t plus4 -o $(BUILDDIR)/$(PROJNAME)-plus4.bin $(CFILES)

msx: bdir
	$(Z80BUILD) +msx -create-app -subtype=rom $(CFILES) -o $(PROJNAME)
	mv $(PROJNAME).rom $(BUILDDIR)/$(PROJNAME)-msx.rom
	rm -f $(PROJNAME) *.bin *.img

zxspec: bdir
	$(Z80BUILD) +zx -lndos -clib=ansi -pragma-define:ansicolumns=40 -create-app $(CFILES) -o $(PROJNAME)
	mv $(PROJNAME).tap $(BUILDDIR)/$(PROJNAME)-zxspec.tap
	rm $(PROJNAME)

all: $(PROJNAME) a2 a2e atari8bit c64 c16 c128 pet plus4 zxspec msx

clean:
	rm -rf $(BUILDDIR) *.o
