.gitignore: Ignore the generated distribution tarball
[assignment-template.git] / Makefile
index d6ad2e6940d20b03e4ea42bd789163ee003af27c..af2d15bbbc003d4a322be1236b70dfab14e2abb0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 2012  W. Trevor King
+# Copyright (C) 2012-2013  W. Trevor King
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -25,12 +25,13 @@ PACKAGE = hw0
 VERSION = 1
 RELEASE = $(COURSE)-$(PACKAGE)-$(VERSION)
 RUN_PROGRAM = hello_world
+SCRIPTS =
 C_PROGRAMS = hello_world
 CXX_PROGRAMS = goodbye_world
 PROGRAMS = $(C_PROGRAMS) $(CXX_PROGRAMS)
 
 # Define the source files that will be distributed in the tarball
-SOURCE = *.c COPYING Makefile README
+SOURCE = *.c *.cpp *.h COPYING Makefile README $(SCRIPTS)
 
 # Define a list of object files needed to link PROGRAM.  We're setting
 # things up here so that a program % depends on the object file %.o.
@@ -59,6 +60,8 @@ TAR = tar
 .PHONY: all help clean dist run print- printvars
 
 # target: all - the default target
+# The target of the first rule is the default goal.  See:
+#   http://www.gnu.org/software/make/manual/html_node/Rules.html
 all: $(PROGRAMS)
 
 # target: help - display callable targets
@@ -81,11 +84,11 @@ dist:
 
 # target: hello_world - compile the hello_world program
 # Use GCC to link the program from object files.
-# For an explanation of the
+# For an explanation of the static pattern rule syntax:
 #   targets ...: target-pattern: prereq-patterns ...
-# syntax, see
+# see
 #   http://www.gnu.org/software/make/manual/html_node/Static-Usage.html
-# For an explanation of $@, $^ and other special variables, see
+# For an explanation of $@, $^, and other special variables, see
 #   http://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
 # For an explanation of .SECONDEXPANSION, see
 #   http://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html
@@ -117,11 +120,11 @@ dist:
 # certainly allowed to go that route if you wish.
 .SECONDEXPANSION:
 $(C_PROGRAMS): % : $$($$(@)_OBJECTS)
-       $(CC) $(LDFLAGS) -o $@ $^ $($(@)_LIBS)
+       $(CC) $(LDFLAGS) -o "$@" $^ $($(@)_LIBS)
 
 .SECONDEXPANSION:
 $(CXX_PROGRAMS): % : $$($$(*)_OBJECTS)
-       $(CXX) $(LDFLAGS) -o $@ $^ $($(@)_LIBS)
+       $(CXX) $(LDFLAGS) -o "$@" $^ $($(@)_LIBS)
 
 # target: run - use the program for its intended purpose
 # Here we just execute RUN_PROGRAM, but you could also use something
@@ -134,10 +137,13 @@ $(CXX_PROGRAMS): % : $$($$(*)_OBJECTS)
 run: $(PROGRAMS)
        ./$(RUN_PROGRAM)
 
-# Matching rule for compiling object files from C++ source
+# Pattern rule for compiling object files from C++ source
 # There is an implicit rule for this in GNU make
 #   http://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html
-# but I redefine it here for clarity.
+# but I redefine it here for clarity.  For an explanation of the
+#   %.o: %.cpp
+# syntax, see
+#   http://www.gnu.org/software/make/manual/html_node/Pattern-Intro.html
 #
 # CXX and CXXFLAGS have defaults defined by make
 #   http://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
@@ -146,12 +152,12 @@ run: $(PROGRAMS)
 # for example, try
 #    $ make CXX=/usr/local/bin/g++ CXXFLAGS=-Wall
 %.o: %.cpp
-       $(CXX) $(CXXFLAGS) -c $<
+       $(CXX) $(CXXFLAGS) -c "$<"
 
-# Matching rule for compiling object files from C source
+# Pattern rule for compiling object files from C source
 # The comments from the C++ rule above also apply here
 %.o: %.c
-       $(CC) $(CFLAGS) -c $<
+       $(CC) $(CFLAGS) -c "$<"
 
 # target: print-% - display a variable value (e.g. print-PROGRAMS)
 # Take some of the mystery out of variable manipulation.  For example,