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

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 212
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 65
56 GNU make
Normally, you do not need to specify this option because make does it for you: -w
is turned on automatically when you use the -C option, and in sub-makes. make will
not automatically turn on -w if you also use -s’, which says to be silent, or if you use
--no-print-directory to explicitly disable it.
5.8 Defining Canned Recipes
When the same sequence of commands is useful in making various targets, you can define
it as a canned sequence with the define directive, and refer to the canned sequence from
the recipes for those targets. The canned sequence is actually a variable, so the name must
not conflict with other variable names.
Here is an example of defining a canned recipe:
define run-yacc =
yacc $(firstword $^)
mv y.tab.c $@
endef
Here run-yacc is the name of the variable being defined; endef marks the end of the
definition; the lines in between are the commands. The define directive does not expand
variable references and function calls in the canned sequence; the $ characters, parentheses,
variable names, and so on, all become part of the value of the variable you are defining. See
Section 6.8 [Defining Multi-Line Variables], page 69, for a complete explanation of define.
The first command in this example runs Yacc on the first prerequisite of whichever rule
uses the canned sequence. The output file from Yacc is always named y.tab.c. The second
command moves the output to the rule’s target file name.
To use the canned sequence, substitute the variable into the recipe of a rule. You
can substitute it like any other variable (see Section 6.1 [Basics of Variable References],
page 59). Because variables defined by define are recursively expanded variables, all the
variable references you wrote inside the define are expanded now. For example:
foo.c : foo.y
$(run-yacc)
foo.y will be substituted for the variable $^ when it occurs in run-yacc’s value, and
foo.c for $@’.
This is a realistic example, but this particular one is not needed in practice because
make has an implicit rule to figure out these commands based on the file names involved
(see Chapter 10 [Using Implicit Rules], page 111).
In recipe execution, each line of a canned sequence is treated just as if the line appeared
on its own in the rule, preceded by a tab. In particular, make invokes a separate sub-shell for
each line. You can use the special prefix characters that affect command lines (‘@’, -’, and
+’) on each line of a canned sequence. See Chapter 5 [Writing Recipes in Rules], page 41.
For example, using this canned sequence:
define frobnicate =
@echo "frobnicating target $@"
frob-step-1 $< -o $@-step-1
frob-step-2 $@-step-1 -o $@
endef
Vista de página 65
1 2 ... 61 62 63 64 65 66 67 68 69 70 71 ... 211 212

Comentários a estes Manuais

Sem comentários