Makefile 四个赋值运算符 (=、:=、?=、+=),它们的区别

https://stackoverflow.com/questions/448910/what-is-the-difference-between-the-gnu-makefile-variable-assignments-a

VARIABLE = value(Lazy Set)

Normal setting of a variable - values within it are recursively expanded when the variable is used, not when it’s declared.

变量的正常设置-在使用变量时,变量中的值将递归展开,而不是在声明变量时展开。

VARIABLE := value (Lazy Set)

Setting of a variable with simple expansion of the values inside - values within it are expanded at declaration time.

用简单的内部值扩展来设置变量-声明时将扩展其中的值。

VARIABLE ?= value(Lazy Set If Absent)

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

仅当变量没有值时才设置该变量。值总是在访问变量时计算的。

VARIABLE += value(Append)

Appending the supplied value to the existing value (or setting to that value if the variable didn’t exist)

将提供的值附加到现有值(如果变量不存在,则将设置附加到该值)。

如果以上两个赋值的不能理解。

举个例子
x = foo
y = $(x) bar
x = xyz

以上y的值将会是 xyz bar。

x := foo
y := $(x) bar
x := xyz

以上y的值将会是 foo bar。

发布了148 篇原创文章 · 获赞 6 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/LU_ZHAO/article/details/104900214