# Copyright 2005, Martin Strmberg.
#
# Makefile for FreeDOS XMS Driver
#
#
# You might need to change the following lines if you use another
# assembler, linker or compiler.

# This is for preprocessing with GCC.
CPP 	= 	gcc -E -x assembler-with-cpp -undef -Ui386

# This is for GNU as.
AS 	= 	as -ahls=$*.lst

# This is for GNU ld.
LD 	= 	ld -T link_script --oformat binary -Map $*.map -s


#
# That you'd want to change something below this line is unlikely.

.PHONY: all clean sizes

all: fdxms.sys fdxxms.sys fdxmst.sys fdxxmst.sys 
#fdxxmsdt.sys sizes

fdxms.s : fdxms.asm fdxms.inc print_string.inc xms_resident.inc
	$(CPP) $< >$@

fdxxms.s : fdxms.asm fdxms.inc print_string.inc xxms_variables.inc xxms_resident.inc xxms_nonresident.inc
	$(CPP) -DXXMS $< >$@

fdxmst.s: fdxms.asm fdxms.inc print_string.inc xms_resident.inc
	$(CPP) -DTRACE_CODE $< >$@

fdxxmst.s: fdxms.asm fdxms.inc print_string.inc xxms_variables.inc xxms_resident.inc xxms_nonresident.inc
	$(CPP) -DXXMS -DTRACE_CODE $< >$@

fdxxmsdt.s: fdxms.asm fdxms.inc print_string.inc xxms_variables.inc xxms_resident.inc xxms_nonresident.inc
	$(CPP) -DXXMS -DTRACE_CODE -DDEBUG_CODE $< >$@


# Rules.

%.sys: %.o
	$(LD) -o $@ $^

%.o: %.s
	$(AS) -o $@ $<

sizes: fdxms.map fdxmst.map fdxxms.map fdxxmst.map
	grep 'driver_end' $^ | tee sizes.txt

clean:
	-rm *.map *.o *.s *.lst
