# This is GNU Make control file
# You need Hitech-C compiler and GNU sh-utils installed.
.SUFFIXES: .as .s .obj .lib
DESTDIR = ..
INC = -I..
LIB = ..
SCRIPTS = ..

OUT = console.lib font.lib console.inc

OBJS = kbd.obj pr64.obj
FONTS = font42.obj font64.obj

SRCS = $(OBJS:.obj=.as) $(FONTS:.obj=.as)

.as.s:
	cpp -DEXPORT= $(INC) $< $@

.s.obj:
	sh -c 'zas -o$@ $< 2>&1'

all: $(OUT)

console.lib: $(OBJS)
	libr r $@ $(OBJS)

font.lib: $(FONTS)
	libr r $@ $(FONTS)

console.inc: $(SRCS) $(SCRIPTS)/export.sed
	sh -c '{ for a in $(SRCS); do sed -f $(SCRIPTS)/export.sed < $$a; done;} >$@'


test: ttytest.obj console.lib font.lib
	sh -c 'echo "-LM -n -mtest.map -otest.obj \
		-ploader=6000h/0,adata=6000h/,text,data,bss -ploader_end=data \
		$(LIB)/ldbas0.obj \
		$< console.lib font.lib $(LIB)/string.lib \
		$(LIB)/ldbas1.obj"' \
	| hlink
# $(LIB)/math.lib
	objtohex -B0 test.obj test.bin
#	rm test.obj


install: $(OUT)
ifdef DESTDIR
	cp -f $(OUT) $(DESTDIR)
endif

uninstall:
ifdef DESTDIR
	rm -f $(OUT:%=$(DESTDIR)/%)
endif


clean:
	rm -f *.obj *.map *.sym *.lst *.s *.hex *.bin

clean-all: clean
	rm -f $(OUT)
