#
# NetDrv makefile
#
# -oa   Relax alias checking
# -ob   Try to generate straight line code
# -oe - expand user functions inline (-oe=20 is default)
# -oh   Enable repeated optimizations
# -oi   generate certain lib funcs inline
# -oi+  Set max inline depth (C++ only, use -oi for C)
# -ok   Flowing of register save into function flow graph
# -ol   loop optimizations
# -ol+  loop optimizations plus unrolling
# -or   Reorder for pipelined (486+ procs); not sure if good to use
# -os   Favor space over time
# -ot   Favor time over space
# -ei   Allocate an "int" for all enum types
# -zp2  Allow compiler to add padding to structs
# -zpw  Use with above; make sure you are warning free!
# -0    8088/8086 class code generation
# -s    disable stack overflow checking
# -zmf  put each function in a new code segment; helps with linking

# For this code performance is not an issue.  Make it small.

tcp_h_dir = ..\..\TCPINC\
tcp_c_dir = ..\..\TCPLIB\
common_h_dir = ..\..\INCLUDE

memory_model = -ms
compile_options = -0 $(memory_model) -DCFG_H="netdrv.cfg" -oh -ok -os -s -oa -ei -zp2 -zpw -we -zmf
compile_options += -i=$(tcp_h_dir) -i=$(common_h_dir)

tcpobjs = packet.obj arp.obj eth.obj ip.obj utils.obj timer.obj ipasm.obj udp.obj dns.obj trace.obj
objs = netdrv.obj

all : clean netdrv.exe simple.sys rename

rename : .symbolic
	@rename netdrv.exe netdrive.exe
	@rename simple.sys netdrive.sys

clean : .symbolic
	@del netdrv.exe
	@del netdrive.exe
	@del netdrive.sys
	@del *.obj
	@del *.map
	@del *.lst
	@del simple.exe
	@del simple.sys
	@del simple_tmp.asm
	@del chksum_t.*

patch : .symbolic
	..\..\utils\ptach netdrv.exe netdrv.map $(memory_model)

.asm : $(tcp_c_dir)

.cpp : $(tcp_c_dir)

.asm.obj :
	wasm -0 $(memory_model) $[*

.cpp.obj :
	wpp $[* $(compile_options)

netdrv.exe : $(tcpobjs) $(objs)
	wlink system dos option map option eliminate option stack=4096 name $@ file *.obj


simple.obj :
	bash fixdate.sh
	wasm simple_tmp.asm
	@rename simple_tmp.obj simple.obj

simple.sys : simple.obj
	wlink system dos file simple.obj
	exe2bin simple.exe simple.sys



# Special binaries for chksum code testing.  These are not normally built.

chksum_test : clean chksum_t.exe chksum_t.sys

chksum_t.exe : chksum_test.obj ipasm.obj
	wlink system dos option map option eliminate option stack=4096 name $@ file chksum_test.obj file ipasm.obj

simple_chksum_test.obj :
	bash fixdate.sh
	wasm simple_tmp.asm -dCHKSUM_TESTING
	@rename simple_tmp.obj simple_chksum_test.obj

chksum_t.sys : simple_chksum_test.obj
	wlink system dos file simple_chksum_test.obj
	exe2bin simple_chksum_test.exe chksum_t.sys
	@del simple_chksum_test.exe
