distname = unity-1.1

distsubdirs = tools source examples

distfiles = tools/*.c tools/*.h tools/Makefile tools/*.exe \
	    source/*.asm source/Makefile \
	    examples/*.asm examples/*.81 examples/*.prg examples/Makefile \
	    prgm0.prg prgm1.prg prgm2.prg prgm3.prg ti81.inc \
	    Makefile readme.html program.txt copying.txt

all:
	$(MAKE) -C tools all
	$(MAKE) -C source all
	$(MAKE) -C examples all

clean:
	$(MAKE) -C tools clean
	$(MAKE) -C source clean
	$(MAKE) -C examples clean
	rm -f doc-a.html doc-b.html doc-c.html
	rm -f list-012.html list-3.html

w32tools:
	$(MAKE) -C tools clean all CC=i586-mingw32msvc-gcc _exe=.exe
	i586-mingw32msvc-strip tools/*.exe
	rm -f tools/*.o

readme.html: prgm0.prg prgm1.prg prgm2.prg tools/listprg
	sed -n '1,/##BEGIN PRGM0-PRGM2/p' < readme.html > doc-a.html
	sed -n '/##END PRGM0-PRGM2/,/##BEGIN PRGM3/p' < readme.html > doc-b.html
	sed -n '/##END PRGM3/,$$p' < readme.html > doc-c.html
	-./tools/listprg -fh -t 'Prgm0: UDATA' prgm0.prg -t 'Prgm1: USETUP' prgm1.prg -t 'Prgm2: ULAUNCH' prgm2.prg > list-012.html
	-./tools/listprg -fh -t 'Prgm3: URELOAD' prgm3.prg > list-3.html
	cat doc-a.html list-012.html doc-b.html list-3.html doc-c.html > readme.html
	rm -f list-012.html list-3.html

dist:
	rm -rf $(distname)
	mkdir $(distname)
	set -e ; for d in $(distsubdirs) ; do \
	 mkdir $(distname)/$$d ; \
	done
	set -e ; for f in $(distfiles) ; do \
	 cp -p $$f $(distname)/$$f ; \
	done
	zip -9 $(distname).zip -r $(distname)

.PHONY: all clean w32tools dist
