help-make
[Top][All Lists]
Advanced

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

Re: The -e option confuses the $(origin ) ?


From: Masahiro Yamada
Subject: Re: The -e option confuses the $(origin ) ?
Date: Mon, 13 Sep 2021 22:16:38 +0900

On Mon, Sep 13, 2021 at 9:23 PM Kaz Kylheku (gmake)
<729-670-0061@kylheku.com> wrote:
>
> On 2021-09-13 00:28, Masahiro Yamada wrote:
> > masahiro@oscar:~/workspace/foo$ export FOO=2
> > masahiro@oscar:~/workspace/foo$ make
> > Makefile:1: the origin of FOO is: environment
> > Makefile:2: the value of FOO is: 2
> > make -e -f Makefile.sub1 FOO=1
>
> Note that this FOO=1 will be exported to the environment. See the
> GNU Make 4.3 manual, section 5.7.2 Communicating Variables to a
> Sub-make:
>
>    "Except by explicit request, 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."


This is not answering my question.

I know both 'command line' and 'environment'
propagate variables down to sub-makes.
That is not what I am asking about.



If I remove -e from Makefile, I get this.

masahiro@oscar:~/workspace/foo$ make
Makefile:1: the origin of FOO is: undefined
Makefile:2: the value of FOO is:
make -f Makefile.sub1 FOO=1
make[1]: Entering directory '/home/masahiro/workspace/foo'
Makefile.sub1:1: the origin of FOO is: command line
Makefile.sub1:2: the value of FOO is: 1
make -f Makefile.sub2
make[2]: Entering directory '/home/masahiro/workspace/foo'
Makefile.sub2:1: the origin of FOO is: command line
Makefile.sub2:2: the value of FOO is: 1
make[2]: Leaving directory '/home/masahiro/workspace/foo'
make[1]: Leaving directory '/home/masahiro/workspace/foo'


Without -e, all the sub-makes remember that
FOO's origin is 'command line'.


By default, the strength of a variable is this order:
'command line' > 'file' > 'environment'



The manual says:

       -e, --environment-overrides
            Give variables taken from the environment  precedence  over  vari‐
            ables from makefiles.

It claims, with -e given, the order between 'file' and 'environment'
is swapped.


Variables that originate in 'command line'
take precedence over anything else.
This is true irrespective of -e.


There is no good reason to forget the origin of FOO.
Why should $(origin FOO) return 'environment' ?



> > make[1]: Entering directory '/home/masahiro/workspace/foo'
> > Makefile.sub1:1: the origin of FOO is: command line
> > Makefile.sub1:2: the value of FOO is: 1
> > make -f Makefile.sub2
> > make[2]: Entering directory '/home/masahiro/workspace/foo'
> > Makefile.sub2:1: the origin of FOO is: environment
> > Makefile.sub2:2: the value of FOO is: 1
>
> Here, we are seeing the value of FOO from the environment,
> as exported by make -e -f Makefile.sub1 FOO=1.
>
> (Since your makefiles do not define FOO themselves, the
> effect of -e is not being demonstrated.)


I do not intend to demonstrate the documented behavior.
I know. It works.

I am asking about the undocumented side-effect,
where $(origin FOO) is changed
from 'command line' to 'environment'.

I hope this clarifies my question.



-- 
Best Regards
Masahiro Yamada



reply via email to

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