On Mon, 2015-04-20 at 07:08 -0400, Robert P. J. Day wrote: > just want to make sure i understand the details of exporting > variables in gnu make.
It's trivial to test; write a makefile: all: ; @echo $$VAR then set VAR in different ways and see which ones cause this to echo the value. > 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? Yes. > 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? Yes. > 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. Correct. > finally, if i change the origin of the variable to: > > $ make VAR=value ... > > is that variable still part of the environment? Yes. See the GNU make manual "Communicating variables to sub-makes": 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. _______________________________________________ Help-make mailing list Help-make@gnu.org https://lists.gnu.org/mailman/listinfo/help-make