What is ?= in Makefile

codedoc picture codedoc · Jul 16, 2014 · Viewed 46.7k times · Source
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 ?=.

Answer

Simon picture Simon · Jul 16, 2014

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