What is ?= in Makefile

2020-05-24 18:51发布

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 ?=.

2条回答
甜甜的少女心
2楼-- · 2020-05-24 19:26

?= indicates to set the KDIR variable only if it's not set/doesn't have a value.

For example:

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

test:
    echo $(KDIR)

Would print "foo"

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

查看更多
够拽才男人
3楼-- · 2020-05-24 19:27

Thanks to Simon and R.T. for their quick and correct response.

Also, I have found the GNU manual that explains everything in detail: http://www.gnu.org/software/make/manual/html_node/Setting.html

查看更多
登录 后发表回答