-# 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
VERSION = 1
RELEASE = $(COURSE)-$(PACKAGE)-$(VERSION)
RUN_PROGRAM = hello_world
-SCRIPTS =
+SCRIPTS =
C_PROGRAMS = hello_world
CXX_PROGRAMS = goodbye_world
PROGRAMS = $(C_PROGRAMS) $(CXX_PROGRAMS)
.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
# 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
# http://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
# 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
# for example, try
# $ make CXX=/usr/local/bin/g++ CXXFLAGS=-Wall
%.o: %.cpp
- $(CXX) $(CXXFLAGS) -c $<
+ $(CXX) $(CXXFLAGS) -c "$<"
# 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,