# 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 = pic256.s

# Source files for 16 color graphics library.
src16  = graphlib.s graph16.s pic16.s cel16.s
obj16 = ..\dll.o $[f,,$(src16),o]

# Source files for 256 color graphics library.
src256  = graphlib.s graph256.s pic256.s cel256.s palette.c
obj256 = ..\dll.o $[f,,$(src256),o]

# Files to be compiled for speed optimization.  All others will be optimized
# for space.
speed = 

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

# Files which are used to make utilities.  These will use the default
# libraries.
utils = 



graph: graph16 graph256

graph16: graph16.dll
graph256: graph256.dll

graph16.dll: graph16.exe
graph256.dll: graph256.exe


graph16.exe: $(obj16)
	:link $(lFlags) <@<
$[s," +\n",$**]
graph16.exe
graph16.map;
<
	exetodll graph16


graph256.exe: $(obj256)
	:link $(lFlags) <@<
$[s," +\n",$**]
graph256.exe
graph256.map;
<
	exetodll graph256



#
# For PLINK
#
#graph.exe: $(obj)
#	pl <@<
#file $[s,",\n ",$**]
#library	libh.lib
#batch
#out		graph
#map		= graph.pm a,g,m
#<
#	exetodll graph


# Flags used in C compilations:
# -c				compile only
# -DLINT_ARGS	define LINT_ARGS, to enable argument checking
# -W3				give maximum number of error messages
# -Gs				disable stack checking
# -Zp				pack all structures
# -AC				compact model (small code, large data)
# -Au				SS != DS, reload DS on function entry
# -ND	DLL_DATA	all data segments will be named DLL_DATA

cFlags = -c -W3 -Gs -Zp -AC -Au -ND DLL_DATA -DLINT_ARGS


# Flags used in assembly compilations:
# MASM flags:
# -ml				case sensitive
# -s				write segments in order in which they occur
# -t				write error output only
# -z				display lines containing errors
# -w2				maximum warning level
# Preprocessor flags:
# -e				'enter' and 'exit' are not keywords

asFlags = -a"-ml -s -t -z -w2" -p"-e"


# Linker flags
# /NOI			case sensitive
# /M				create a link map
# /NOE			
# /LI				add line number info to map

lFlags = /NOI /M /NOE /LI




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

.c.o:
	%if %member($<, $(debug))
#
		@%set dOpt = -Zi -Od
	%elseif %member($<, $(speed))
		@%set dOpt = -Oalt
	%else
		@%set dOpt = -Os
	%endif
#
	@%setenv include=../;../..
	%if %member($<, $(speed))
		@%set dOpt = -Oalt
	%else
		@%set dOpt = -Os
	%endif
#
	%if %member($<, $(utils))
		@%set lOpt = 
	%else
		@%set lOpt = -Zl
	%endif
#
	%if %member($<, $(list))
		:cl $(cFlags) $(dOpt) $(lOpt) -Fc -Fo$@ $<
	%else
		:cl $(cFlags) $(dOpt) $(lOpt) -Fo$@ $<
	%endif
	
	
.s.o:
#
#	Assemble for debugging if file is member of debug list.
#
	@%setenv include=../;../..
	%if %member($<, $(debug))
		:as $(asFlags) -d $<
	%else
		:as $(asFlags) $<
	%end

