# Makefile for the PciAc5 Device Driver
#
# Copyright (c) 2013 David Azarewicz david@88watts.net
#
# This file is part of the PciAc5 Device Driver.
#
# PciAc5 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PciAc5 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PciAc5.  If not, see <http://www.gnu.org/licenses/>.
#
#
# 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 %DRV16KIT
DRV16KIT=$(%DRV16KIT)
!else
DRV16KIT=..
!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=$(DRV16KIT);$(DDK)\base\TOOLS;$(WATCOM)\BINP;$(WATCOM)\BINW;
%INCLUDE=.;$(DRV16KIT);$(WATCOM)\H;$(DDK)\base\h;$(DDK)\base\inc;
%LIB=$(WATCOM)\lib386;$(WATCOM)\lib386\os2;$(DDK)\base\LIB;

CC=wcc
CPP=wpp
ASM=wasm
LINK=wlink
C16DRVFLAGS=-q -bt=os2 -6 -obilmr -s -ze -zl -zq -zff -zgf -ms -wx -zp4 -za99 -zu
CFLAGS=-q -bt=os2 -6s -bm -wx -s -obilmr -zp4 -zq -zm
AFLAGS=-q -6p -bt=os2 -wx -d1

# Inference rules
.c.obj: .AUTODEPEND
     $(CC) $(C16DRVFLAGS) $*.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 $(DRV16KIT)\Drv16.lib $(DDK)\base\lib\os2286.lib
    @%create $^*.lrf
    @%append $^*.lrf system os2 dll
    @%append $^*.lrf option quiet,map,verbose,caseexact,eliminate sort global
    @%append $^*.lrf name $(NAME).sys
    @AddToFile.cmd $^*.lrf,option description,BLDLEVEL,$(VENDOR),$(VERSION),PCI AC5 driver (c) %Y $(VENDOR)
    @%append $^*.lrf file $(DRV16KIT)\Drv16.lib(header)
    @for %f in ($(OBJS)) do @%append $^*.lrf file %f
    @%append $^*.lrf library $(DRV16KIT)\Drv16.lib
    @%append $^*.lrf library $(DDK)\BASE\lib\rmcalls.lib
    @%append $^*.lrf library $(DDK)\base\lib\os2286.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 DDATE,DATEL

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
