############################################################################## # # Sample Makefile for C++ applications # Works for single and multiple file programs. # Works on several different versions of Unix. # written by Robert Duvall # ############################################################################## ############################################################################## # Application specific variables --- change these to customize your compile # TYPE type of executable to create # Possible values: PRIMARY, TEST, LIB, or whatever else you want # ARCH system on which you are compiling # Possible values: CPS, ACPUB, LINUX, CYGWIN, MINGW, OSX, SGI # # EXEC_TYPE name of the given type of executable file # SRC_TYPE space separated list of all source code files that must be linked # to create the executable of given TYPE (i.e., not template files) # INC_FILES space separated list of header and template files --- add to this # list only if you have files that do not have a corresponding .cpp # files listed in SRC_FILES ############################################################################## TYPE = PRIMARY ARCH = CPS EXEC_PRIMARY = something SRC_PRIMARY = main.cpp something.cpp EXEC_TEST = testsomething SRC_TEST = testit.cpp something.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 (like opengl) SYSINC_CPS_DIR = SYSINC_ACPUB_DIR = SYSINC_LINUX_DIR = SYSINC_CYGWIN_DIR = SYSINC_MINGW_DIR = SYSINC_OSX_DIR = SYSINC_SGI_DIR = SYSINC_DIR = $(SYSINC_$(ARCH)_DIR:%=-I%/include) # Where to find system libraries (like opengl) SYSLIB_CPS_DIR = SYSLIB_ACPUB_DIR = SYSLIB_LINUX_DIR = SYSLIB_CYGWIN_DIR = SYSLIB_MINGW_DIR = SYSLIB_OSX_DIR = SYSLIB_SGI_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_MINGW_RUN = SYSLIB_OSX_RUN = SYSLIB_SGI_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_MINGW_LIB = SYSLIB_OSX_LIB = SYSLIB_SGI_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/tapestry COURSE_CYGWIN_DIR = /usr/local/tapestry COURSE_MINGW_DIR = COURSE_OSX_DIR = /usr/local/tapestry COURSE_SGI_DIR = /usr/local/tapestry COURSE_DIR = $(COURSE_$(ARCH)_DIR) # What course specific libraries to link to COURSE_LIB = -ltapestry ############################################################################## # What options to give to the compiler to customize compilation # COMPILER what compiler to use # 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 ############################################################################## CCC_CPS_DIR = CCC_ACPUB_DIR = CCC_LINUX_DIR = CCC_CYGWIN_DIR = CCC_MINGW_DIR = c:/program\ files/mingw/bin/ CCC_OSX_DIR = CCC_SGI_DIR = /usr/local/bin/ COMPILER = $(CCC_$(ARCH)_DIR)g++ REMOVE_CPS = $(RM) REMOVE_ACPUB = $(RM) REMOVE_LINUX = $(RM) REMOVE_CYGWIN = $(RM) REMOVE_MINGW = del REMOVE_OSX = $(RM) REMOVE_SGI = $(RM) REMOVE = $(REMOVE_$(ARCH)) DEBUG_CPS = -O2 DEBUG_ACPUB = -g DEBUG_LINUX = $(DEBUG_ACPUB) DEBUG_CYGWIN = $(DEBUG_ACPUB) DEBUG_MINGW = $(DEBUG_ACPUB) DEBUG_OSX = $(DEBUG_ACPUB) DEBUG_SGI = $(DEBUG_ACPUB) DEBUG = $(DEBUG_$(ARCH)) EXTRA_CPS = -Wall EXTRA_ACPUB = -Wall EXTRA_LINUX = $(EXTRA_ACPUB) EXTRA_CYGWIN = $(EXTRA_ACPUB) EXTRA_MINGW = $(EXTRA_ACPUB) EXTRA_OSX = $(DEBUG_ACPUB) EXTRA_SGI = $(DEBUG_ACPUB) EXTRA = $(EXTRA_$(ARCH)) EXEC_SUFFIX_CPS = EXEC_SUFFIX_ACPUB = EXEC_SUFFIX_LINUX = EXEC_SUFFIX_CYGWIN = .exe EXEC_SUFFIX_MINGW = .exe EXEC_SUFFIX_OSX = EXEC_SUFFIX_SGI = 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 commands to use CCC = $(COMPILER) CXX = $(CCC) # What flags should be passed to the compiler 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 ## BUGBUG: should not hardcode .cpp extension EXEC = $(EXEC_$(TYPE)) SRC_FILES = $(SRC_$(TYPE)) INC_FILES = $(SRC_FILES:%.cpp=%.h) $(INC_$(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) # clean up after you're done clean : $(REMOVE) $(OFILES) $(EXEC) core # depend figures out header file dependecies, # use each time you add a new header file ### BUGBUG: does not work on MINGW depend: makedepend -- $(CXXFLAGS) -- -Y $(SRC_FILES) # 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 -- makedepend depends on it.