[Top][All Lists]

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

Re: Using environmnet variables in make

From: Paul Smith
Subject: Re: Using environmnet variables in make
Date: Mon, 02 Mar 2009 09:50:35 -0500

On Mon, 2009-03-02 at 03:46 -0800, albob wrote:
>      Firstly thanks for all your help in this. I am getting a much better
> understanding of how make actually works (sub-shells etc). Is below a fair
> summary?

It's definitely true that to write good makefiles for situations which
are more than just simple compiles, you need at least a reasonable
understanding of shell programming.  Most of your questions here are
really about the shell, not make.

> 1) If I need the environment variable visable to all sub-shells of my make
> file I need to do the exprt externally to the sub-shells
> i.e.
> QA_STEP = start
> export QA_STEP
> test:
>    <do_something>

Right, although make supports the "all in one" syntax so you can just

    export QA_STEP = start

> 2) If it is only (and must only be) visible to a particular task in the make
> file I export it on the same line as the sub-process which needs to see it
> test:
>      @QA_STEP=start; export QA_STEP; <do-something>

Yes, although if <do-something> is a single command you can write it
much more succinctly as:

        @QA_STEP=start <do-something>

Again, this is a feature of the shell so you should be looking at the
shell docs for help with these things.

> 3) (An extension of 2 above) If within the task in the make file there are
> multiple commands which need to see the variable I need to have the export
> for each command ie.
>  test:
>      @QA_STEP=start; export QA_STEP; <do-something>
>      @QA_STEP=start; export QA_STEP; <do-something-else>

That would work, but more likely you would write:

        @QA_STEP=start; export QA_STEP; <do-something>; <do-something-else>

> Also as an aside, what is the purpose of the "@" at the start of the lines?

You should check the GNU make manual, or just try it and see the
difference; the "@" prefix tells make to not print the command line
before executing it.

 Paul D. Smith <address@hidden>          Find some GNU make tips at:            
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

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