# Makefile for the SCI interpreter and assorted drivers and utilities.

# Do not use builtins (default) dependencies or actions -- everything
# is explicitly declared here.
.SUFFIXES
# Execute commands directly, without invoking command.com.  
.NOSHELL


# Files to be compiled for debugging.  All others will be optimized.
debug = math.s

# Files to be compiled for speed optimization.  All others will be optimized
# for space.
speed = string.c list.c animate.c motion.c nlsaidf.c nllists.c resource.c

# Files to be compiled with an assembly listing.
list = 

# Files which are used to make utilities.  These will use the default
# libraries.
utils = makevol.c compress.c compres.s


# Standard flags for C, as, and link.
cFlags = -c -DLINT_ARGS -W3 -Gs -Zp -AS
asFlags = -a"-ml -s -t -z -w2"
lFlags = /NOI /CO /MAP


# Source files for interpreter.
s1  = start.s sci.c pmachine.s printf.c debug.c
s2  = fileio.s string.c script.c list.c
s3  = kerndisp.s dialog.c event.c eventasm.s
s4  = kernel.c picture.c
s5  = resource.c text.c window.c animate.c
s6  = object.s math.s debugasm.s
s7  = menu.c savevars.s restart.c intrpt.s
s8  = sound.c motion.c flist.s savegame.c
s9  = snd.s fardata.c dos.c mouse.s trig.c
#s10 = nlparse.c nlsaid.c  nlsaidf.c nlvocab.c
#s11 = nlquery.c  nlsema.c  nlpragma.c 
#s12 = nlprint.c  nllists.c nlsyms.c

src = $(s1) $(s2) $(s3) $(s4) $(s5) $(s6) $(s7) $(s8) $(s9)
#src0 = $(s1) $(s2) $(s3) $(s4) $(s5) $(s6) $(s7) $(s8) $(s9)
#src  = $(src0) $(s10) $(s11) $(s12)

graph16 = graph.s graph16.s cels16.s
graph256  = graph.s graph256.s cels256.s

filSrc = fileload.c
volSrc = dcompres.s hfd.s volload.c


# Object files for the interpreter.
# Create object file names by tacking an 'o' extension onto the source names.
fil16Src = $(src) $(graph16) $(filSrc) memmgr.s
fil256Src = $(src) $(graph256) $(filSrc) memmgr.s
vol16Src = $(src) $(graph16) $(volSrc) memmgr.s
vol256Src = $(src) $(graph256) $(volSrc) memmgr.s

filObj = $[f,,$(filSrc),o]
volObj = $[f,,$(volSrc),o]


############ METHODS FOR BUILDING OBJECT FILES  ############

.c.o:
#
#	Get included files either from the network or a local directory,
#	depending on whether the network is there.
#
#	@%setenv include=i:
	@%setenv include=vcs\
#
#	Set any debugging-related options
#
	%if %member($<, $(debug))
		@%set dOpt = -Zi -Od
	%elseif %member($<, $(speed))
		@%set dOpt = -Oalt
	%else
		@%set dOpt = -Os
	%endif
#
#	Set any library-related options
#
	%if %member($<, $(utils))
		@%set lOpt = 
	%else
		@%set lOpt = -Zl
	%endif
#
#	Now do the compilation with all flags in place.
#
	%if %member($<, $(list))
		cl $(cFlags) $(dOpt) $(lOpt) -Fc -Fo$@ $<
	%else
		cl $(cFlags) $(dOpt) $(lOpt) -Fo$@ $<
	%endif
	
	
.s.o:
#
#	Get included files either from the network or a local directory,
#	depending on whether the network is there.
#
#	@%setenv include=f:/interp/sci/
	@%setenv include=vcs\
#
#	Assemble for debugging if file is member of debug list.
#
	%if %member($<, $(debug))
		as $(asFlags) -d $<
	%else
		as $(asFlags) $<
	%endif




############ FILE-BASED RESOURCES  ############

sci: $[f,,$(fil16Src),o]
	link $(lFlags) <@<
$[s," +\n",$**]
sci.exe
sci.map
libh.lib
<
	cvpack -p sci.exe
	incver sci.exe -vsci.ver
	ts sci /f_/e/s




############ VOLUME-BASED RESOURCES  ############

sciv: $[f,,$(vol16Src),o]
	link $(lFlags) <@<
$[s," +\n",$**]
sciv.exe
sciv.map
libh.lib
<
	cvpack -p sciv.exe
	incver sciv.exe -vsci.ver



prod: sci sciv





############ FILE-BASED RESOURCES  256 COLORS ############
sci256: $[f,,$(fil256Src),o]
     link $(lFlags) <@<
$[s," +\n",$**]
sci256.exe
sci256.map
libh.lib
<
#	cvpack -p sci.exe
#	incver sci.exe -vsci.ver


############ VOLUME-BASED RESOURCES  256 COLORS ############
sci256: $[f,,$(vol256Src),o]
     link $(lFlags) <@<
$[s," +\n",$**]
sci256.exe
sci256.map
libh.lib
<
#	cvpack -p sci.exe
#	incver sci.exe -vsci.ver




############ DRIVERS  ############

.o.drv:
	link $<;
	exe2bin $* $@
	+del $*.o
	+del $*.exe



############ MAKEVOLS  ############

MKsrc = makevols.c compress.c compres.s

makevols: $(MKsrc)
     link $(lFlags) <@<
$[s," +\n",$**]
makevols.exe
makevols.map
libh.lib
<
     cvpack -p makevols.exe

