GNU make manual 翻译( 一百五十一)

继续翻译

   To use the canned sequence, substitute the variable into the recipe

of a rule.  You can substitute it like any other variable (*note Basics

of Variable References: Reference.).  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 (*note Using Implicit Rules:

Implicit Rules.).



   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 subshell for each line.  You can

use the special prefix characters that affect command lines (`@', `-',

and `+') on each line of a canned sequence.  *Note Writing Recipes in

Rules: Recipes.  For example, using this canned sequence:



     define frobnicate =

     @echo "frobnicating target $@"

     frob-step-1 $< -o $@-step-1

     frob-step-2 $@-step-1 -o $@

     endef



`make' will not echo the first line, the `echo' command.  But it _will_

echo the following two recipe lines.



   On the other hand, prefix characters on the recipe line that refers

to a canned sequence apply to every line in the sequence.  So the rule:



     frob.out: frob.in

             @$(frobnicate)



does not echo _any_ recipe lines.  (*Note Recipe Echoing: Echoing, for

a full explanation of `@'.)

为了利用序列包,把变量替换到规则中的片段中去。你可以像使用其它变量一样替换它(*note Basics of Variable References: Reference.)。因为被 define定义的变量是递归性的扩展变量,所有你在变量参照中写的变量现在将立即扩展。例如:

foo.c : foo.y
$(run-yacc)

foo.y 会被利用以替换 run-yacc 中的 $^,而 foo.c 会被利用以替换 run-yacc 中的 $@

这是一个现实性的例子,但是这个特定的例子在实践中是没有必要的,因为 make 有一个隐式的规则利用相关的文件名来构建出这些命令(*note Using Implicit Rules: Implicit Rules)。

在片段的执行中,序列包的每移行都会被认为航向这个行就出现在规则中,前边被加了一个tab符号一般。在特定的场合下,make为每移行激活一个子shell。你可以在序列包的受到影响的命令行前用特定的前缀字符('@','-','+')。*Note Writing Recipes in Rules: Recipes. 例如,使用这个序列包:

define frobnicate =
@echo "frobnicating target $@"
frob-step-1 $< -o $@-step-1
frob-step-2 $@-step-1 -o $@
endef

make 不会显示出第一行的echo 指令,但是它会显示出接下来的两个片段行。

On the other hand, prefix characters on the recipe line that refers
to a canned sequence apply to every line in the sequence. So the rule:

另一方面,在片段行中的前缀字符会依照顺序应用到序列包的每一行。因此规则:

frob.out: frob.in
@$(frobnicate)

不会显示任何一个片段行。. (对@的完整解释,参考*Note Recipe Echoing: Echoing)

后文待续

你可能感兴趣的:(Make)