# Makefile for the Netwide Assembler under 16-bit DOS
#
# The Netwide Assembler is copyright (C) 1996 Simon Tatham and
# Julian Hall. All rights reserved. The software is
# redistributable under the licence given in the file "Licence"
# distributed in the NASM archive.
#
# This Makefile is designed to build NASM using a 16-bit DOS C
# compiler such as Microsoft C, provided you have a compatible MAKE.
# It's been tested with Microsoft C 5.x plus Borland Make. (Yes, I
# know it's silly, but...)

# update:  MSC 5.1 will not compile 'nasmlib.c'   (arg lists don't match)
#          MSC 6.00A will not compile 'insnsa.c'  (qcl is required)
#          MSC 7.00 will compile all
#
# GNU software compiled by DJGPP is also required:
#
#    grep  2.4
#    perl  5.6.1
#
# Source and DOS/Windows binaries may be downloaded from:
#
#    ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/
#
# Compilation has been tested under Windows 98 & Windows 2000
# MSC 7.00 & DJGPP applications require a DPMI interface, which is
# a part of MSC 7.00 under DOS.  It is also a part of Windows.
#
#
# For a 16-bit compiler, we don't need all the formats
#
CONFIG = -DOF_ONLY -DOF_BIN -DOF_OBJ -DOF_WIN32 -DOF_AS86

#CC = cl /c /O /AL /Gt
#   Compile for a 286, ain't nobody using an 8086 anymore
CC = cl /c /Oz /AL /Gt256 /G2 /I.. # MSC 7.00

#QCL = qcl /c /AL /Gt
QCL = $(CC)                     # MSC 7.00

LINK = link
LINKFLAGS = /F4000 /Fm
LIBRARIES =
EXE = .exe#
OBJ = obj#

.c.$(OBJ):
	$(CC) $(CONFIG) /Fo$@ $*.c

NASMOBJS1 = nasm.$(OBJ) nasmlib.$(OBJ) float.$(OBJ) insnsa.$(OBJ) \
           assemble.$(OBJ) labels.$(OBJ) parser.$(OBJ) outform.$(OBJ)
NASMOBJS2 = output\outbin.$(OBJ) output\outaout.$(OBJ) output\outcoff.$(OBJ)
NASMOBJS3 = output\outelf.$(OBJ) output\outobj.$(OBJ) output\outas86.$(OBJ)
NASMOBJS4 = output\outrdf.$(OBJ) output\outrdf2.$(OBJ) output\outieee.$(OBJ)
NASMOBJS5 = output\outdbg.$(OBJ) preproc.$(OBJ) listing.$(OBJ) eval.$(OBJ)

NASMOBJS = $(NASMOBJS1) $(NASMOBJS2) $(NASMOBJS3) $(NASMOBJS4) $(NASMOBJS5)

NDISASMOBJS = ndisasm.$(OBJ) disasm.$(OBJ) sync.$(OBJ) nasmlib.$(OBJ) \
              insnsd.$(OBJ)

all : nasm$(EXE) ndisasm$(EXE)

# We have to have a horrible kludge here to get round the 128 character
# limit, as usual...
LINKOBJS = a*.obj e*.obj f*.obj insnsa.obj l*.obj na*.obj o*.obj p*.obj
nasm$(EXE): $(NASMOBJS)
	echo $(NASMOBJS1) + >foo
	echo $(NASMOBJS2) + >>foo
	echo $(NASMOBJS3) + >>foo
	echo $(NASMOBJS4) + >>foo
	echo $(NASMOBJS5)   >> foo
	$(LINK) /st:4096 @foo,nasm;

ndisasm$(EXE): $(NDISASMOBJS)
	$(LINK) $(NDISASMOBJS), ndisasm;

output\version.h: version.h
	copy version.h output

output\nasm.h: nasm.h
	copy nasm.h output

output\insnsi.h: insnsi.h
	copy insnsi.h output

output\nasmlib.h: nasmlib.h
	copy nasmlib.h output

output\outform.h: outform.h
	copy outform.h output

# These files contains all the standard macros that are derived from
# the version number.
version.h: version version.pl
	perl version.pl h < version > version.h

version.mac: version version.pl
	perl version.pl mac < version > version.mac

# This source file is generated from the standard macros file
# `standard.mac' by another Perl script. Again, it's part of the
# standard distribution.

macros.c: macros.pl standard.mac version.mac
	perl macros.pl standard.mac version.mac

insnsa.c insnsd.c insnsi.h insnsn.c: insns16.dat insns.pl
	perl insns.pl insns16.dat

insns16.dat:  insns.dat
	grep -v WILLAMETTE insns.dat | grep -v KATMAI | grep -v SSE | \
	    grep -v MMX | grep -v 3DNOW | grep -v UNDOC >insns16.dat

# These source files are generated from regs.dat by yet another
# perl script.
 regs.c: regs.dat regs.pl
	perl regs.pl c regs.dat > regs.c
regflags.c: regs.dat regs.pl
	perl regs.pl fc regs.dat > regflags.c
regdis.c: regs.dat regs.pl
	perl regs.pl dc regs.dat > regdis.c
regvals.c: regs.dat regs.pl
	perl regs.pl vc regs.dat > regvals.c
regs.h: regs.dat regs.pl
	perl regs.pl h regs.dat > regs.h

# Another grotty hack: QC is less likely to run out of memory than
# CL proper; and we don't need any optimisation in these modules
# since they're just data.
insnsa.$(OBJ): insnsa.c nasm.h version.h insnsi.h insns.h
	$(QCL) insnsa.c

insnsd.$(OBJ): insnsd.c nasm.h version.h insnsi.h insns.h
	$(QCL) insnsd.c

tidy:
	del output\*.h
	del *.$(OBJ)
	del output\*.$(OBJ)

clean :  tidy
	del nasm$(EXE)
	del ndisasm$(EXE)

spotless:  clean
	del insns16.dat
	del insnsa.c
	del insnsd.c
	del insnsi.h
	del insnsn.c
        del version.h

#-- Magic hints to mkdep.pl --#
# @object-ending: ".$(OBJ)"
# @path-separator: "\"
#-- Everything below is generated by mkdep.pl - do not edit --#
assemble.$(OBJ): assemble.c insns.h assemble.h regvals.c nasm.h regs.h \
 insnsi.h nasmlib.h version.h
disasm.$(OBJ): disasm.c insns.h regs.c sync.h names.c nasm.h disasm.h regs.h \
 insnsn.c insnsi.h version.h regdis.c
eval.$(OBJ): eval.c nasm.h regs.h labels.h nasmlib.h version.h eval.h
float.$(OBJ): float.c nasm.h regs.h version.h
insnsa.$(OBJ): insnsa.c insns.h nasm.h regs.h insnsi.h version.h
insnsd.$(OBJ): insnsd.c insns.h nasm.h regs.h insnsi.h version.h
insnsn.$(OBJ): insnsn.c
labels.$(OBJ): labels.c nasm.h regs.h nasmlib.h version.h
listing.$(OBJ): listing.c listing.h nasm.h regs.h nasmlib.h version.h
macros.$(OBJ): macros.c
names.$(OBJ): names.c regs.c insnsn.c
nasm.$(OBJ): nasm.c listing.h preproc.h insns.h outform.h assemble.h \
 parser.h nasm.h regs.h labels.h insnsi.h nasmlib.h version.h eval.h
nasmlib.$(OBJ): nasmlib.c insns.h regs.c names.c nasm.h regs.h insnsn.c \
 insnsi.h nasmlib.h version.h
ndisasm.$(OBJ): ndisasm.c insns.h sync.h nasm.h disasm.h regs.h insnsi.h \
 nasmlib.h version.h
outform.$(OBJ): outform.c outform.h nasm.h regs.h version.h
output\outaout.$(OBJ): output\outaout.c outform.h nasm.h regs.h nasmlib.h \
 version.h
output\outas86.$(OBJ): output\outas86.c outform.h nasm.h regs.h nasmlib.h \
 version.h
output\outbin.$(OBJ): output\outbin.c outform.h nasm.h regs.h nasmlib.h \
 version.h
output\outcoff.$(OBJ): output\outcoff.c outform.h nasm.h regs.h nasmlib.h \
 version.h
output\outdbg.$(OBJ): output\outdbg.c outform.h nasm.h regs.h nasmlib.h \
 version.h
output\outelf.$(OBJ): output\outelf.c outform.h nasm.h regs.h nasmlib.h \
 version.h
output\outieee.$(OBJ): output\outieee.c outform.h nasm.h regs.h nasmlib.h \
 version.h
output\outobj.$(OBJ): output\outobj.c outform.h nasm.h regs.h nasmlib.h \
 version.h
output\outrdf.$(OBJ): output\outrdf.c outform.h nasm.h regs.h nasmlib.h \
 version.h
output\outrdf2.$(OBJ): output\outrdf2.c outform.h nasm.h regs.h nasmlib.h \
 version.h
parser.$(OBJ): parser.c insns.h parser.h nasm.h regs.h insnsi.h regflags.c \
 float.h nasmlib.h version.h
preproc.$(OBJ): preproc.c nasm.h macros.c regs.h nasmlib.h version.h
regdis.$(OBJ): regdis.c
regflags.$(OBJ): regflags.c
regs.$(OBJ): regs.c
regvals.$(OBJ): regvals.c
sync.$(OBJ): sync.c sync.h