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

继续翻译

6.8 Defining Multi-Line Variables
=================================

Another way to set the value of a variable is to use the `define'
directive.  This directive has an unusual syntax which allows newline
characters to be included in the value, which is convenient for
defining both canned sequences of commands (*note Defining Canned
Recipes: Canned Recipes.), and also sections of makefile syntax to use
with `eval' (*note Eval Function::).

   The `define' directive is followed on the same line by the name of
the variable being defined and an (optional) assignment operator, and
nothing more.  The value to give the variable appears on the following
lines.  The end of the value is marked by a line containing just the
word `endef'.  Aside from this difference in syntax, `define' works
just like any other variable definition.  The variable name may contain
function and variable references, which are expanded when the directive
is read to find the actual variable name to use.

   You may omit the variable assignment operator if you prefer.  If
omitted, `make' assumes it to be `=' and creates a recursively-expanded
variable (*note The Two Flavors of Variables: Flavors.).  When using a
`+=' operator, the value is appended to the previous value as with any
other append operation: with a single space separating the old and new
values.

6.8 定义多行变量
=================================

另一个设置一个变量的值的方法就是使用 define 指令。这个指令有一个不同寻常的语法,允许新行字符被包含在其中,方便我们定义命令序列包(*note Defining Canned Recipes: Canned Recipes.),并且也方便用 eval 函数来分隔makefile的语法(*note Eval Functions::)。

define指令在同一行的变量名后面,还有一个(可选的)赋值符号,再没有其他的了。

对变量的赋值出现在后面的行里,值的最后用一个仅仅包含单词'endef'来结尾。除了语法上的略有不同,define的工作方式就像其他的变量定义一样。 

变量名中可以博阿含函数或者变量参照,当是实际读取便来能够命的真实值的时候会被扩展。

如果愿意,你可以省略变量的赋值操作符。如果省略掉,make 假定它为 = ,轻且创建一个递归扩展式的变量(*note The Two Flavors of Variables: Flavors.)。当使用 +=操作符,值会附加到之前的值之上,和其他追加操作一样:有一个单独的空格在旧的和新的值之间。

后文待续

posted @ 2012-10-04 14:31  健哥的数据花园  阅读(278)  评论(0编辑  收藏  举报