make: Static Usage
1
1 4.12.1 Syntax of Static Pattern Rules
1 -------------------------------------
1
1 Here is the syntax of a static pattern rule:
1
1 TARGETS ...: TARGET-PATTERN: PREREQ-PATTERNS ...
1 RECIPE
1 ...
1
1 The TARGETS list specifies the targets that the rule applies to. The
1 targets can contain wildcard characters, just like the targets of
11 ordinary rules (⇒Using Wildcard Characters in File Names
Wildcards.).
1
1 The TARGET-PATTERN and PREREQ-PATTERNS say how to compute the
1 prerequisites of each target. Each target is matched against the
1 TARGET-PATTERN to extract a part of the target name, called the "stem".
1 This stem is substituted into each of the PREREQ-PATTERNS to make the
1 prerequisite names (one from each PREREQ-PATTERN).
1
1 Each pattern normally contains the character '%' just once. When the
1 TARGET-PATTERN matches a target, the '%' can match any part of the
1 target name; this part is called the "stem". The rest of the pattern
1 must match exactly. For example, the target 'foo.o' matches the pattern
1 '%.o', with 'foo' as the stem. The targets 'foo.c' and 'foo.out' do not
1 match that pattern.
1
1 The prerequisite names for each target are made by substituting the
1 stem for the '%' in each prerequisite pattern. For example, if one
1 prerequisite pattern is '%.c', then substitution of the stem 'foo' gives
1 the prerequisite name 'foo.c'. It is legitimate to write a prerequisite
1 pattern that does not contain '%'; then this prerequisite is the same
1 for all targets.
1
1 '%' characters in pattern rules can be quoted with preceding
1 backslashes ('\'). Backslashes that would otherwise quote '%'
1 characters can be quoted with more backslashes. Backslashes that quote
1 '%' characters or other backslashes are removed from the pattern before
1 it is compared to file names or has a stem substituted into it.
1 Backslashes that are not in danger of quoting '%' characters go
1 unmolested. For example, the pattern 'the\%weird\\%pattern\\' has
1 'the%weird\' preceding the operative '%' character, and 'pattern\\'
1 following it. The final two backslashes are left alone because they
1 cannot affect any '%' character.
1
1 Here is an example, which compiles each of 'foo.o' and 'bar.o' from
1 the corresponding '.c' file:
1
1 objects = foo.o bar.o
1
1 all: $(objects)
1
1 $(objects): %.o: %.c
1 $(CC) -c $(CFLAGS) $< -o $@
1
1 Here '$<' is the automatic variable that holds the name of the
1 prerequisite and '$@' is the automatic variable that holds the name of
1 the target; see ⇒Automatic Variables.
1
1 Each target specified must match the target pattern; a warning is
1 issued for each target that does not. If you have a list of files, only
1 some of which will match the pattern, you can use the 'filter' function
11 to remove non-matching file names (⇒Functions for String
Substitution and Analysis Text Functions.):
1
1 files = foo.elc bar.o lose.o
1
1 $(filter %.o,$(files)): %.o: %.c
1 $(CC) -c $(CFLAGS) $< -o $@
1 $(filter %.elc,$(files)): %.elc: %.el
1 emacs -f batch-byte-compile $<
1
1 In this example the result of '$(filter %.o,$(files))' is 'bar.o
1 lose.o', and the first static pattern rule causes each of these object
1 files to be updated by compiling the corresponding C source file. The
1 result of '$(filter %.elc,$(files))' is 'foo.elc', so that file is made
1 from 'foo.el'.
1
1 Another example shows how to use '$*' in static pattern rules:
1
1 bigoutput littleoutput : %output : text.g
1 generate text.g -$* > $@
1
1 When the 'generate' command is run, '$*' will expand to the stem, either
1 'big' or 'little'.
1