GNU Makefile变量赋值=,?=,:=和+ =有什么区别? [英] What is the difference between the GNU Makefile variable assignments =, ?=, := and +=?
问题描述
任何人都可以清楚地说明变量赋值在Makefiles中是如何工作的.
Can anybody give a clear explanation of how variable assignment really works in Makefiles.
之间的区别是什么:
VARIABLE = value
VARIABLE ?= value
VARIABLE := value
VARIABLE += value
我已经阅读了GNU Make的部分.手册,但对我来说仍然没有意义.
I have read the section in GNU Make's manual, but it still doesn't make sense to me.
推荐答案
懒惰集
VARIABLE = value
变量的常规设置-使用变量而不是声明变量时,递归扩展其中的值
Normal setting of a variable - values within it are recursively expanded when the variable is used, not when it's declared
VARIABLE := value
使用内部值的简单扩展设置变量-声明时扩展其中的值.
Setting of a variable with simple expansion of the values inside - values within it are expanded at declaration time.
VARIABLE ?= value
仅在没有值的情况下设置变量.访问VARIABLE
时始终评估value
.等同于
Setting of a variable only if it doesn't have a value. value
is always evaluated when VARIABLE
is accessed. It is equivalent to
ifeq ($(origin FOO), undefined)
FOO = bar
endif
有关详细信息,请参见文档.
See the documentation for more details.
VARIABLE += value
将提供的值附加到现有值(如果变量不存在,则设置为该值)
Appending the supplied value to the existing value (or setting to that value if the variable didn't exist)
这篇关于GNU Makefile变量赋值=,?=,:=和+ =有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!