# Makefile
#
# written by Don Robert Maszle and Frederic Bois
#
# for mod: a preprocessor for MCSim simulation program
#
# Copyright (c) 1991-2002  Frederic Bois and Don Maszle
# All rights reserved.
#
#
#----------------------------------------------------------------------
#
# INTRODUCTION
#
#  This is a general format makefile to allow for ease of porting
#  between systems.  All system dependent and program dependent
#  specifications are defined as symbols in several sections as
#  described below.
#
#  `>>>>' indicates sections where things might commonly be changed
#  like the name of the compiler, or the name of the program to be
#  compiled.
#
#  `****' introduces important notes.
#
#  The section TARGETS below describes the targets for this Makefile.
#
#
#----------------------------------------------------------------------
#
#****  Standard Makefile names should be used throughout this file.
#****
#
#  `Make' is specifically designed to be used with several language
#  compilers including C, FORTRAN, Lex, and Yacc. A system Makefile
#  defines default settings for a number of standard variables that
#  specify the names of the various stages of compilation for different
#  languages, and flags to these compilers, in addition to defining default
#  compilation (inference) rules that use file prefixes to determine the
#  the rule.
#
#  This file overrides many default system settings, and some inference
#  rules. To do so correctly, Standard Makefile Names Must Be Used.
#  Several standard variables are listed here. See the manual for a
#  complete description (on Unix do `man make').
#
#       CC     :  Name of the C compiler
#       CFLAGS :  Flags passed to the $(CC) with every file
#
#       LINK   :  Name of the linker
#       CLFLAGS:  any compiler flags that get passed to the linker,
#       LFLAGS :  any flags specific to the linker.
#
#
#----------------------------------------------------------------------
#
# TARGETS
#
# There is only one target:
#
#    mod	This DEFAULT target creates the `mod' program
#


#---------- System Calls ----------
#
#>>>>  Define any system dependent calls here

ECHO = echo
COPY = cp
DEL = rm
MKDIR = mkdir
ARC  = tar
ARCFLAGS = cvf
MOD = mod


#---------- Compiler ----------
#
#>>>>  Define the COMPILER name and LINKER name here only.

CC = gcc
LINK = gcc

#>>>>  Define PATHS
#	The include path should be a directory containing header
#	files which are not in the standard include path.  Use `.'
#	if none is used.  
INCPATH = .
OBJPATH = o


#---------- Flags ----------
#
#  Define the flags for each cycle of compilation.
#
#  NOTE:  Only if you are compiling with gcc should you use
#         both debugging and optimization together.  Most (all?)
#         other compilers get confused, or won't accept the flags.
#
#>>>> Define debugging symbols and flags.
#
#     The symbols DEBUG and NDEBUG have different effects!  Some
#     library macros use DEBUG (to include debugging code) and others
#     use NDEBUG (to disinclude code). 
#
#     As an example, assertions ("assert.h") must be explicitely
#     DISincluded by defining NDEBUG, while, generally, diagnostic
#     messages must be included by defining DEBUG. 
#
#>>>> To compile with DEBUGGING uncomment the next lines
#
#DEBUG_SYMBOLS = -DDEBUG
#C_DEBUG_FLAG = -g
#L_DEBUG_FLAG = -g
#
#>>>> To compile with OPTIMIZATION uncomment the following lines
#
DEBUG_SYMBOLS = -DNDEBUG
C_OPTIM_FLAG = -O
L_OPTIM_FLAG =

#
#>>>> Include any special warning flags 
#
WARNINGS = -Wall


#--------------------
#****  You shouldn't need to change these lines.  They are dependent
#****  only on the above setup.

CFLAGS = $(C_OPTIM_FLAG) $(C_DEBUG_FLAG) $(DEBUG_SYMBOLS) \
	-I $(INCPATH) $(WARNINGS) -DMODGEN

CLFLAGS = $(L_OPTIM_FLAG) $(L_DEBUG_FLAG)

LFLAGS = -lm


#---------- Program spec ----------
#
#  Several suffixes are used for this section.  If the target
#  is called `xxx', then the following symbols have these meanings:
#
#  xxx		: Final target name
#  xxxDEP	: All dependencies of target
#  xxxO		: Object files for target
#  xxxO1,
#  xxxO2	: Alternate object files for target
#  xxxH, xxxH1..: Header files, perhaps grouped with the objects
#
#  Repeat the program specs as needed.  For each target, include
#  a link spec at the end of this file.
#
#>>>> Executable filename

MOD=mod

MODT=$(MOD)

MODLIBZ=$(MM)libc$(FPL)

#>>>> Object files, one per line followed by a \ to continue the line.
#     These can be partitioned if need be into logical groups.
#
MODO =\
	lex.o\
	lexerr.o\
	lexfn.o\
	mod.o\
	modd.o\
	modi.o\
	modo.o\
	strutil.o
MODDEP =$(MODO)


#---------- Targets ---------- 
#
#>>>> These are all the targets for the Makefile
#
#     `one' is the default target as it is the first in the file
#

one: $(MODT)


#---------- Inference Rules ---------- 
#
#****  These replace the default inference rules defined in the system
#****  makefile.  No need to make changes here.

.c.$(OBJPATH)/%.o:
	$(CC) $(CFLAGS) -o $(OBJPATH)/$@ $<


#---------- Link Rules ---------- 
#
#>>>>  Each compilation target must have a link rule defining the
#      linking stage of compilation.  The basic format is in the
#      target xxxT and its dependency list xxxDEP.  The second
#      and subsequent lines execute the $(LINK) command and pass
#      the following:
#        CLFLAGS:  any compiler flags that get passed to the linker,
#        xxxT   :  the output target name,
#        xxxDEP :  the dependency list of objects, and
#        LFLAGS :  any flags specific to the linker.
#

$(MODT): $(MODDEP) 
	@echo 'Linking $(MODT)...'
	@$(LINK) $(CLFLAGS) -o $(MODT) $(MODDEP) $(LFLAGS)
	@echo '* Created: executable "$(MODT)".'
	@echo

lex.o:          lex.h lexerr.h hungtype.h
lexerr.o:	lexerr.h lex.h hungtype.h
lexfn.o:        lex.h lexfn.h strutil.h lexerr.h hungtype.h
mod.c:		mod.h lex.h hungtype.h
modd.o:         lexerr.h mod.h lexfn.h hungtype.h lex.h
modi.o:         lexerr.h mod.h hungtype.h lex.h
modo.o:         mod.h lexfn.h lexerr.h hungtype.h lex.h 
