# Makefile for the Required Device Driver
#
# Copyright (c) 2013-2015 David Azarewicz david@88watts.net
#
# This file is part of the Required Device Driver.
#
# Required 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.
#
# Required 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 Required.  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

%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

.map.sym:
  wat2map.cmd $[@ $^*.ma1
  @mapsym $^*.ma1
  @%erase $^*.ma1

all: Driver.sys Driver.sym BaseDev.sys BaseDev.sym

.obj.sys: 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 $^*.sys
  @AddToFile.cmd $^*.lrf,option description,BLDLEVEL,$(VENDOR),$(VERSION),$^& driver (c) %Y $(VENDOR)
  @%append $^*.lrf file $(DRV16KIT)\Drv16.lib(header)
  @%append $^*.lrf file $[@
  @%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

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
