Override Make Variables
Variables in make can be set in a number of ways.
In the Makefile
The most common that we see is inside the Makefile itself, using the =, ?=, or := operators.
The = operator sets the value literally, allowing for dereference-time expansion. Thus, if I do
foo = bar baz = $(foo) yoink foo = gar
Then by the end, $(baz) will equal "gar yoink", because the $(foo) isn't expanded until the very last moment.
- If, on the other hand, I do
foo = bar baz := $(foo) yoink foo = gar
Then $(baz) will equal "bar yoink", because the := expands all vars immediately!
The ?= operator will only set vars that have not yet been already set. Thus:
foo = bar foo ?= gar
will leave $(foo) set to "bar", while
foo ?= gar foo ?= zoink
will leave it set to "gar", assuming that nothing else had been setting foo in the past.
From the Environment
Setting a variable from the environment will cause it to be set when the Makefile runs. Thus, if you set foo from the shell, and then exported it, the last example in the previous section would have no effect on foo at all!
Note that to achieve the equivalent of the = in the Makefile, you must use single-quotes to preserve the value. Thus, to set the $(baz) var in the same way as it's set in the very first example, one would have to do:
$ export baz='$(foo) yoink'
Hard Override
This is the magic that makes most things in GAR work. If you specify a variable on the make command line, it supercedes all other settings in the environment or in the Makefile. Thus,
$ make DESTDIR=/home/nick/destination/ install
Will set $(DESTDIR) to that path no matter what the Makefile itself does to it.
Actually, that's not entirely true, as the Makefile has an "override" directive that explicitly subverts these comand-line settings. It's deep magic, however, and is used in very few places!
The most common override is done using INSTALL_OVERRIDE_DIRS.