# Makefile for the SCI class system.
#
# Since starting up the Script compiler 'SC' takes such a long time (due to
# reading in lots of header files), it is best to compile all modules in one
# invocation of the compiler rather than invoking the compiler for each module
# to be made.  In order to do this, we build a macro ('files') at run-time
# which contains those modules which need recompiling and pass this macro as
# a list of files to the compiler.


###### The following macros give the directory setup ######

# 'moduleDir' is the directory in which object files ('.so' files) are to be
# placed.  If you want these files put in the current directory, set it to '.'
moduleDir = .

# 'sysDir' is the directory in which the base class system is kept.
sysDir = \app24\lsci\sys

# 'errFile' is the file to which error output is to be written.
errFile = make.log

# 'compile' is the name of the executable 'SC' compiler.
compile = \app24\tsn\exe\lsc

# 'scFlags' are any flags (other than the output directory specification)
# which you wish to have passed to the compiler
scFlags = -O -s -c -w -n

###### These macros give the files which constitute your application ######

# These are the source files for the SCI class system
s1  = object.sc host.sc msg.sc netuser.sc group.sc player.sc
s2  = msgqueue.sc packdata.sc msgproc.sc
s3  = game.sc
s4  = 
s5  = 
s6  = 
s7  = 
s8  = 
s9  = 
s10 = 
src = $(s1) $(s2) $(s3) $(s4) $(s5) $(s6) $(s7) $(s8) $(s9) $(s10)

# The object files are just the source files with the '.sc' replaced by '.so'
obj = $[f,,$(src),so]

# This tells PolyMake where to look for the object files.
.PATH.so = $(moduleDir)


###### This is where the work gets done ######

# To make an object file from a source file, add it to the list of files
# to compile.
.sc.so:
	@%set files = $(files) $[f,"",$<,""]

# Since 'classes' is always written after a compile, it will serve as our
# target.
classes: $(obj)
	%if "$(files)"
		@%setenv sinclude=$(sysDir)
		:@$(compile) $(scFlags) -o$(moduleDir) >$(errFile) <@<
$[s,"\n",$(files)]
<
		%endif

# To remake the world, we delete all the old object files (just to make sure...),
# get new copies of 'classdef', 'selector', and 'module.dir' from the system,
# set 'files' to the list of all source files, and execute the actions for
# 'classes'.
all: $(src)
	@del *.so >nul
	@copy $(sysDir)\classdef >nul
	@copy $(sysDir)\module.dir >nul
	@copy $(sysDir)\selector >nul
	@%set files = $[f,"",$(src),""]
	@%do classes
