且构网

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

GNU make manual 翻译( 一百六十八)

更新时间:2022-09-25 08:56:55

继续翻译

GNU make manual 翻译( 一百六十八)
6.9 Undefining Variables
========================

If you want to clear a variable, setting its value to empty is usually
sufficient. Expanding such a variable will yield the same result (empty
string) regardless of whether it was set or not. However, if you are
using the `flavor' (*note Flavor Function::) and `origin' (*note Origin
Function::) functions, there is a difference between a variable that
was never set and a variable with an empty value.  In such situations
you may want to use the `undefine' directive to make a variable appear
as if it was never set. For example:

     foo := foo
     bar = bar

     undefine foo
     undefine bar

     $(info $(origin foo))
     $(info $(flavor bar))

   This example will print "undefined" for both variables.

   If you want to undefine a command-line variable definition, you can
use the `override' directive together with `undefine', similar to how
this is done for variable definitions:

     override undefine CFLAGS
GNU make manual 翻译( 一百六十八)

6.9 取消变量定义
========================

如果你想要清除一个变量,设置它的值为空通常是有效率的。扩展这样一个变量将会达到同样的效果(空串),无论它是否被设置了。但是如果你正在使用 flavor(*note Flavor Function::)或origin(*note Origin Function::)函数,对一个从没有设置过的变量和有一个空值的变量会有区别。在这种场合下,你也许想要使用 undefine 指令来使得一个变量看上去就好像从来没有设置过。例如:

foo := foo
bar = bar

undefine foo
undefine bar

$(info $(origin foo))
$(info $(flavor bar))

这个例子会给两个变量都打印出 "undefined"。

如果你想要取消一个命令行变量的定义,你可以将override 指令和 undefine结合使用,和如何为变量定义反向操作的做法类似:

override undefine CFLAGS

后文待续






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