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

简介:

继续翻译

复制代码
5.3 Recipe Execution
====================

When it is time to execute recipes to update a target, they are
executed by invoking a new subshell for each line of the recipe, unless
the `.ONESHELL' special target is in effect (*note Using One Shell: One
Shell.)  (In practice, `make' may take shortcuts that do not affect the
results.)

   *Please note:* this implies that setting shell variables and
invoking shell commands such as `cd' that set a context local to each
process will not affect the following lines in the recipe.(1)  If you
want to use `cd' to affect the next statement, put both statements in a
single recipe line.  Then `make' will invoke one shell to run the
entire line, and the shell will execute the statements in sequence.
For example:

     foo : bar/lose
             cd $(@D) && gobble $(@F) > ../$@

Here we use the shell AND operator (`&&') so that if the `cd' command
fails, the script will fail without trying to invoke the `gobble'
command in the wrong directory, which could cause problems (in this
case it would certainly cause `../foo' to be truncated, at least).

   ---------- Footnotes ----------

   (1) On MS-DOS, the value of current working directory is *global*, so
changing it _will_ affect the following recipe lines on those systems.
复制代码

5.3 片段执行
====================

当到了执行片段去改变一个目的的时候,会通过为片段中的每一行激活一个新的子shell来执行。除非.ONESHELL 特殊目的起了效果(*note Using One Shell: One Shell)。

 

*请注意:* 设置shell变量或者如cd 等命令来设置的本地上下文并不会影响后面的片段行。如果你想要用cd 来影响下一个句子,可以把所有的子句放入到一个单独的行里。 然后,make 会激活一个shell 来运行整个的行,并且shell 会按照序列运行这些句子:

foo : bar/lose
cd $(@D) && gobble $(@F) > ../$@

这里我们使用 shell 的 与操作符 ,这样 如果 cd 命令失败,整个脚本将失败,不会再在错误的目录里激活 gobble 命令,不至于导致问题(在上述例子中,至少会导致 ../foo被 删除)

---------- 脚注 ----------

(1) On MS-DOS, the value of current working directory is *global*, so
changing it _will_ affect the following recipe lines on those systems.

(1) 在 MS-DOS 系统里面,当前工作目录是 *global*, 因此改变了它的话,会影响后面的行。

后文待续




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

目录
相关文章
|
Linux C语言
make: gcc:命令未找到
make: gcc:命令未找到
make: gcc:命令未找到
|
C语言 C++ Perl
如何处理错误消息Please install the gcc make perl packages
如何处理错误消息Please install the gcc make perl packages
144 0