help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detect unset variables in gnu make


From: Philip Guenther
Subject: Re: Detect unset variables in gnu make
Date: Wed, 9 Apr 2014 07:36:53 -0700

On Tue, Apr 8, 2014 at 10:39 PM, Rakesh Sharma <address@hidden> wrote:
> Is there a way to find out if a variable is unset in a Makefile?

Yes, this can be done by testing the it with the $(origin) function.
For a variable that isn't set, $(origin VARIABLE) will return the word
"undefined".

...
> My goal was to trigger the DEBUG evaluation in Makefile based on the state of 
> the DEBUG variable. This can make from the environment (by way of: setenv 
> DEBUG), from the command line (make DEBUG=     goal),  as defined inside the 
> Makefile (DEBUG :=  1  ).

Many shell and make constructs treat empty and unset variables the
same.  Is there some reason to let your users treat empty as different
than unset?
Why not have them use 'make DEBUG=1' or 'make DEBUG=yes'?

Ah yes, there's also an advantage to having empty mean off: you can
set an environment variable to empty for just one make invocation on
the make command line, but unsetting it requires a separate command
and shell.  That is, this works to clear it:
    make DEBUG=

but to unset it you have to use
    ( unset DEBUG; make )               # sh syntax
    ( unsetenv DEBUG; make )         # csh syntax


So yes, you _can_ treat empty variables as different than unset
variables in make, but I would argue that you normally _shouldn't_.


Philip Guenther



reply via email to

[Prev in Thread] Current Thread [Next in Thread]