]> git.ipfire.org Git - thirdparty/automake.git/commit
[ng] utils: new function 'am.vars.is-undef'
authorStefano Lattarini <stefano.lattarini@gmail.com>
Fri, 27 Jul 2012 18:30:11 +0000 (20:30 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Sat, 28 Jul 2012 08:15:21 +0000 (10:15 +0200)
commite2004fd5ed8420617af1d31b99228908b0a3b948
tree75b428485b1b073b83f354054e628fa914946018
parent3727413f33e44a9171e817ceb2e86743631dda9c
[ng] utils: new function 'am.vars.is-undef'

Sometimes, in our makefiles, we want to assign a default value to
a variable that might not have been assigned yet.  One might think
that using the GNU make assignment '?=' is enough:

    VAR ?= DEFAULT-VALUE

But alas, such a usage allows interferences from the environment; i.e.,
if an environment variable named 'VAR' is defined to, say, BAD-VALUE,
the construct above will result in the $(VAR) make variable being
defined to BAD-VALUE, not to DEFAULT-VALUE.

Use the 'am.vars.is-undef' function to avoid this situation.  It tells
whether the given make variable is not "safely" defined, i.e., either
undefined, or defined to a value that is inherited from the environment.

With such a tool, we can safely declare default values for variables
that avoids environmental interferences, as follow:

    ifeq ($(call am.vars.is-undef,VAR),yes)
      VAR = DEFAULT-VALUE
    endif

* lib/am/header-vars.am (am.vars.is-undef): New.
* t/internals.tap: Test it, and add few sanity checks.

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
lib/am/header-vars.am
t/internals.tap