且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-09-15 22:17:40

继续翻译

GNU make manual 翻译( 一百七十一)
   Target-specific variables have the same priority as any other
makefile variable.  Variables provided on the command line (and in the
environment if the `-e' option is in force) will take precedence.
Specifying the `override' directive will allow the target-specific
variable value to be preferred.

   There is one more special feature of target-specific variables: when
you define a target-specific variable that variable value is also in
effect for all prerequisites of this target, and all their
prerequisites, etc. (unless those prerequisites override that variable
with their own target-specific variable value).  So, for example, a
statement like this:

     prog : CFLAGS = -g
     prog : prog.o foo.o bar.o

will set `CFLAGS' to `-g' in the recipe for `prog', but it will also
set `CFLAGS' to `-g' in the recipes that create `prog.o', `foo.o', and
`bar.o', and any recipes which create their prerequisites.

   Be aware that a given prerequisite will only be built once per
invocation of make, at most.  If the same file is a prerequisite of
multiple targets, and each of those targets has a different value for
the same target-specific variable, then the first target to be built
will cause that prerequisite to be built and the prerequisite will
inherit the target-specific value from the first target.  It will
ignore the target-specific values from any other targets.
GNU make manual 翻译( 一百七十一)

目的特定的变量和其他的makefile 变量拥有同样的优先级。在命令行提供的变量(或者如果在环境变量中提供但是make运行时指定了 -e 选项)会拥有更高的优先级。指定override 指令可以允许 目的特定的变量拥有更高的优先级。

这里还有另外一个目的特定的变量的特殊功能:当你定义一个目的特定的变量,此变量的值也在此目的的所有前提条件中有效。前提条件的前提条件中也以此类推有效。(除非前提条件中用它们自己的目的特定的变量覆盖了此变量)。因此,例如一个像下面这样的:

prog : CFLAGS = -g
prog : prog.o foo.o bar.o

将会在针对 `prog'的片段里面,设置‘ CFLAGS' 为 `-g' , 但是也会在创建了 prog.o ,foo.o 和 bar.o 的片段里面,设置‘ CFLAGS' 为 `-g'。 在其他的创建了它们的前提条件的片段中也是这样。

需要清楚的是,一个前提条件在大多数情况下仅仅是在每次make激活时会被创建一次。如果一个同样的文件是多个目的的前提条件,并且每一个目的对此目的特定的变量有不同的值,那么第一个目的将要导致要建立的前提条件会继承第一个目的的目的特定的变量值。它会忽略其他的目的特定的变量值。

后文待续






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