#  This program 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 2 of the License, or 
#  (at your option) any later version.
#
#  This program 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 this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# Makefile for NOISE.SYS Version 0.6.2
# written for bcc 4, tasm 3.2 or 4.1, exe2bin

# Make optional defines (ie, "make -DLIST"):
#       -DEXE           Build EXE-format driver rather than core image
#       -DLIST          Generate a listing
#       -DCPU={3,4,5}   Build for CPU (ie, -DCPU=4 for i486)
#       -DWIN95         Build to be Win95-friendly
#       -DDEBUG         Build for testing entropy sources (no hashing/mixing)
#       -DTSC           Use CPU Timestamp Counter (if CPU={4,5} only)

# A note about Win95/MS-DOS 7 and long filenames:
#       If the long filenames cause problems with older versions of make,
#       use the following in a short batch file before making:
#
#               move initnoise.inc initnois.inc
#               move initnois.inc initnoise.inc
#               move multiplex.inc multiple.inc
#               move multiple.inc multiplex.inc
#

# Note: assumes AS, AFLAGS, CC, CFLAGS macros are already defined in
#       "builtins.mak" (Borland make.exe); otherwise define them
#       below, with requisite paths for includes, libraries, etc.

LINK = tlink
LOPT = /k

MBIN = exe2bin

COPT = -3 -mt -O2 -Z

!if $d(DEBUG)
DBG=1
!else
DBG=0
!endif

!if $d(CPU)
!else
CPU=3
!endif

AOPT = /d__DEBUG=$(DBG) /d__CPU=$(CPU)

!if $d(WIN95)
AOPT = $(AOPT) /dWIN95
!endif

!if $d(TSC)
AOPT = $(AOPT) /d__UseTSC=1
!else
AOPT = $(AOPT) /d__UseTSC=0
!endif

!if $d(LIST)
AOPT = $(AOPT) /l
!endif

.asm.obj:
  $(AS) $(AOPT) $(AFLAGS) $&.asm

.obj.exe:
  $(LINK) $(LOPT) $&.obj

.exe.sys:
!if $d(EXE)
  copy $&.exe $&.sys
!else
  $(MBIN) $&.exe $&.sys
!endif
#  if exist $&.exe erase $&.exe

# (Will the above line work for execom also?)

noise.sys: noise.obj

noise.obj: noise.asm noise.def noise.mac \
           sha.inc multiplex.inc \
           initnoise.inc printf.inc cpuid.inc

clean:
  if exist noise.lst erase noise.lst
  if exist noise.sys erase noise.sys
  if exist noise.exe erase noise.exe
  erase *.obj
  erase *.map
