1 # Copyright (C) 2012 W. Trevor King
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Declare variables describing package information.
17 # http://www.gnu.org/software/make/manual/html_node/Setting.html
18 # The $(...) syntax references a variable's value.
19 # http://www.gnu.org/software/make/manual/html_node/Reference.html
20 # You can override variables from the command line. For example
21 # $ make VERSION=2 dist
22 # will generate hw0-2.tar.gz
26 RELEASE = $(COURSE)-$(PACKAGE)-$(VERSION)
29 # Define the source files that will be distributed in the tarball
30 SOURCE = *.c COPYING Makefile README
32 # Define a list of object files needed to link PROGRAM
33 OBJECTS = $(PROGRAM).o
35 # You may want to link agains external libraries. For example, to
36 # link against the system math library, use.
40 # Define useful programs (this makes it easy to swap in alternates)
47 # Declare targets that do not generate files of the same name.
48 # http://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
49 .PHONY: all help clean dist run
51 # target: all - the default target
54 # target: help - display callable targets
55 # Use `grep` to search this file for target comments
57 $(GREP) '^# target:' [Mm]akefile
59 # target: clean - remove automatically generated files
61 $(RM) -rf $(PROGRAM) *.o $(RELEASE)*
63 # target: dist - generate a tarball packaging the source
64 # Here, we move the source into a temporary release directory, tar the
65 # release directory, and remove the release directory.
68 $(CP) -r $(SOURCE) $(RELEASE)
69 $(TAR) -czf $(RELEASE).tar.gz $(RELEASE)
72 # target: hello_world - compile the hello_world program
73 # Use GCC to link the program from object files.
74 $(PROGRAM): $(OBJECTS)
75 $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
77 # target: run - use the program for its intended purpose
78 # Here we just execute PROGRAM, but you could also use something like
79 # run: $(PROGRAM) plot.gp
82 # where plot.gp was a gnuplot script for plotting data generated by
87 # Matching rule for compiling object files from C++ source
88 # There is an implicit rule for this in GNU make
89 # http://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html
90 # but I redefine it here for clarity.
92 # CXX and CXXFLAGS have defaults defined by make
93 # http://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
94 # but they can also be come from the environment
95 # http://www.gnu.org/software/make/manual/html_node/Environment.html
97 # $ make CXX=/usr/local/bin/g++ CXXFLAGS=-Wall
99 $(CXX) $(CXXFLAGS) -c $<
101 # Matching rule for compiling object files from C source
102 # The comments from the C++ rule above also apply here
104 $(CC) $(CFLAGS) -c $<