博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GNU make manual 翻译( 一百四十五)
阅读量:4565 次
发布时间:2019-06-08

本文共 3657 字,大约阅读时间需要 12 分钟。

继续翻译

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:     exportThis tells `make' that variables which are not explicitly mentioned inan `export' or `unexport' directive should be exported.  Any variablegiven in an `unexport' directive will still _not_ be exported.  If youuse `export' by itself to export variables by default, variables whosenames contain characters other than alphanumerics and underscores willnot be exported unless specifically mentioned in an `export' directive.   The behavior elicited by an `export' directive by itself was thedefault in older versions of GNU `make'.  If your makefiles depend onthis 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.  Thiswill be ignored by old `make's, while the `export' directive will causea syntax error.     Likewise, you can use `unexport' by itself to tell `make' _not_ toexport variables by default.  Since this is the default behavior, youwould 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 recipesand not for others.  The last `export' or `unexport' directive thatappears by itself determines the behavior for the entire run of `make'.   As a special feature, the variable `MAKELEVEL' is changed when it ispassed down from level to level.  This variable's value is a stringwhich 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 asub-sub-`make', and so on.  The incrementation happens when `make' setsup 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 canwrite a makefile that behaves one way if run recursively and anotherway 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 awhitespace-separated list of file names.  This variable, if defined inthe outer-level makefile, is passed down through the environment; thenit serves as a list of extra makefiles for the sub-`make' to readbefore 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 变量。

后文待续

转载于:https://www.cnblogs.com/gaojian/archive/2012/10/01/2709770.html

你可能感兴趣的文章
TP框架代码学习 学习记录 3.2.3
查看>>
doc文档生成带目录的pdf文件方法
查看>>
js数组,在遍历中删除元素(用 for (var i in arr)是无效的 )
查看>>
通过前端上传图片等文件的方法
查看>>
在 OC 中调用 Swift 代码
查看>>
Android仿腾讯应用宝 应用市场,下载界面, 有了进展button
查看>>
安卓|五大逆向软件下载
查看>>
5 OK6410裸机调试(不用Jlink)
查看>>
“模板”学习笔记(5)-----编译器在处理函数模板的时候都干了啥
查看>>
教你用shell写CGI程序
查看>>
窗口 对话框 Pop Dialog 示例
查看>>
ubuntu(centos) server安装vmware tools
查看>>
数据结构之最大不重复串
查看>>
为什么要配置sdk-tools/platform-toools?
查看>>
自己动手开发更好用的markdown编辑器-07(扩展语法)
查看>>
maven dependency:tree中反斜杠的含义
查看>>
队列的循环队列
查看>>
程序中的日期格式
查看>>
大众点评CAT错误总结以及解决思路
查看>>
MyEclipse 检出新项目后,如果项目名称签名有个红色感叹号
查看>>