# 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 = 

# 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 = 

# Source files for library.
s1  = tsnlib.s tsn.c remobj.s tsnexec.s
s2  = 
src  = $(s1) $(s2)
obj  = ..\dll.o $[f,,$(src),o]



# Flags used in C compilations:
# -c				compile only
# -DLINT_ARGS	define LINT_ARGS, to enable argument checking
# -W3				give maximum number of error messages
# -Zp				pack all structures
# -ACw			compact model (small code, large data), DS != SS

cFlags = -c -DLINT_ARGS -W3 -Zp -ACw


# 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 keywordsxs

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:
	@%setenv include=../;/lsci
#
	%if %member($<, $(debug))
		@%set dOpt = -Zi -Gs
	%elseif %member($<, $(speed))
		@%set dOpt = -Oaceglti -Gs
	%else
		@%set dOpt = -Oaceglsi -Gs
	%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=../;/lsci
	%if %member($<, $(debug))
		:as $(asFlags) -d $<
	%else
		:as $(asFlags) $<
	%end



tsn.dll:	tsn.exe


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



############ METHODS FOR BUILDING .EXE FILES ############

.o.exe:
	:link $(lFlags) <@<
$[s," +\n",$**]
$*.exe
$*.map
sx+slibce
<


############ METHODS FOR BUILDING .EXE FILES ############

# Program root by itself builds the .exe file

.exe.:	$*.exe
	+echo done



############ METHODS FOR BUILDING .COM FILES ############

.exe.com:
	exe2bin $< $*.com
	+del $<
	+del $*.map



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

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