Roland Ver. 4.5 Informações Técnicas Página 133

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 212
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 132
Chapter 10: Using Implicit Rules 123
test’. The pattern rule prerequisites are turned into actual file names by substituting the
stem for the character %’. Thus, if in the same example one of the prerequisites is written
as %.c’, it expands to test.c’.
When the target pattern does not contain a slash (and it usually does not), directory
names in the file names are removed from the file name before it is compared with the target
prefix and suffix. After the comparison of the file name to the target pattern, the directory
names, along with the slash that ends them, are added on to the prerequisite file names
generated from the pattern rule’s prerequisite patterns and the file name. The directories
are ignored only for the purpose of finding an implicit rule to use, not in the application
of that rule. Thus, e%t matches the file name src/eat, with src/a as the stem. When
prerequisites are turned into file names, the directories from the stem are added at the front,
while the rest of the stem is substituted for the %’. The stem src/a with a prerequisite
pattern c%r gives the file name src/car.
A pattern rule can be used to build a given file only if there is a target pattern that
matches the file name, and all prerequisites in that rule either exist or can be built. The
rules you write take precedence over those that are built in. Note however, that a rule
whose prerequisites actually exist or are mentioned always takes priority over a rule with
prerequisites that must be made by chaining other implicit rules.
It is possible that more than one pattern rule will meet these criteria. In that case,
make will choose the rule with the shortest stem (that is, the pattern that matches most
specifically). If more than one pattern rule has the shortest stem, make will choose the first
one found in the makefile.
This algorithm results in more specific rules being preferred over more generic ones; for
example:
%.o: %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
%.o : %.f
$(COMPILE.F) $(OUTPUT_OPTION) $<
lib/%.o: lib/%.c
$(CC) -fPIC -c $(CFLAGS) $(CPPFLAGS) $< -o $@
Given these rules and asked to build bar.o where both bar.c and bar.f exist, make
will choose the first rule and compile bar.c into bar.o. In the same situation where bar.c
does not exist, then make will choose the second rule and compile bar.f into bar.o.
If make is asked to build lib/bar.o and both lib/bar.c and lib/bar.f exist, then the
third rule will be chosen since the stem for this rule (‘bar’) is shorter than the stem for the
first rule (‘lib/bar’). If lib/bar.c does not exist then the third rule is not eligible and
the second rule will be used, even though the stem is longer.
10.5.5 Match-Anything Pattern Rules
When a pattern rule’s target is just %’, it matches any file name whatever. We call these
rules match-anything rules. They are very useful, but it can take a lot of time for make to
think about them, because it must consider every such rule for each file name listed either
as a target or as a prerequisite.
Vista de página 132
1 2 ... 128 129 130 131 132 133 134 135 136 137 138 ... 211 212

Comentários a estes Manuais

Sem comentários