# NMAKE makefile for generic TSR
# example: C:\UNDOC>nmake tsrfile.exe

# can be overriden from environment with NMAKE /E
# example:
#   C:\UNDOC>set swap=1
#   C:\UNDOC>nmake /e tsrfile.exe
#
#   C:\UNDOC>set no_disk=1
#   C:\UNDOC>nmake /e tsrmem.exe
SWAP = 0
NO_DISK = 0

!IF $(SWAP)
DOSSWAP = -DDOS_SWAP
DOSSWAP_O = dosswap.obj
!ENDIF

!IF $(NO_DISK)
USES_DISK = 
!ELSE
USES_DISK = -DUSES_DISK
!ENDIF

# defines the key components of the generic TSR:
#   TSREXAMP.C - main
#   INDOS.C - InDOS, critical error flag
#   PSP.C - Set PSP, Get PSP
#   EXTERR.C - Extended error save and restore
#   TSRUTIL.ASM - Miscellaneous routines
#   STACK.ASM - Stack save and restore 
#   DOSSWAP.C - Optional use of DOS Swappable Data Area (SDA)
UNDOC_OBJS = indos.obj psp.obj exterr.obj

TSR_OBJS = tsrexamp.obj $(UNDOC_OBJS) $(DOSSWAP_O) \
    tsrutil.obj stack.obj

# command to turn a .C file into an .OBJ file
.c.obj:
    cl -AS -Ox -Zp -c -W3 -DTSR $(USES_DISK) $(DOSSWAP) $*.c

# command to turn an .ASM file into an .OBJ file
.asm.obj:
    masm -ml $*.asm;

# special handling for MULTUTIL.ASM
multutil.obj:  tsrutil.asm
    masm -ml -DMULTI tsrutil,multutil;

multstk.obj:  stack.asm
    masm -ml -DMULTI stack,multstk;

# make the file-browser sample TSR
tsrfile.exe:  $(TSR_OBJS) file.obj 
    link /far/noi $(TSR_OBJS) file,tsrfile.exe;

# make the MCB-walker sample TSR
tsrmem.exe:  $(TSR_OBJS) mem.obj put.obj
    link /far/noi $(TSR_OBJS) mem put,tsrmem.exe;

# make the INT 2Eh command-interpreter sample TSR
INT2E_OBJS = test2e.obj send2e.obj have2e.obj do2e.obj
INT2E = test2e send2e have2e do2e

tsr2e.exe: $(TSR_OBJS) $(INT2E_OBJS) put.obj
    link /far/noi $(TSR_OBJS) $(INT2E) put,tsr2e;

# make the non-pop-up PRINT add-on
multi.exe: multi.obj $(UNDOC_OBJS) multutil.obj multstk.obj
    link /far/noi multi $(UNDOC_OBJS) multutil multstk,multi;
