help-make
[Top][All Lists]
Advanced

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

RE: simply expanded variable getting overwritten


From: Paul Smith
Subject: RE: simply expanded variable getting overwritten
Date: Mon, 20 Aug 2007 22:51:45 -0400

On Mon, 2007-08-20 at 16:15 +0100, Dave Korn wrote:
> Anyway, the problem is that CLCMD doesn't get expanded when the rule
> for $(loc_mod)_clean is defined, but when it gets executed.  By that
> time, only the last definition of CLCMD still remains.  Now, the first
> thing that might spring to mind would be to do:
> 
> $(loc_mod)_CLCMD:=  Module/$(loc_mod)/*.bak
> 
> $(loc_mod)_clean:
>         @echo $($(loc_mod)_CLCMD)
> 
> but that suffers the same problem: loc_mod doesn't get expanded until
> the rule is run, by which time it too has the problem.
> 
> To get it expanded earlier, you need an eval:
> 
> define clean_rule
> $(loc_mod)_clean:
>         @echo $$($(loc_mod)_CLCMD)
> endef
> 
> $(eval $(call clean_rule))

You don't need eval for this.  There are a number of ways to do it.  A
more-or-less portable way (works with all versions of GNU make and many
other versions of make, but not all), would be to use automatic
variables:

        $(loc_mod)_CLCMD := Module/$(loc_mod)/*.bak
        
        $(loc_mod)_clean:
                @echo $($(@:_clean=)_CLCMD)

Another, slightly fancier option would be to use target-specific
variables:

        $(loc_mod)_clean: CLCMD := Module/$(loc_mod)/*.bak
        $(loc_mod)_clean:
                @echo $(CLCMD)

-- 
-------------------------------------------------------------------------------
 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




reply via email to

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