############################################################################## # # Sample Makefile for C++ applications # Works for single and multiple file programs. # Works on several different versions of Unix. # written by Robert Duvall # # For use with multiple file projects consider using 'make depend' to # generate dependencies whenever you add new header files ############################################################################## ############################################################################## # Application specific variables --- change these to customize your compile # EXEC_XXX name of the given type of executable file (i.e., test, main, etc.) # SRC_XXX space separated list of all source code files that must be linked # to create the executable of same type (i.e., not template files) # ARCH system on which you are compiling # Possible values: CPS, ACPUB, LINUX, CYGWIN # TYPE which executable to compile # Possible values: MAIN, TEST, or any other you want to define # (e.g., MAIN2) ############################################################################## ARCH = CPS TYPE = MAIN EXEC_MAIN = tryit SRC_MAIN = tryit.cpp EXEC_TEST = tryit_test SRC_TEST = tryit_test.cpp ############################################################################## # Where to find course related header files (and their libraries) # --- typically only need to set this at the start of the semester # SYSINC_DIR space separated list of system directories where to find headers # SYSLIB_DIR space separated list of system directories where to find libraries # SYSLIB_LIB space separated list of system libraries needed # SYSLIB_RUN space separated list of system libraries needed at runtime # COURSE_DIR space separated list of course directories where to find files # COURSE_LIB space separated list of course libraries needed ############################################################################## # Where to find system headers SYSINC_CPS_DIR = SYSINC_ACPUB_DIR = SYSINC_LINUX_DIR = SYSINC_CYGWIN_DIR = SYSINC_DIR = $(SYSINC_$(ARCH)_DIR:%=-I%/include) # Where to find system libraries SYSLIB_CPS_DIR = SYSLIB_ACPUB_DIR = SYSLIB_LINUX_DIR = SYSLIB_CYGWIN_DIR = SYSLIB_DIR = $(SYSLIB_$(ARCH)_DIR:%=-L%/lib) # Where to find system libraries at runtime SYSLIB_CPS_RUN = SYSLIB_ACPUB_RUN = SYSLIB_LINUX_RUN = SYSLIB_CYGWIN_RUN = SYSLIB_RUN = $(SYSLIB_$(ARCH)_RUN:%=-R%/lib) # What system libraries to link to SYSLIB_CPS_LIB = SYSLIB_ACPUB_LIB = SYSLIB_LINUX_LIB = SYSLIB_CYGWIN_LIB = SYSLIB_LIB = $(SYSLIB_$(ARCH)_LIB:%=-l%) # Where to find course specific libraries (and what they are) COURSE_CPS_DIR = /usr/project/courses COURSE_ACPUB_DIR = /afs/acpub/project/cps/tapestry COURSE_LINUX_DIR = /usr/local COURSE_CYGWIN_DIR = /usr/local COURSE_DIR = $(COURSE_$(ARCH)_DIR) # What course specific libraries to link to COURSE_LIB = -ltapestry # What flags should be passed to the compiler CCC_CPS_DIR = CCC_ACPUB_DIR = CCC_LINUX_DIR = CCC_CYGWIN_DIR = COMPILER = $(CCC_$(ARCH)_DIR)g++ DEBUG_CPS = -g DEBUG_ACPUB = $(DEBUG_CPS) DEBUG_LINUX = $(DEBUG_CPS) DEBUG_CYGWIN = $(DEBUG_CPS) DEBUG = $(DEBUG_$(ARCH)) EXTRA_CPS = -Wall EXTRA_ACPUB = $(EXTRA_CPS) EXTRA_LINUX = $(EXTRA_CPS) EXTRA_CYGWIN = $(EXTRA_CPS) EXTRA = $(EXTRA_$(ARCH)) EXEC_SUFFIX_CPS = EXEC_SUFFIX_ACPUB = EXEC_SUFFIX_LINUX = EXEC_SUFFIX_CYGWIN = .exe EXEC_SUFFIX = $(EXEC_SUFFIX_$(ARCH)) ############################################################################## # Compiler specifications # These match the variable names given in /usr/share/lib/make/make.rules # so that make's generic rules work to compile our files. # gmake prefers CXX and CXXFLAGS for c++ programs ############################################################################## # Which compiler should be used CCC = $(COMPILER) CXX = $(CCC) DEBUG_LEVEL = $(DEBUG) EXTRA_CCFLAGS = $(EXTRA) CCFLAGS = $(VERBOSE) $(DEBUG_LEVEL) $(EXTRA_CCFLAGS) CXXFLAGS = $(CCFLAGS) # What flags should be passed to the C pre-processor # In other words, where should we look for files to include - note, # you should never need to include compiler specific directories here # because each compiler already knows where to look for its system # files (unless you want to override the defaults) # CPPFLAGS = -I. \ $(SYSINC_DIR) \ $(COURSE_DIR:%=-I%/include) # What flags should be passed to the linker # In other words, where should we look for libraries to link with - note, # you should never need to include compiler specific directories here # because each compiler already knows where to look for its system files. # LDFLAGS = -L. \ $(SYSLIB_DIR) \ $(COURSE_DIR:%=-L%/lib) \ $(SYSLIB_RUN) # What libraries should be linked with LDLIBS = $(COURSE_LIB) $(SYSLIB_LIB) # All source files have associated object files EXEC = $(EXEC_$(TYPE)) SRC_FILES = $(SOURCE_$(TYPE)) OFILES = $(SRC_FILES:%.cpp=%.o) ########################################################################### # Additional rules make should know about in order to compile our files ########################################################################### # all is the default rule all : $(EXEC) # exec depends on the object files $(EXEC) : $(OFILES) $(LINK.cc) -o $(EXEC) $(OFILES) $(LDLIBS) # depend figures out header file dependecies, # use each time you add a new header file depend: makedepend -- $(CXXFLAGS) -- -Y $(SRC_FILES) # clean up after you're done clean : $(RM) $(EXEC)$(EXEC_SUFFIX) *.o core # compile a single .cpp file into an object (.o) file # for later linking with other .o files .cpp.o: $(COMPILE.cc) $< # compile a single .cpp file into an executable file .cpp: $(LINK.cc) $< -o $@ $(LDLIBS) # DO NOT DELETE THIS LINE -- make depend depends on it.