# Set the environmental variables for compiling
#
# WATCOM must be defined in the environment
# ILINK must be available in the PATH

# -5s pentium instructions, stack based calling
# -bm multi-thread environment
# -s remove stack checking
# -wx maximum warning level
# -ox optimization
# -zq quiet
# -zp4 dword structure packing
# -fpi inline 387 instructions
# -ecs default to _syscall
CFLAGS=-6s -bm -s -wx -ox -zq -zp4 -fpi -ecs
%INCLUDE=.;$(%WATCOM)\H;$(%WATCOM)\H\OS2;
%LIB=$(%WATCOM)\lib386;$(%WATCOM)\lib386\os2;

OBJS= test.obj afunc.obj

all: testw.exe testi.exe runit

test.obj: test.c
    wcc386 $(CFLAGS) $[@

afunc.obj: afunc.asm
    alp $[@

testw.exe: $(OBJS)
	@%create $^&.lrf
	@%append $^&.lrf system os2v2
	@%append $^&.lrf option quiet,map,eliminate,caseexact,verbose
	@%append $^&.lrf sort
	@%append $^&.lrf debug all
	@%append $^&.lrf name $^@
	@for %f in ($(OBJS)) do @%append $^&.lrf file %f
	wlink @$^&.lrf
	@%erase $^&.lrf

testi.exe: $(OBJS)
	@%create $^&.lnk
	@%append $^&.lnk /map:$^&.map
	@%append $^&.lnk /out:$^@
	@for %f in ($(OBJS)) do @%append $^&.lnk %f
	ilink /exepack:2 /oldcpp @$^&.lnk
	@%erase $^&.lnk
	
runit: .symbolic
  @echo testi and testw should produce the same result
  testi
  testw	

clean: .symbolic
  @if exist *.obj @del *.obj
  @if exist *.exe @del *.exe
  @if exist *.map @del *.map

