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

本文介绍了在Makefile中如何通过设置变量为空或者使用`undefine`指令来取消变量定义的方法,并对比了这两种方式的区别,特别是在使用`flavor`或`origin`函数时的不同表现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

继续翻译

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

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

后文待续

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值