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: Dave Korn
Subject: RE: simply expanded variable getting overwritten
Date: Mon, 20 Aug 2007 16:15:26 +0100

On 20 August 2007 15:45, Dave Korn wrote:

> On 20 August 2007 14:10, micron_make wrote:
> 
>> When I run
>>> make one_clean
>> I get Module/two/*.bak i.e. loc_mod is two  and not one.
> 
>   When I run it, I get an warning message.
> 
> 
> /tmp/EXP_MOD_NAM $ make
> Module/two/gen.mak:14: warning: overriding commands for target `_clean'
> Module/one/gen.mak:14: warning: ignoring old commands for target `_clean'
> Module//*.bak
> 
> 
>   It's kind of frustrating trying to solve a problem when you lie to us
> about the code you are running.  How about showing us what you're ACTUALLY
> running, by cutting and pasting, because when you manually retype it you
> introduce errors?

  Ah, local_mod != loc_mod, that's fixed it, now I can reproduce the problem.

/tmp/EXP_MOD_NAM $ make
Module/two/*.bak


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

... which I think gives the results you want:

/tmp/EXP_MOD_NAM $ make one_clean
Module/one/*.bak
/tmp/EXP_MOD_NAM $ make two_clean
Module/two/*.bak






    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....





reply via email to

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