PARTS=loading1.xex config/config.xex loading2.xex memsetup.xex font_dl.xex client.xex

TESTXEX=fnchat-$(shell date +%Y%m%d-%H%M).xex

VERSION:=$(shell git describe --dirty --long 2>/dev/null || echo NOGIT )+$(shell date +%Y%m%d-%H%M )@$(shell hostname -s 2>/dev/null || echo UNKNOWN )

# remove the -a if using older versions of atasm
ATASM=atasm -s -a

all: clean fnchat.xex
	[ -d /var/tnfs ] && cp fnchat.xex /var/tnfs/ || true

fnchat.xex: $(PARTS)
	cat $(PARTS) > fnchat.xex

client.xex: client

client:
	$(MAKE) -f Makefile.client VERSION=$(VERSION)

config/config.xex:
	$(MAKE) -C config VERSION=$(VERSION)

clean:
	rm -f $(PARTS) *.o src/*.o obj/atari/*.o config/*.o fnchat.xex
	$(MAKE) -f Makefile.client clean

%.xex: %.asm
	$(ATASM) -o$@ $<

memsetup.xex: memsetup.asm

loading1.xex: loading.asm
	$(ATASM) -o$@ $<

loading2.xex: loading.asm
	$(ATASM) -o$@ -DCLIENT=1 $<

font_dl.xex: font_dl.asm font.dat

test: memsetup.xex font_dl.xex
	cl65 -C src/atari.cfg -t atari -o testmain.xex src/addrs.c src/edbox.c src/screen.c src/keyclick.s uitest/test.c
	cat memsetup.xex font_dl.xex testmain.xex > test.xex

install: all
	cp fnchat.xex $(TESTXEX)
	sluk $(TESTXEX)
	scp $(TESTXEX) zapp:/var/tnfs/

atr: all
	cp atr/dos_20s.atr atr/fnchat-dos2.atr
	cp atr/dos25_sd.atr atr/fnchat-dos25.atr
	cp atr/mydos_sd.atr atr/fnchat-mydos.atr
	cp fnchat.xex atr/autorun.sys
	cp fnchat.xex atr/fnchat.ar0
	cd atr ; \
	axe -w autorun.sys fnchat-dos2.atr ; \
	axe -w autorun.sys fnchat-dos25.atr ; \
	axe -w fnchat.ar0 fnchat-mydos.atr ; \
	cp fnchat-dos2.atr fnchat-dos25.atr fnchat-mydos.atr /var/tnfs
