[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Detect unset variables in gnu make
From: |
Rakesh Sharma |
Subject: |
RE: Detect unset variables in gnu make |
Date: |
Wed, 9 Apr 2014 11:40:46 -0700 |
Hello Guenther,
Thanks for the tips about the $(origin varname) function. That is solving the
problems I was having. As regards the value of the variable I like to keep them
in 3 domains:
unset <- never been defined (or undefined midway)
null <- defined but set to an empty value (/^$/) => length($var) = 0
nonnull <- defined & set to a nonnull value(even if all spaces /^\s+$/ or /\S/
or better still /./) => length($var) > 0
But like you mentioned, I am coming around to the fact that null or unset
variables need to be clubbed together in make.
I am finding a great dichotomy in the way make handles newlines embedded within
make variables. $(info ...$(string_with_NLs_) outputs ok,
but the same string when used inside recipies (i.e., shell) creates untold
misery. No amount of escaping, subst, etc. seem to help here.
Thanks,
Rakesh
> Date: Wed, 9 Apr 2014 07:36:53 -0700
> Subject: Re: Detect unset variables in gnu make
> From: address@hidden
> To: address@hidden
> CC: address@hidden
>
> 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