Roland Ver. 4.5 Technické informace Strana 129

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 212
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 128
Chapter 10: Using Implicit Rules 119
Thus, a pattern rule %.o : %.c says how to make any file stem.o from another file
stem.c.
Note that expansion using % in pattern rules occurs after any variable or function ex-
pansions, which take place when the makefile is read. See Chapter 6 [How to Use Variables],
page 59, and Chapter 8 [Functions for Transforming Text], page 83.
10.5.1 Introduction to Pattern Rules
A pattern rule contains the character % (exactly one of them) in the target; otherwise, it
looks exactly like an ordinary rule. The target is a pattern for matching file names; the %
matches any nonempty substring, while other characters match only themselves.
For example, %.c as a pattern matches any file name that ends in .c’. s.%.c as
a pattern matches any file name that starts with s.’, ends in .c and is at least five
characters long. (There must be at least one character to match the %’.) The substring
that the % matches is called the stem.
% in a prerequisite of a pattern rule stands for the same stem that was matched by the
% in the target. In order for the pattern rule to apply, its target pattern must match the
file name under consideration and all of its prerequisites (after pattern substitution) must
name files that exist or can be made. These files become prerequisites of the target.
Thus, a rule of the form
%.o : %.c ; recipe...
specifies how to make a file n.o, with another file n.c as its prerequisite, provided that n .c
exists or can be made.
There may also be prerequisites that do not use %’; such a prerequisite attaches to every
file made by this pattern rule. These unvarying prerequisites are useful occasionally.
A pattern rule need not have any prerequisites that contain %’, or in fact any prerequi-
sites at all. Such a rule is effectively a general wildcard. It provides a way to make any file
that matches the target pattern. See
Section 10.6 [Last Resort], page 125.
More than one pattern rule may match a target. In this case make will choose the “best
fit” rule. See Section 10.5.4 [How Patterns Match], page 122.
Pattern rules may have more than one target. Unlike normal rules, this does not act as
many different rules with the same prerequisites and recipe. If a pattern rule has multiple
targets, make knows that the rule’s recipe is responsible for making all of the targets. The
recipe is executed only once to make all the targets. When searching for a pattern rule to
match a target, the target patterns of a rule other than the one that matches the target in
need of a rule are incidental: make worries only about giving a recipe and prerequisites to
the file presently in question. However, when this file’s recipe is run, the other targets are
marked as having been updated themselves.
10.5.2 Pattern Rule Examples
Here are some examples of pattern rules actually predefined in make. First, the rule that
compiles .c files into .o files:
%.o : %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
Zobrazit stránku 128
1 2 ... 124 125 126 127 128 129 130 131 132 133 134 ... 211 212

Komentáře k této Příručce

Žádné komentáře