[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: append to/from command line variable
From: |
Paul D. Smith |
Subject: |
Re: append to/from command line variable |
Date: |
Mon, 7 Nov 2005 09:33:51 -0500 |
%% "Martin d'Anjou" <address@hidden> writes:
md> I have no problem seeing what happens with make -e, but I don't
md> get why make prints $$FOO as empty in he first example and "boz
md> baz" in the second.
md> I guess I don't understand what happens behind the curtains when
md> "Make automatically exports all variables that were in the
md> environment ...".
The command:
echo FOO = $$FOO
is having the shell print the shell environment variable $FOO. It's NOT
printing the make variable $(FOO).
You know that a process inherits its environment from its parent, and
that it passes its environment to its children.
When make starts, it grabs all the environment variables it inherited
and instantiates them as make variables, too. Those variables are all
marked as "exported". When make runs a command (like the shell above),
it takes all the make variables marked as "exported", and uses that as
the environment of the command it runs.
So, in the first example there was no environment variable FOO inherited
by make, so that variable was not marked as "exported", and so it was
not put into the environment of the shell that was invoked, and so the
value printed was empty.
If you add FOO to the environment before calling make, then it will be
inherited from the environment and marked as exported (then you override
the value with something else, but the variable is still exported). So
it will be exported to the shell and have a value there as well.
HTH.
--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden> Find some GNU make tips at:
http://www.gnu.org http://make.paulandlesley.org
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist