#
#                Generic makefile for SIMSCRIPT programs
#
# MAKE ARGUMENTS:
#     <no arg> : Make executable with the name assigned to the "PRG" parameter.
#     clean    : Remove all non-source files, i.e. object files and the 
#                executable and all intermediate files.
#     cleanexe : Remove the executable.
#-----------------------------------------------------------------------------



#=============================================================================
#== FILL IN THE PARAMETERS BELOW UNTIL THE LINE ">>> END OF PARAMETERS <<<" ==
#=============================================================================
#
# <<< PARAMETERS >>>

# PRG:  The name of the executable.
PRG = food

# PREAMBLE: SIMSCRIPT source file containing the preamble.
# SIMFILES: All other SIMSCRIPT source files.  A "\" followed
#           immediately by a carriage return must be put at the end of 
#           the line to continue to the next.
#
# When a program has only one module/ sim-file or the preamble is contained
# in a file with other routines, you must define PREAMBLE as this file name.

PREAMBLE = Preamble.sim

SIMFILES = broil.sim callord.sim choicek.sim choiceot.sim choicew.sim \
           clock.sim customer.sim generate.sim main.sim makeburg.sim \
           makefry.sim makeshak.sim moveto.sim occupier.sim stopsim.sim \
           takeord.sim

#
# SFLAGS:  SIMSCRIPT compile flags.

SFLAGS = -d

# SIMLINK:  Specify link command with SIMGRAPHICS I, SIMGRAPHICS II, or
#           no graphics; dynamic or static link.
#
#           <<< DYNAMIC LINK >>>
#           SIMGRAPHICS I  - simgld1
#           SIMGRAPHICS II - simgld2 or simgld
#           NO GRAPHICS    - simld
#
#           <<< STATIC LINK >>>
#           SIMGRAPHICS I  - tsimgld1
#           SIMGRAPHICS II - tsimgld2
#           NO GRAPHICS    - tsimld

SIMLINK  = simgld2 


# >>> END OF PARAMETERS <<<
#
#=============================================================================
#================= BELOW HERE NO CHANGES SHOULD BE NECESSARY =================
#=============================================================================

# SIMC:  SIMSCRIPT compile command.
SIMC = simc

# OBJS:  List of .o files.
OBJS     = $(PREAMBLE:.sim=.o) $(SIMFILES:.sim=.o)

# The first (empty) .SUFFIXES clears the SUFFIXES list. The second 
# acknowledges only the .sim and .o suffixes. This avoids problems with 
# extraneous .c files and others.
.SUFFIXES:
.SUFFIXES: .o .sim .c


$(PRG) : $(OBJS)
	@echo "--- Linking ..."
	$(SIMLINK) -o $(PRG) $(OBJS)
	@echo "--- $(PRG) was successfully built!"

clean : 
	@echo "--- Removing all intermediate files and the executable."
	rm -f *.o *.c *.i *.s *~ core a.out $(PRG) msdebug.*

cleanexe : 
	@echo "--- Removing executables."
	rm -f core a.out $(PRG)

#-------------------------- RULES ----------------------------------------
#

# If preamble was changed, we need to recompile everything. Since after
# that all *.o will be current, just the link is left in the target above.

$(PREAMBLE:.sim=.o): $(PREAMBLE)
	@echo "--- $(PREAMBLE:.sim=.o) outdated or missing!"
	@echo "--- Recompiling everything ..."
	$(SIMC) -c $(SFLAGS) $(PREAMBLE) $(SIMFILES)


# How to make an individual object file from a simcript source file. 

.sim.o:
	$(SIMC) -cv $(SFLAGS) $(PREAMBLE) $*.sim


