###############################################################################
#
# BUILD PROCEDURE
#
# "wmake"  (Watcom C/C++ WMAKE.exe)
#
# Environment variables:
#    PRODUCTION - yes/no (default no)
#    TOOLS      - Location of Build Machine "tools" directory (e.g. X:\TOOLS)
#    INCLUDE    - Should not be defined in environment
#    LIB        - Should not be defined in environment
#    PATH       - Is set by makefile to include TOOLS\OS2\DDK\TOOLS and
#                 Watcom BINP and BINW dirs (OS2 build environment) and
#                 Watcom BINNT, BINW dirs  (Windows 95/NT build environment)
#    DEVCOPY    - Optional.  Extra directory to copy driver to (for development)
#
# TOOLKITS, DDKs and Compilers:
#    Watcom C/C++ 11.0B - Installed to TOOLS\OS2\WATCOM
#    IBM OS/2 Toolkit   - Installed to TOOLS\OS2\TOOLKIT
#    IBM OS/2 DDK       - Installed to TOOLS\OS2\DDK (used for mapsym only)
#
#################################################################################

# Erase partially created targets after an error
.ERASE

.EXTENSIONS:
.EXTENSIONS: .sys .obj .asm .inc .def .lrf .ref .lst .sym .map .c .cpp .h .lib

.BEFORE
!ifndef %TOOLS
   !error Environment variable TOOLS must be set (e.g. SET TOOLS=Y:\TOOLS)
!endif
!ifndef %WATCOM
   set WATCOM=$(%TOOLS)\OS2\WATCOM
!endif
MASM60=$(%TOOLS)\OS2\MASM60
WAT=$(%WATCOM)

DDK=$(%TOOLS)\OS2\DDK
DDK_TOOLS=$(DDK)\BASE\TOOLS
DDK_LIB=$(DDK)\BASE\LIB
DDK_H=$(DDK)\BASE\H
DDK_INC=$(DDK)\BASE\INC
TK=$(%TOOLS)\OS2\TOOLKIT
TK_BIN=$(TK)\BIN
TK_LIB=$(TK)\LIB
TK_H=$(TK)\H
   set INCLUDE=
   set LIB=
   set PATH=$(WAT)\BINNT;$(WAT)\BINW;$(WAT)\BINP;$(TK_BIN)

NAME        = IOCTL90

##########################################
# Options for Watcom 32-bit C/C++ compiler
##########################################
#  -bt=os2   = Build target OS is OS/2
#  -ms       = Memory model small
#  -mf       = Memory model flat
#  -3        = Enable use of 80386 instructions
#  -4        = Optimize for 486 (assumes -3)
#  -5        = Optimize for Pentium (assumes -3)
#  -j        = char default is unsigned
#  -d1       = Include line number info in object
#              (necessary to produce assembler listing)
#  -d2       = Include debugging info for ICAT (+20KB hit in .SYS size)
#  -fo       = Specify name of produced object file
#  -hc       = Codeview style debug info (necessary for ICAT)
#  -o        = Optimization - i = enable inline intrinsic functions
#                             r = optimize for 80486 and pentium pipes
#                             s = space is preferred to time
#                             l = enable loop optimizations
#                             a = relax aliasing constraints
#                             n = allow numerically unstable optimizations
#  -s        = Omit stack size checking from start of each function
#  -zl       = Place no library references into objects
#  -wx       = Warning level set to maximum (vs 1..4)
#  -zfp      = Prevent use of FS selector
#  -zgp      = Prevent use of GS selector
#  -zq       = Operate quietly
#  -zm       = Put each function in its own segment
#  -zu       = Do not assume that SS contains segment of DGROUP

!ifeq %production yes
#undef DEBUG
!else
DEBUG=-DDEBUG
!endif

CC=wcc386
CPP=wpp386
CINC=-i=$(WAT)\H -i=$(TK_H) -i=$(WAT)\H\OS2 
CFLAGS=-5 -bt=os2 -d1 -oi -s -w4 -zq $(CINC) $(DEBUG)

##########################################
# Options for Microsoft MASM 6.00B (Last OS/2 version of MASM)
##########################################
#    -Cx Preserve case in publics
#    -Sn Supress symbol table listing
#    -Fl Generate listing

ASM     = $(MASM60)\binp\ml
AFLAGS  = -c -Cx -Sn -Fl
AINC    = -I$(DDK_INC)

##########################################
# Options for linker.
##########################################
LINK=wlink
WMAPNAME=mapfile

##########################################
# Options for Watcom disassembler
##########################################
WDISFLAGS=-e -p -l -m -s

#########################################
# Inference rules
#########################################

.c.obj: .AUTODEPEND
   $(CC) $(CFLAGS) -Fo$*.obj $*.c
   wdis -e -p -l -s $*

.cpp.obj: .AUTODEPEND
   $(CPP) $(CFLAGS) -Fo$*.obj $*.cpp
   wdis $(WDISFLAGS) $*
   
.asm.obj: .AUTODEPEND
   $(ASM) $(AFLAGS) $(AINC) -Fo$*.obj -Fl$*.lst $*.asm

OBJS1=asciinum.obj callback.obj commands.obj data.obj help.obj main.obj
OBJS2=mixerapi.obj parse.obj pddname.obj util.obj
OBJS=$(OBJS1) $(OBJS2)

all: $(NAME).exe $(NAME).sym

$(NAME).lrf: makefile
   @%write $^@ system os2v2
   @%write $^@ option quiet
   @%write $^@ option verbose
   @%write $^@ option caseexact
   @%write $^@ option symfile=$(NAME).dbg
   @%write $^@ option cache
   @%write $^@ option map=$(WMAPNAME).
   @%write $^@ name $(NAME).exe
   @for %f in ($(OBJS)) do @%append $^@ file %f
   @%write $^@ library $(TK_LIB)\OS2386.LIB
   @%write $^@ library $(TK_LIB)\MMPM2.LIB

$(NAME).exe: $(OBJS) $(NAME).lrf
   $(LINK) @$(NAME).lrf
!ifdef %DEVCOPY
   copy $*.exe %DEVCOPY%
!endif

$(NAME).sym: $(WMAPNAME)
   ..\util\wat2map $(WMAPNAME) $(NAME).map
   $(DDK_TOOLS)\MAPSYM $(NAME).map
!ifdef %DEVCOPY
   copy $*.sym %DEVCOPY%
!endif

# Enable display of environment via "wmake env"
env: .SYMBOLIC
   @set

clean: .SYMBOLIC
   @for %f in ($(OBJS)) do @if exist %f erase %f
   @if exist $(NAME).EXE erase $(NAME).EXE
   @if exist $(NAME).SYM erase $(NAME).SYM
   @if exist $(NAME).MAP erase $(NAME).MAP
   @if exist $(NAME).LRF erase $(NAME).LRF
   @if exist $(WMAPNAME) erase $(WMAPNAME)
   @if exist *.LST             erase *.LST
   @if exist *.ERR             erase *.ERR
   @if exist list              erase list
