Chapter 10: Using Implicit Rules 125
new rule is defined, the built-in one is replaced. The new rule’s position in the sequence of
implicit rules is determined by where you write the new rule.
You can cancel a built-in implicit rule by defining a pattern rule with the same target
and prerequisites, but no recipe. For example, the following would cancel the rule that runs
the assembler:
%.o : %.s
10.6 Defining Last-Resort Default Rules
You can define a last-resort implicit rule by writing a terminal match-anything pattern rule
with no prerequisites (see Section 10.5.5 [Match-Anything Rules], page 123). This is just
like any other pattern rule; the only thing special about it is that it will match any target.
So such a rule’s recipe is used for all targets and prerequisites that have no recipe of their
own and for which no other implicit rule applies.
For example, when testing a makefile, you might not care if the source files contain real
data, only that they exist. Then you might do this:
%::
touch $@
to cause all the source files needed (as prerequisites) to be created automatically.
You can instead define a recipe to be used for targets for which there are no rules at
all, even ones which don’t specify recipes. You do this by writing a rule for the target
.DEFAULT. Such a rule’s recipe is used for all prerequisites which do not appear as targets
in any explicit rule, and for which no implicit rule applies. Naturally, there is no .DEFAULT
rule unless you write one.
If you use .DEFAULT with no recipe or prerequisites:
.DEFAULT:
the recipe previously stored for .DEFAULT is cleared. Then make acts as if you had never
defined .DEFAULT at all.
If you do not want a target to get the recipe from a match-anything pattern rule or
.DEFAULT, but you also do not want any recipe to be run for the target, you can give it an
empty recipe (see Section 5.9 [Defining Empty Recipes], page 57).
You can use a last-resort rule to override part of another makefile. See Section 3.6
[Overriding Part of Another Makefile], page 15.
10.7 Old-Fashioned Suffix Rules
Suffix rules are the old-fashioned way of defining implicit rules for make. Suffix rules are
obsolete because pattern rules are more general and clearer. They are supported in GNU
make for compatibility with old makefiles. They come in two kinds: double-suffix and
single-suffix.
A double-suffix rule is defined by a pair of suffixes: the target suffix and the source
suffix. It matches any file whose name ends with the target suffix. The corresponding
implicit prerequisite is made by replacing the target suffix with the source suffix in the file
name. A two-suffix rule whose target and source suffixes are ‘.o’ and ‘.c’ is equivalent to
the pattern rule ‘%.o : %.c’.
Comentários a estes Manuais