Chapter 3: Writing Makefiles 15
you can write an explicit rule with the makefile as the target, and an empty recipe (see
Section 5.9 [Using Empty Recipes], page 57).
If the makefiles specify a double-colon rule to remake a file with a recipe but no prereq-
uisites, that file will always be remade (see Section 4.12 [Double-Colon], page 38). In the
case of makefiles, a makefile that has a double-colon rule with a recipe but no prerequisites
will be remade every time make is run, and then again after make starts over and reads
the makefiles in again. This would cause an infinite loop: make would constantly remake
the makefile, and never do anything else. So, to avoid this, make will not attempt to re-
make makefiles which are specified as targets of a double-colon rule with a recipe but no
prerequisites.
If you do not specify any makefiles to be read with ‘-f’ or ‘--file’ options, make will try
the default makefile names; see Section 3.2 [What Name to Give Your Makefile], page 12.
Unlike makefiles explicitly requested with ‘-f’ or ‘--file’ options, make is not certain that
these makefiles should exist. However, if a default makefile does not exist but can be created
by running make rules, you probably want the rules to be run so that the makefile can be
used.
Therefore, if none of the default makefiles exists, make will try to make each of them in
the same order in which they are searched for (see Section 3.2 [What Name to Give Your
Makefile], page 12) until it succeeds in making one, or it runs out of names to try. Note
that it is not an error if make cannot find or make any makefile; a makefile is not always
necessary.
When you use the ‘-t’ or ‘--touch’ option (see Section 9.3 [Instead of Executing Recipes],
page 101), you would not want to use an out-of-date makefile to decide which targets to
touch. So the ‘-t’ option has no effect on updating makefiles; they are really updated even
if ‘-t’ is specified. Likewise, ‘-q’ (or ‘--question’) and ‘-n’ (or ‘--just-print’) do not
prevent updating of makefiles, because an out-of-date makefile would result in the wrong
output for other targets. Thus, ‘make -f mfile -n foo’ will update mfile, read it in, and
then print the recipe to update foo and its prerequisites without running it. The recipe
printed for foo will be the one specified in the updated contents of mfile.
However, on occasion you might actually wish to prevent updating of even the makefiles.
You can do this by specifying the makefiles as goals in the command line as well as specifying
them as makefiles. When the makefile name is specified explicitly as a goal, the options ‘-t’
and so on do apply to them.
Thus, ‘make -f mfile -n mfile foo’ would read the makefile mfile, print the recipe
needed to update it without actually running it, and then print the recipe needed to update
foo without running that. The recipe for foo will be the one specified by the existing
contents of mfile.
3.6 Overriding Part of Another Makefile
Sometimes it is useful to have a makefile that is mostly just like another makefile. You
can often use the ‘include’ directive to include one in the other, and add more targets or
variable definitions. However, it is invalid for two makefiles to give different recipes for the
same target. But there is another way.
In the containing makefile (the one that wants to include the other), you can use a
match-anything pattern rule to say that to remake any target that cannot be made from
Comentários a estes Manuais