Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 231
codedoc Avatar asked Jul 16 '14 09:07

codedoc


People also ask

What does ?= In makefile mean?

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

What does %O %c mean in makefile?

The simple answer is that %.o is a target that matches any file ending in .o. "%.o: %. c" means that any file ending in .o depends on the same filename ending in . c to be present.

What is $$ in makefile?

$$ means be interpreted as a $ by the shell. the $(UNZIP_PATH) gets expanded by make before being interpreted by the shell.

What is Percent symbol in makefile?

If there is a wildcard symbol (%) in the pattern, this will match any number of characters, and these characters are copied into the replacement string at the place of the % in the second argument.


2 Answers

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

like image 81
Simon Avatar answered Sep 22 '22 14:09

Simon


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

like image 42
codedoc Avatar answered Sep 25 '22 14:09

codedoc