bug-make
[Top][All Lists]
Advanced

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

Re: export vs $(origin )


From: Paul Smith
Subject: Re: export vs $(origin )
Date: Thu, 02 Jul 2020 11:31:27 -0400
User-agent: Evolution 3.36.2-0ubuntu1

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.




reply via email to

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