help-make
[Top][All Lists]
Advanced

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

Re: how to set an environment variable from within a makefile


From: Philip Guenther
Subject: Re: how to set an environment variable from within a makefile
Date: Sat, 17 Mar 2012 21:04:35 -0700

On Sat, Mar 17, 2012 at 8:34 PM, Mark Galeck (CW) <address@hidden> wrote:
> The export directive can be used to communicate variables to sub-makes.
>
> Is there a way to communicate a variable up-stream, or between makefiles in 
> the same depth of recursion.
> I thought I would try to setup an environment variable from within a 
> makefile, either using
>                FOOBAR=value
> in a recipe,
> or $(shell FOOBAR=value) , outside one.
>
> But this does not seem to work - it only works in the context of that same 
> makefile, but not outside of it,
>
> How can I do this through environment variables?

In UNIX, when a process creates a child process, the child process
gets its own environment, separate from that of the process that
created it.  There's nothing the child can do to affect the
environment of its parent.

Programs that have needed to do this are generally written to output
to stdout the variable assignments that are desired and then document
that their caller, the program that invokes them, should capture that
output and evaluate it.  For example, the 'tset' program is generally
invoked from shell startup scripts with something like this:
    eval `tset -sQ $TERM`

it writes to its stdout something like:
   TERM=screen;
   TERMCAP='screen:am:bs:<560 more bytes of termcap info>';
   export TERM TERMCAP

The eval `...` form then makes the shell capture that and parse it so
that the shell sets the variables in its own environment.


> (I can probably use writing to a file to store that information, but I would 
> rather use env variables).

Write it to a file and then include that in your other Makefiles.


Philip Guenther



reply via email to

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