GNU make manual 翻译( 一百四十五)

继续翻译

   You may notice that the `export' and `unexport' directives work in

`make' in the same way they work in the shell, `sh'.



   If you want all variables to be exported by default, you can use

`export' by itself:



     export



This tells `make' that variables which are not explicitly mentioned in

an `export' or `unexport' directive should be exported.  Any variable

given in an `unexport' directive will still _not_ be exported.  If you

use `export' by itself to export variables by default, variables whose

names contain characters other than alphanumerics and underscores will

not be exported unless specifically mentioned in an `export' directive.



   The behavior elicited by an `export' directive by itself was the

default in older versions of GNU `make'.  If your makefiles depend on

this behavior and you want to be compatible with old versions of

`make', you can write a rule for the special target

`.EXPORT_ALL_VARIABLES' instead of using the `export' directive.  This

will be ignored by old `make's, while the `export' directive will cause

a syntax error.  



   Likewise, you can use `unexport' by itself to tell `make' _not_ to

export variables by default.  Since this is the default behavior, you

would only need to do this if `export' had been used by itself earlier

(in an included makefile, perhaps).  You *cannot* use `export' and

`unexport' by themselves to have variables exported for some recipes

and not for others.  The last `export' or `unexport' directive that

appears by itself determines the behavior for the entire run of `make'.



   As a special feature, the variable `MAKELEVEL' is changed when it is

passed down from level to level.  This variable's value is a string

which is the depth of the level as a decimal number.  The value is `0'

for the top-level `make'; `1' for a sub-`make', `2' for a

sub-sub-`make', and so on.  The incrementation happens when `make' sets

up the environment for a recipe.



   The main use of `MAKELEVEL' is to test it in a conditional directive

(*note Conditional Parts of Makefiles: Conditionals.); this way you can

write a makefile that behaves one way if run recursively and another

way if run directly by you.



   You can use the variable `MAKEFILES' to cause all sub-`make'

commands to use additional makefiles.  The value of `MAKEFILES' is a

whitespace-separated list of file names.  This variable, if defined in

the outer-level makefile, is passed down through the environment; then

it serves as a list of extra makefiles for the sub-`make' to read

before the usual or specified ones.  *Note The Variable `MAKEFILES':

MAKEFILES Variable.

你也许注意到了 export 和 unexport 指令在make的工作方式和shell的工作方式一致。

如果你想要所有的变量都被缺省地导出,你可以用 export 自身:

export

这告诉make ,没有被显式地在export 或者unexport 中提及的变量,将被导出。任何在unexport指令 中给出的变量仍然不会到处。如果你使用了export自身来缺省地导出变量,名字中包含其他字符的变量将不会导出,除非你在export 指令中特别提及。

被一个export 自身指令引出的行为在旧版本的GNU make 中是缺省的。如果你的makefile依赖于这种行为而且你想要保持对旧版本make的兼容性,你可以为特殊目的 .EXPORT_ALL_VARIABLES 写一个规则,而不是用 export 指令。这个将被旧版本的 make 忽略掉,此时,export 指令会导致一个语法错误。

类似地,你可以使用 unexport 自身来告诉make 缺省地不要到处变量。因为这是缺省的行为,如果export 自身已经被之前使用了(也许是在一个被包含了的makefile里面)你只需要使用 unexport自身就行了。你不能在某些片段里通过使用export自身来导出某些变量同时又通过使用 unexport自身来缺省不导出某些变量。最后出现的export 或者 unexport 指令会决定整个make的行为。

作为一个特殊的功能,变量 MAKELEVEL 在从一层向下一层传递的时候会改变。这个变量的值是一个字符串,是一个10进制数字的深度值。顶级make为0,子make为1,子-子make为2,以此类推。make为一个片段设置环境的时候,发生数值增长。

MAKELEVEL的主要用途是在一个条件性的指令中测试(*note Conditional Parts of Makefiles:Conditionals.);这样你可以写一个makefile, 在某种条件下递归运行,另外一种条件下直接运行。

你可以使用变量 MAKEFILES来导致所有的make 命令用额外的makefile。MAKEFILES的值是一个空格分隔的文件名字列表。这个值,被定义在外层makefile中,在环境中向下传递;然后给子make提供一个增强makefile列表来读取。*Note The Variable 'MAKEFILES': MAKEFEILES 变量。

后文待续

你可能感兴趣的:(Make)