help-make
[Top][All Lists]
Advanced

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

Re: simple question about variables in a rule


From: Robert P. J. Day
Subject: Re: simple question about variables in a rule
Date: Sun, 16 May 2004 08:01:18 -0400 (EDT)

On Sun, 16 May 2004, David Boyce wrote:

> At 06:51 AM 5/16/2004, Robert P. J. Day wrote:
...
> >target:
> >         @echo "A = $A"
> >         @echo "B = $B"
> >         ... rest of rule ...
> >
> >now, for efficiency, i'll always use these variables as "${A}/${B}", so i
> >just want to temporarily set that value to, say, C (and *only* within the
> >scope of this rule):
> 
> Classic make, per se, offers no help with this. By the time you're into the 
> command, make has handed off to the shell; you're not even operating in the 
> make process anymore and the shell has no access to make's symbol table. 

i had assumed something like that, i just wondered if there was some cute
make trick to deal with it.

> But this is easily solved by setting up quoting such that A and B are 
> expanded by make before handing off to the shell, whereas C is assigned as 
> a *shell* variable which is assigned and then expanded by the shell. This 
> in turn can be done two ways, either as an environment variable:
> 
> target:
>          @echo "A = $A"
>          @echo "B = $B"
>          C=$A/$B rest of rule ...
> 
> Or you can set up C as a regular (unexported) shell variable:
> 
> target:
>          @echo "A = $A"
>          @echo "B = $B"
>          C=$A/$B;\
>          rest of rule ...

neither of these really represent an option for me as the rule is fairly
long and involves including definition calls and loops and if statements.  
it's doable, i guess, but it would be fairly cumbersome, and i don't want 
to hack the makefile to that extent.

> I believe that with sufficiently modern versions of GNU make you could also 
> make use of "target-specific variables", e.g.
> 
> target: C = $A/$B
> 
> (see http://www.gnu.org/software/make/manual/html_mono/make.html#SEC77) for 
> details. But the traditional solution is probably preferable where applicable.

i just tried that with my version of make 3.79.1 on fedora core 1, and got

packages.mk:72: *** commands commence before first target.  Stop.

is this telling me that this version of make is not sufficiently modern?

rday

p.s.  the actual target line reads:

  mainpkg: PKG_ROOT = /tmp/${PKG_NAME}

where PKG_NAME is one of the variables passed in the make invocation:

  $ make PKG_NAME=blah mainpkg

so, apparently, this won't work for me.  time to sit and think about
how to handle this as gracefully as possible.




reply via email to

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