bug-make
[Top][All Lists]
Advanced

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

Re: [regression] make 4.0+ breaks 'export' when '-e' option is given


From: Paul Smith
Subject: Re: [regression] make 4.0+ breaks 'export' when '-e' option is given
Date: Tue, 09 Feb 2016 14:47:41 -0500

On Tue, 2016-02-09 at 20:18 +0100, Enrico Scholz wrote:
> GNU make 4.0 seems to implement the behavior described in its
> documentation:
> 
> > 5.7.2 Communicating Variables to a Sub-`make'
> > ...
> > `make' exports a variable only if it is either defined in the environment
> > initially or set on the command line, and if its name consists only of
> > letters, numbers, and underscores.
> 
> E.g. I will *not* pass 'a-b' to its sub makes.

Not so.

That's not what that paragraph intends to say, and not what happens. It
means make only exports a variable *to the shell* if it's a valid shell
environment variable--shell environment variables can only contain
alphanumerics plus underscores.

That statement is not related to *make* variable assignments, which is
what you are using.  All make variables on the command line are always
provided to all sub-makes and will be considered command-line make
variable assignments in the sub-make as well.

The above paragraph says that IN ADDITION TO THAT, command-line
variables which are valid shell variables will be automatically
exported as shell variables.

If you try it you'll find this is true, of every version of make.

Consider this makefile:

  FOO = bar

  a-b = my-a-b
  a_b = my-a_b

  a:
        ${MAKE} -f ${firstword ${MAKEFILE_LIST}} b

  b:
        @echo TEST1 '>${a-b}<'
        @echo TEST2 '>${a_b}<'
        @echo TEST3 ">$${a-b}<"
        @echo TEST4 ">$${a_b}<"

Yields:

  $ make a-b='ok ab $(FOO) a-b=XXX' a_b='ok ab ${FOO} a_b=XXX'
  make -f Makefile b
  TEST1 >ok ab bar a-b=XXX<
  TEST2 >ok ab bar a_b=XXX<
  TEST3 >b<
  TEST4 >ok ab bar a_b=XXX<

For TEST1 and TEST2 you can see that the value provided on the command
line is present in the sub-make even though I didn't export anything,
as expected.

Note that for TEST4 I'm showing the _shell_ variable $a_b, which has
been exported to the shell as per the paragraph of the manual you
document.

For TEST3 you can see that this means something entirely different
(show $a if it is set, else show "b").  The shell can't have a variable
named "a-b".

> When you run my example without the 'export' line, you get with '-e':
> 
> > TEST1 ><
> > TEST2 >ok ab bar a_b=XXX<

Yes, I'd say this is a bug.

However, it's entirely orthogonal from what you want to do, as far as
you've described here.



reply via email to

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