On Thu, 2020-07-02 at 17:16 +0200, Jan Beulich wrote:
> > export wom
> > introduces the variable to the env and set origin to environment.
> 
> Not according to my observations.

The difference is whether the variable already exists in the
environment or not.

For this makefile:

  export FOO
  $(info FOO: $(origin FOO))
  all:;

If you run it like this:

  $ FOO= make
  FOO: environment
  make: 'all' is up to date.

But if you run it like this:

  $ unset FOO; make
  FOO: file
  make: 'all' is up to date.

Basically, if you run "export FOO" and FOO does not currently exist at
all, either in the environment or in the makefile, then it's created in
make and assigned a "file" origin.

I'm not sure how it could be otherwise: by specifying "export" you ARE
creating that variable, because it will be placed into the child's
environment when a recipe is invoked, even if it's not set.  In other
words, if FOO is not already a variable make knows about then running
"export FOO" makes it into a variable that make knows about, which has
its "export" flag set.

For example if you change the above makefile:

  export FOO
  $(info FOO: $(origin FOO))
  all: ; @env | grep FOO

then you run:

  $ unset FOO; make
  FOO: file
  FOO=
  make: 'all' is up to date.

you can see that "FOO" is in the environment in the recipe even though
it wasn't in the environment when make started.


  • export vs $(o... Jan Beulich
    • Re: expo... Dmitry Goncharov via Bug reports and discussion for GNU make
      • Re: ... Jan Beulich
        • ... Paul Smith
          • ... Jan Beulich
            • ... Paul Smith
              • ... Andreas Schwab
        • ... Dmitry Goncharov via Bug reports and discussion for GNU make

Reply via email to