help-make
[Top][All Lists]
Advanced

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

Re: a couple more questions about variables and scope


From: Noel Yap
Subject: Re: a couple more questions about variables and scope
Date: Wed, 09 Jun 2004 09:54:27 -0400
User-agent: Mozilla Thunderbird 0.5 (Windows/20040212)

Robert P. J. Day wrote:
(apologies if these are trivial questions -- it seems like the info on variables and scope/exports is sort of scattered across chapters in the make manual.)

  i think i finally got a grip on variables.  as i see it, when i invoke
"make", i can define variables in one of three ways:

  a) $ export FOO=bar
     $ make ...

  b) $ FOO=bar make ...

  c) $ make FOO=bar ...

techniques a) and b) above are effectively identical (at least from the
point of view of the make command) since they both define a variable in
the *shell's* environment to be passed to the make command, correct? the
only difference, of course, is whether the FOO env variable still exists
after the call to make, but strictly from the perspective of the make
command, approaches a) and b) are identical, right?

Correct.

next, in all three cases, as long as i don't try to mess with the value of FOO in the makefiles, that variable will be available throughout *all*
recursive make calls, correct?

Yes.

  there *is*, of course, a difference between a)/b) and c) in that, in the
docs, a) and b) refer to getting a variable from the "environment", while
c) is described as getting a variable value as a "command argument", and
those situations are clearly processed differently depending on whether
you want to override that value in the makefile, etc. that is, a simple
assignment in a makefile will override a value coming in as part of the
*environment*, but not as a command argument (unless you use the
"override" directive, etc.).  is this accurate so far?

This sounds familiar although I haven't memorized the details.  IMHO, taking 
advantage of this doesn't scale well since no one ever remembers the details.

In addition, c), and only c), allows passing of variables whose names contain 
characters that are illegal in shell variables.

if so, one more question. does all this hold when i make a recursive make call? that is, if i define a variable within a makefile and "export" it, does it have all the properties of a regular environment variable that i would have received from the shell, as opposed to passing that variable
as a command argument?

I believe so, but I can't say for sure since I try to stay away from recursive 
make.

HTH,
Noel




reply via email to

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