What is ?= in Makefile

LinuxLinux KernelMakefile

Linux Problem Overview


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

Linux Solutions


Solution 1 - Linux

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

Solution 2 - Linux

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncodedocView Question on Stackoverflow
Solution 1 - LinuxSimonView Answer on Stackoverflow
Solution 2 - LinuxcodedocView Answer on Stackoverflow