Makefile diff between ?= vs =.
- If you’d like a variable to be set to a value only if it’s not already set,
- then you can use the shorthand operator ‘?=’ instead of ‘=’.
Note: Got the comment as "Can you make this ?= so that it can be overriden in the invocation of the makefile?", so it will be good to use?=
These below two settings of the variable ‘FOO’ are identical
These below two settings of the variable ‘FOO’ are identical
FOO ?= bar
and
ifeq ($(origin FOO), undefined) FOO = bar endif
Program:
# ?= indicates to set the KDIR variable only if it's not set/doesn't have a value.KDIR ?= "?=foo"
KDIR ?= "?=bar"
EDIR = "=foo"
EDIR = "=bar"
test:
echo $(KDIR)
echo
echo $(EDIR)
Output:
~/velrajk/sample/makefile/make_?=$ make
echo "?=foo"
?=foo
echo
echo "=bar"
=bar
No comments:
Post a Comment