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

继续翻译

6.13 Suppressing Inheritance

============================



As described in previous sections, `make' variables are inherited by

prerequisites.  This capability allows you to modify the behavior of a

prerequisite based on which targets caused it to be rebuilt.  For

example, you might set a target-specific variable on a `debug' target,

then running `make debug' will cause that variable to be inherited by

all prerequisites of `debug', while just running `make all' (for

example) would not have that assignment.



   Sometimes, however, you may not want a variable to be inherited.  For

these situations, `make' provides the `private' modifier.  Although

this modifier can be used with any variable assignment, it makes the

most sense with target- and pattern-specific variables.  Any variable

marked `private' will be visible to its local target but will not be

inherited by prerequisites of that target.  A global variable marked

`private' will be visible in the global scope but will not be inherited

by any target, and hence will not be visible in any recipe.



   As an example, consider this makefile:

     EXTRA_CFLAGS =



     prog: private EXTRA_CFLAGS = -L/usr/local/lib

     prog: a.o b.o



   Due to the `private' modifier, `a.o' and `b.o' will not inherit the

`EXTRA_CFLAGS' variable assignment from the `progs' target.

6.13 抑制继承
============================

在前面的章节中所描述的那样,make 变量通过前提条件继承。这个能力允许你根据目的,去改变一个前提条件的行为。例如,你可能在一个叫debug的目的上设置列一个目的特定的变量,然后运行 make debug。这可以导致变量被所有debug 的前提条件所继承。但是运行 make all(例如)就不会有这些赋值。

A global variable marked
`private' will be visible in the global scope but will not be inherited
by any target, and hence will not be visible in any recipe.

但是有时候,你也许不希望一个变量被继承。在这种场合下,make 提供了一个 private 修饰符。尽管这个private 修饰符可以用在任何变量赋值上面,到那时它在目的或者模式特定的变量赋值上面更有意义。任何标记为 private 的目的仅仅对本地的目的可见,并且不会被其前提条件所继承。

考虑下面的例子:
EXTRA_CFLAGS =

prog: private EXTRA_CFLAGS = -L/usr/local/lib
prog: a.o b.o

由于`private' 修饰符的关系, `a.o' 和 `b.o' 将不会从prog目的 继承 
`EXTRA_CFLAGS' 变量。

后文待续

你可能感兴趣的:(Make)