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

简介:

继续翻译

复制代码
   You may nest `define' directives: `make' will keep track of nested
directives and report an error if they are not all properly closed with
`endef'.  Note that lines beginning with the recipe prefix character
are considered part of a recipe, so any `define' or `endef' strings
appearing on such a line will not be considered `make' directives.

     define two-lines =
     echo foo
     echo $(bar)
     endef

   The value in an ordinary assignment cannot contain a newline; but the
newlines that separate the lines of the value in a `define' become part
of the variable's value (except for the final newline which precedes
the `endef' and is not considered part of the value).

   When used in a recipe, the previous example is functionally
equivalent to this:

     two-lines = echo foo; echo $(bar)

since two commands separated by semicolon behave much like two separate
shell commands.  However, note that using two separate lines means
`make' will invoke the shell twice, running an independent subshell for
each line.  *Note Recipe Execution: Execution.

   If you want variable definitions made with `define' to take
precedence over command-line variable definitions, you can use the
`override' directive together with `define':

     override define two-lines =
     foo
     $(bar)
     endef

*Note The `override' Directive: Override Directive.
复制代码

你可以嵌套 define 指令:make 将会保持对嵌套的指令的跟踪,并且如果没有正确地以endef 结束将会报告错误。请注意,以片段前缀符号开始的行被认为是片段的一部分,因此任何define 或者 endef 串出现在这样一行不会被认为是 make 指令。

define two-lines =
echo foo
echo $(bar)
endef

在一个普通的赋值当中,使不能包含一个新行的;但是在define中分隔了值的各行的新行成为变量值得一部分(除了在 endef之后的那个新行,此新行不会被认为是值的一部分)。

在片段中使用,上一个例子就会等价于:

two-lines = echo foo; echo $(bar)

因为两个命令用分号分隔,看起来就像两个独立的shell 命令。但是,请注意使用两个独立的意味着 shell 必须被激活两次,为每一个行都要运行一个子shell。*Note Recipe Execution: Execution.

如果你想要使 define中定义的变量获得比命令行中的变量更高的优先级,你可以将define 和 override 指令结合起来使用:

override define two-lines =
foo
$(bar)
endef

*Note The `override' Directive: Override Directive.

后文待续





本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/10/04/2711496.html,如需转载请自行联系原作者

目录
相关文章
|
Linux C语言
make: gcc:命令未找到
make: gcc:命令未找到
make: gcc:命令未找到