36 GNU make
If none of the explicit rules for a target has a recipe, then make searches for an applicable
implicit rule to find one see Chapter 10 [Using Implicit Rules], page 111).
4.11 Static Pattern Rules
Static pattern rules are rules which specify multiple targets and construct the prerequisite
names for each target based on the target name. They are more general than ordinary rules
with multiple targets because the targets do not have to have identical prerequisites. Their
prerequisites must be analogous, but not necessarily identical.
4.11.1 Syntax of Static Pattern Rules
Here is the syntax of a static pattern rule:
targets ...: target-pattern: prereq-patterns ...
recipe
...
The targets list specifies the targets that the rule applies to. The targets can contain
wildcard characters, just like the targets of ordinary rules (see Section 4.3 [Using Wildcard
Characters in File Names], page 23).
The target-pattern and prereq-patterns say how to compute the prerequisites of each
target. Each target is matched against the target-pattern to extract a part of the target
name, called the stem. This stem is substituted into each of the prereq-patterns to make
the prerequisite names (one from each prereq-pattern).
Each pattern normally contains the character ‘%’ just once. When the target-pattern
matches a target, the ‘%’ can match any part of the target name; this part is called the
stem. The rest of the pattern must match exactly. For example, the target foo.o matches
the pattern ‘%.o’, with ‘foo’ as the stem. The targets foo.c and foo.out do not match
that pattern.
The prerequisite names for each target are made by substituting the stem for the ‘%’ in
each prerequisite pattern. For example, if one prerequisite pattern is %.c, then substitution
of the stem ‘foo’ gives the prerequisite name foo.c. It is legitimate to write a prerequisite
pattern that does not contain ‘%’; then this prerequisite is the same for all targets.
‘%’ characters in pattern rules can be quoted with preceding backslashes (‘\’). Back-
slashes that would otherwise quote ‘%’ characters can be quoted with more backslashes.
Backslashes that quote ‘%’ characters or other backslashes are removed from the pattern
before it is compared to file names or has a stem substituted into it. Backslashes that
are not in danger of quoting ‘%’ characters go unmolested. For example, the pattern
the\%weird\\%pattern\\ has ‘the%weird\’ preceding the operative ‘%’ character, and
‘pattern\\’ following it. The final two backslashes are left alone because they cannot
affect any ‘%’ character.
Here is an example, which compiles each of foo.o and bar.o from the corresponding .c
file:
Comentários a estes Manuais