Make and the ?= operator
The GNU crew improved Make with lots of handy stuff. One such gem that I found today is the
?= operator, which only defines a macro if it is not already defined (like as an environment variable). It behaves almost like wrapping the assignment in
ifndef. John Gramm-Cunning has a good explanation of this subtle difference.
Here’s an example of
?= in action.
INSTALL_HOST ?= firstname.lastname@example.org
The INSTALL_HOST macro will have the value “email@example.com” unless someone specifies it as an environment variable when invoking make. This makes its value easily overridable by users calling your Makfile, like this:
$ INSTALL_HOSTfirstname.lastname@example.org make install
I find it pretty handy.
However, I have one gripe. Make in general is tough to learn because its keywords and operators are not Googlable. Say I find the
?= operator in a Makefile and I want to look it up. Normally, I would just punch it into Google, but that just gives you a bunch of junk results. Not a huge deal, but it’s tough to find good docs out there for this reason