GNU make manual 翻译( 一百五十)

继续翻译

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.  *Note Defining Multi-Line Variables: Multi-Line, 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.

5.8 定义片段包
===========================

当同一个序列的命令在构建各种不同的目的时有用的时候,你可以通过 define 指令把它们定义为一个片段包,参照此包来为那些目的服务。片段包实际上是一个变量,因此名字必须不和其他变量名冲突。

这里有一个定义片段包的例子:

define run-yacc =
yacc $(firstword $^)
mv y.tab.c $@
endef

这里 'run-yacc' 是被定义的变量的名字; 'endef ' 标记了定义的结束;
两者之间是指令。'define' 指令并不扩展片段包中的变量和函数参照。'$' 符号, 括号, 变量名等等, 都成为你所定义的变量的值的一部份。如果要找完整的说明,请参考 *Note Defining Multi-Line Variables: Multi-Line。

在这个例子中的第一个命令在某个运用此片段包的规则的前提条件里,运行Yacc。从Yacc来的输出文件名总是 y.tab.c。第二个命令删除规则目的文件名的输出。

后文待续

你可能感兴趣的:(Make)