# Produce OS/2 1.x (16-bit) executable using Watcom C
# This has the C library statically-linked (s = static)
# Build with pdmake -f makefile.oss
# or wmake -h -e -a -ms -f makefile.oss

# Choose t (tiny), s (small), m (medium), c (compact), l (large), h (huge)
MODELC=h
# Choose long form of above name, required by wasm instead of wcl
MODELA=huge

# If you want to produce a COM file, uncommment this, and follow the
# instructions further down
#MAKECOM=-DMAKECOM

# If you want to use a 32-bit size_t in huge memory model, uncomment this
SZ4=-D__SZ4__



CC=wcl
COPTS=$(SZ4) -zdf -D__16BIT__ -I. -I..\src -oneatx \
      -r -ecc -zp1 -q -w -c -I. -m$(MODELC) -zl -D__OS2__ -fpi87 -s -zu
# Adding -d2 allows you to get source code in the disassembly
# (wdis -l -s), but you need to switch off optimization (-oneatx)

pdptest.exe: os1strt.obj pdptest.obj stdio.obj string.obj stdlib.obj \
       start.obj time.obj errno.obj assert.obj signal.obj locale.obj \
       ctype.obj setjmp.obj math.obj fpfuncsw.obj dossupa.obj dossupc.obj
  if exist watcom.lib del watcom.lib
  wlib -b -q watcom +os1strt.obj
  wlib -b -q watcom +stdio.obj
  wlib -b -q watcom +string.obj
  wlib -b -q watcom +stdlib.obj
  wlib -b -q watcom +start.obj
  wlib -b -q watcom +time.obj
  wlib -b -q watcom +errno.obj
  wlib -b -q watcom +assert.obj
  wlib -b -q watcom +signal.obj
  wlib -b -q watcom +locale.obj
  wlib -b -q watcom +ctype.obj
  wlib -b -q watcom +setjmp.obj
  wlib -b -q watcom +math.obj
  wlib -b -q watcom +fpfuncsw.obj
  wlib -b -q watcom +dossupa.obj
  wlib -b -q watcom +dossupc.obj
# To create a COM file, make it "Form dos com" and change the name to .com
# Stack size has no meaning for .com (the SP will be set by the OS, and the
# SS will be set to the CS/DS/ES). Also os1strt.obj needs to come first
# for a COM file, as the IP is always set to 0100H. Also it needs to be
# built with -mt and memmodel=tiny. If you build a .exe instead of a .com
# with all of that in place, the utility exe2bin, if available, can be
# used to convert a .exe into a .com if you are using a linker that
# can't directly produce a .com file.
# Because we are linking os1strt first, we are required to use the
# dosseg option, for some reason, because we need the stack to come last,
# so that the calculations in os1strt.asm are accurate with regard to
# releasing memory.
#  wlink File os1strt.obj,pdptest.obj Name pdptest.exe Form dos Library watcom.lib Option quiet,stack=8192,start=___asmstart,map,verbose,dosseg
# Use this instead for an NE executable
  wasm -zcm -q -DPDOS86 ..\src\needpdos.asm
  wlink File needpdos.obj Name needpdos.exe Form dos Option quiet,dosseg
# Note that all of these functions are in the "family API"
# from my testing (even though the Huge Incr and Shift may
# not have been originally - they seem to be now). So you
# can run "bind" on the executable if you want.
  rm -f os2.lib
  echo ++DosHugeIncr.DOSCALLS.DOSHUGEINCR.136 >temp.wat
  echo ++DosHugeShift.DOSCALLS.DOSHUGESHIFT.135 >>temp.wat
  echo ++DosExit.DOSCALLS.DOSEXIT.5 >>temp.wat
  echo ++DosOpen.DOSCALLS.DOSOPEN.70 >>temp.wat
  echo ++DosClose.DOSCALLS.DOSCLOSE.59 >>temp.wat
  echo ++DosRead.DOSCALLS.DOSREAD.137 >>temp.wat
  echo ++DosWrite.DOSCALLS.DOSWRITE.138 >>temp.wat
  echo ++DosDelete.DOSCALLS.DOSDELETE.60 >>temp.wat
  echo ++DosMove.DOSCALLS.DOSMOVE.67 >>temp.wat
  echo ++DosGetEnv.DOSCALLS.DOSGETENV.91 >>temp.wat
  echo ++DosExecPgm.DOSCALLS.DOSEXECPGM.144 >>temp.wat
  echo ++DosFreeSeg.DOSCALLS.DOSFREESEG.39 >>temp.wat
  echo ++DosAllocHuge.DOSCALLS.DOSALLOCHUGE.40 >>temp.wat
  echo ++DosChgFilePtr.DOSCALLS.DOSCHGFILEPTR.58 >>temp.wat
  echo ++DosGetDateTime.DOSCALLS.DOSGETDATETIME.33 >>temp.wat
  echo ++DosAllocSeg.DOSCALLS.DOSALLOCSEG.34 >>temp.wat
  echo ++DosCreateCSAlias.DOSCALLS.DOSCREATECSALIAS.43 >>temp.wat
  echo ++DosDevIOCtl.DOSCALLS.DOSDEVIOCTL.53 >>temp.wat
  wlib -q os2.lib @temp.wat
# This is PMCompatible (vio) by default
# Change to Form os2 full (novio) if you are building an editor etc
# that will set the terminal to raw mode, otherwise the keyboard
# may lock up
  wlink File os1strt.obj,pdptest.obj Name pdptest.exe Form os2 Library watcom.lib,os2.lib Option quiet,stack=8192,start=___intstart,map,verbose,dosseg,stub=needpdos.exe

.c.obj:
  $(CC) $(COPTS) $<

os1strt.obj: os1strt.asm
#  as86 -DWATCOM $(SZ4) -Dmemodel=$(MODELA) $(MAKECOM) os1strt.asm
#  ml -c -DWATCOM $(SZ4) -Dmemodel=$(MODELA) $(MAKECOM) os1strt.asm
  wasm -zcm -q -DWATCOM -DWATCOMC $(SZ4) -Dmemodel=$(MODELA) $(MAKECOM) os1strt.asm

dossupa.obj: dossupa.asm
#  as86 -DOS2 -DWATCOMC $(SZ4) -Dmemodel=$(MODELA) -DWATCOM dossupa.asm
#  ml -c -DOS2 -DWATCOMC $(SZ4) -Dmemodel=$(MODELA) -DWATCOM dossupa.asm
  wasm -zcm -q -DOS2 -DWATCOM -DWATCOMC $(SZ4) -Dmemodel=$(MODELA) dossupa.asm
