# be able to access local files...
GFORTHPATH:=$(shell pwd)/site-forth:$(GFORTHPATH):$(shell pwd)

all:	nforth.rom nforthc.bin nforthg.bin

clean:
	rm -f nforth.rom nforthc.bin nforthg.bin

force:

FORTHCOMMON=kernel.fs dict.fs compile.fs interp.fs user.fs constant.fs init.fs \
	site-forth/cross.fs
FORTH99=99build.fs 99test.fs 99simple.fs 99equs.fs 99asm.fs 99prims.fs 99config.fs \
	compile.fs common.fs commonhash.fs files.fs interp.fs
ROM99=nforth.tsm dev.inc general.inc term.inc int.inc kbd.inc test.inc video.inc ram.inc

nforth.prm nforthc.bin nforthg.bin: $(FORCE) nforth0.rom $(FORTH99) $(FORTHCOMMON)
	rm -f list.lst
# 99test.fs builds a basic kernel
	gforth -e ": get-rom-addr `perl romaddr.pl <nforth0.rom` ;" 99build.fs -e bye
	@if ! grep 'Nothing' < list.lst &>/dev/null; then tail list.lst; fi

nforth0.rom: $(FORCE) $(ROM99) #nforth.prm 
	../../bin/tiasm nforth.tsm -r nforth0.rom nforthc.lst 

#nforthg.bin: nforthg0.bin nforthg1.bin
#	cat nforthg0.bin nforthg1.bin >nforthg.bin
#	dd if=/dev/zero bs=512 count=1 >>nforthg.bin

nforth.rom: $(FORCE) nforth.prm nforth0.rom
	cp nforth0.rom nforth.rom
	ADDR="`perl romaddr.pl <nforth0.rom`" && \
	LEFT="$$[8192-$$ADDR]" && \
	dd if=nforth.prm of=nforth.rom bs=1 seek=$$ADDR count=$$LEFT

