target needs to be rebuilt. The commands can be any shell command, so
long as the target is up to date at the
end of them. It is imperative that you
indent the commands with a tab character and not spaces. This is a design
flaw in make that has yet to be fixed,
and it will cause some strange and
obscure errors should you use spaces
instead of tabs in your makefile.
When make encounters a rule, it first
checks the files listed in the dependency
list to ensure that they haven’t changed.
If one of them has, make looks through
the makefile for the rule containing
that file as the target. This recursion
continues until a rule is found where
all the dependencies are unchanged or
rebuilt (or have no further dependencies), and then make executes the listed
commands for that rule before returning
to the previous rule, and so on, until
the root rule has been satisfied and its
commands run.
You may use pattern-matching characters to describe dependencies in the
dependency list or in commands, but
they may not be used in the target.
Phony Targets
Phony targets (also called dummy or
pseudo-targets) are not real files; they
simply are aliases within the makefile.
As I mentioned before, you can specify
targets from the command line, and this
is precisely what phony targets are used
for. If you’re familiar with the process of
78 | SEPTEMBER 2011 WWW.LINUXJOURNAL.COM
using make to build applications on
your system, you’re familiar with make install (which installs the application
after compiling the source) or make clean (which cleans up the temporary
files created while compiling the
source). These are two examples of
phony targets. Obviously, there are no
“install” or “clean” files in the project;
they’re just aliases to a set of commands
set aside to complete some task not
dependent on the modification time
of any particular file in the project.
Here is an example of using a “clean”
phony target:
Special Targets
Some special targets are built in to
make. These special targets hold special
meaning, and they modify the way make
behaves during execution:
.PHONY — this target signifies which
other targets are phony targets. If a
target is listed as a dependency of
.PHONY, the check to ensure that the
target file was updated is not performed. This is useful if at any time
your project actually produces a file
named the same as a phony target;
this check always will fail when executing your phony target.
.SUFFIXES — the dependency list of
this target is a list of the established file
suffixes for this project. This is helpful