help-make
[Top][All Lists]
Advanced

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

want to clarify ways to "export" a make variable


From: Robert P. J. Day
Subject: want to clarify ways to "export" a make variable
Date: Mon, 20 Apr 2015 07:08:31 -0400 (EDT)
User-agent: Alpine 2.11 (LFD 23 2013-08-11)

  just want to make sure i understand the details of exporting
variables in gnu make.

  first, if i set an environment variable either in the shell with:

  $ VAR=value
  $ export VAR
  $ make ...

or as a one-time thing on the make command line with:

  $ VAR=value make ...

is it true that that variable VAR is now part of the make invocation
environment and through all sub-make invocations? that is, there is no
need for me to "export" that variable agin in my Makefile -- it
wouldn't hurt but it's superfluous, and those two ways of doing it are
entirely equivalent? am i right so far?

  also, if i do the above, in any part of that invocation, i can
reassign the value of VAR, that new value would now be part of the
environment at that level and all further sub-makes, and there is of
course no need to "export" that variable again -- once it's part of
the environment, it stays in the environment (short of explicitly
"unexport"ing it). still good so far?

  next, i can always explicitly add a variable to the environment
within a Makefile with:

  export VAR

but if that variable is *already* in my environment from the command
line, the make "export" directive is superfluous -- again, doesn't
hurt, just unnecessary.

  finally, if i change the origin of the variable to:

  $ make VAR=value ...

is that variable still part of the environment? i realize that i have
the freedom to check the origin of a variable from within a Makefile,
but how does that last construct work with the environment compared to
the first versions?  thanks muchly.

rday

-- 

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================



reply via email to

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