What is ?= in Makefile

KDIR ?= $(shell uname -r)

What is the meaning of ?=?

I have understood the difference between :=, += and = from another thread available in Stack Overflow, but unable to find the explanation for ?=.

82306 次浏览

?=表示仅当没有设置/没有值时才设置 KDIR变量。

例如:

KDIR ?= "foo"
KDIR ?= "bar"


test:
echo $(KDIR)

会打印“ foo”

GNU 手册: http://www.gnu.org/software/make/manual/html_node/Setting.html

感谢西蒙和快速反应小组的快速和正确的反应。

此外,我还找到了 GNU 手册,其中详细解释了所有内容: Http://www.gnu.org/software/make/manual/html_node/setting.html