#
# Set the environmental variables for compiling
#
!ifndef %WATCOM # if not defined in the environment
!error WATCOM must be set in the environment.
!endif
WATCOM=$(%WATCOM)

!ifndef %DDK # if not defined in the environment
!error DDK must be set in the environment.
!endif
DDK=$(%DDK)

VENDOR=Your Name
VERSION=1.00

!ifdef %DRV32KIT
DRV32KIT=$(%DRV32KIT)
!else
DRV32KIT=..
!endif

.ERASE

.SUFFIXES:
.SUFFIXES: .sys .exe .obj .asm .inc .def .lrf .lst .sym .map .cpp .c .h .lib .dbg .dll .itl .hlp

NAME=PciAc5

%PATH=$(DRV32KIT);$(DDK)\base\TOOLS;$(WATCOM)\BINP;$(WATCOM)\BINW;
%INCLUDE=.;$(DRV32KIT);$(WATCOM)\H;$(DDK)\base\h;$(DDK)\base32\h;$(DDK)\base\inc;
%LIB=$(WATCOM)\lib386;$(WATCOM)\lib386\os2;$(DDK)\base32\LIB;

CC=wcc386
ASM=wasm
LINK=wlink
CFLAGS=-q -bt=os2 -6s -bm -wx -s -orli -zp4 -zq -zm
C32DRVFLAGS=-q -bt=os2 -6s -olinar -s -ze -zl -zq -zfp -zgp -ms -wx -zp4 -za99
CFLAGS=-q -bt=os2 -6s -bm -wx -s -orli -zp4 -zq -zm
AFLAGS=-q -6p -bt=os2 -wx -d1

# Inference rules
.c.obj: .AUTODEPEND
  $(CC) $(C32DRVFLAGS) $*.c
  wdis -l -s -e -p $*

.asm.obj: .AUTODEPEND
  $(ASM) $(AFLAGS) $*.asm
  wdis -l -s -e -p $*

.c.exe: .AUTODEPEND
  wcc386 $(CFLAGS) $*.c
  wlink debug all format os2 flat file $*.obj option eliminate,quiet

# Object file list
OBJS=PciAc5.obj

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

PciAc5.obj: PciAc5.c version.h

$(NAME).sys: $(OBJS) makefile $(DRV32KIT)\Drv32.lib $(DDK)\base\lib\os2386p.lib
  @%create $^*.lrf
  @%append $^*.lrf name $(NAME).sys
  @%append $^*.lrf format os2 lx phys
  @%append $^*.lrf option mixed1632,nostub,align=4
  @%append $^*.lrf option quiet,map,int,verbose,caseexact,eliminate sort global
  @%append $^*.lrf option stack=0
  @%append $^*.lrf segment _TEXT PRELOAD CONFORMING IOPL DYNAMIC
  @%append $^*.lrf segment TYPE DATA SHARED
  @AddToFile.cmd $^*.lrf,option description,BLDLEVEL,$(VENDOR),$(VERSION),PCI AC5 driver (c) %Y $(VENDOR)
  @%append $^*.lrf file $(DRV32KIT)\Drv32.lib(header)
  @for %f in ($(OBJS)) do @%append $^*.lrf file %f
  @%append $^*.lrf library $(DRV32KIT)\Drv32.lib
  @%append $^*.lrf library $(DDK)\base32\lib\kee.lib
  $(LINK) @$^*.lrf
  @%erase $^*.lrf

version.h: .ALWAYS
  @%create $^@
  @%append $^@ //This file is automatically created by makefile
  @%append $^@ $#define DVENDOR "$(VENDOR)"
  @%append $^@ $#define DFILE "$(NAME).sys"
  @AddToFile.cmd $^@,$#define DYEAR,DATEYEAR
  @AddToFile.cmd $^@,$#define DMONTH,DATEMONTH
  @AddToFile.cmd $^@,$#define DDAY,DATEDAY
  @AddToFile.cmd $^@,$#define DVERMAJOR,VERSIONMAJOR,$(VERSION)
  @AddToFile.cmd $^@,$#define DVERMINOR,VERSIONMINOR,$(VERSION)

test.exe: test.c makefile

$(NAME).sym: $(NAME).map
  wat2map.cmd $(NAME).map $(NAME).ma1
  @mapsym $(NAME).ma1
  @%erase $(NAME).ma1

clean: .symbolic
  @if exist *.map @del *.map
  @if exist *.lst @del *.lst
  @if exist *.obj @del *.obj
  @if exist *.sys @del *.sys
  @if exist *.sym @del *.sym
  @if exist *.exe @del *.exe
  @if exist version.h @del version.h
