# Author: Hannah C. Tang (hctang@cs) # # Sample Makefile for the 326 templates example ### Variables ### # Using a variable defined in a Makefile requires $(MY_VAR) syntax # The C++ compiler is traditionally called CXX. CXX = g++ # The traditional name for compiler flags CXXFLAGS = -g -Wall -ansi # The name of the executable TARGET_NAME = array-test ### Rules ### # The first target in a Makefile is the default. That is, a simple "make" # at the command line will build the "all" target for this Makefile. # Remember the general syntax for rules in a Makefile is: # : # # # ... # # The executable depends on the Array.* files (including the instantiation # file) and main.cc. However, the only object files which we create are # is the driver (main.o) and the instantiation file (ArrayInst.o) all : main.o ArrayInst.o $(CXX) -o $(TARGET_NAME) $(CXXFLAGS) ArrayInst.o main.o # This line compiles (it only compiles -- the build happens in the # first rule) the object file main.o main.o : main.cc $(CXX) $(CXXFLAGS) -c main.cc # This line compiles (it only compiles -- the build happens in the # first rule) the object file ArrayInst.o ArrayInst.o : Array.hh Array.cc $(CXX) $(CXXFLAGS) -c ArrayInst.cc # This rule is a fake target -- that is, it doesn't generate any object # files; rather, the make command will execute the following rm command # (which cleans out your old object files and executable) whenever you # type "make clean" clean : rm -f *.o $(TARGET_NAME) # And .... as a reward for reading through this entire Makefile, here is # is some information on pattern rules! =) # # Quoth Evgeny Roubinchtein (evgenyr@cs.washington.edu): # # > You could also use "patten rules" to tell 'make' how to produce a # > .o given a .cc. You wouldn't then have to write rules like: # > # > FOO.o : FOO.cc # > $(CXX) $(CXXFLAGS) -o $@ $^ # > # > for each .o you want to produce. # > # > Often, people also use automatic dependency generation with pattern # > rules. The sample Makefile Justin Husted has written (in /uns/examples) # > uses pattern rules and automatic dependency generation. # > # > Pattern rules are documented here: # > http://www.gnu.org/manual/make-3.79.1/html_node/make_100.html#IDX828 # > # > Automatic dependency generation is documented here: # > http://www.gnu.org/manual/make-3.79.1/html_node/make_44.html#IDX259 # # Thanks, Evgeny!