[Top][All Lists]
[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: |
Tue, 21 Aug 2007 01:30:53 -0400 |
On Mon, 2007-08-20 at 22:12 -0700, micron_make wrote:
> $(loc_mod)_CLCMD := Module/$(loc_mod)/*.bak
>
> $(loc_mod)_clean:
> @echo $($(@:_clean=)_CLCMD)
> This worked for me. It was difficult to find any specific documentation for
> this kind (($(@: )of usage of automatic variables in the GNU Make pdf. Could
> you please point me to some documentation stressing on usage with some
> examples.
Look at the section on "Substitution References", in "Advanced Features
for Reference to Variables", in the "How to Use Variables" chapter.
This is just shorthand for:
$(loc_mod)_clean:
@echo $($(@:%_clean=%)_CLCMD)
which itself is just syntactic sugar for:
$(loc_mod)_clean:
@echo $($(patsubst %_clean,%,$@)_CLCMD)
> I couldn't get eval method working
> > To get it expanded earlier, you need an eval:
> >
> > define clean_rule
> > $(loc_mod)_clean:
> > @echo $$($(loc_mod)_CLCMD)
> > endef
> >
> > $(eval $(call clean_rule))
It's useless to use $(call ...) here, because you're not passing any
arguments. There's no difference between $(call clean_rule) and just
using $(clean_rule) directly.
Call is only useful for parametrized functions.
> I get "prerequisites cannot be defined in command scripts. Stop"
>
> The way I am using eval is
> define clean_rule
> $(loc_mod)_clean:
> @echo $$($(loc_mod)_CLCMD)
> endef
>
> $(loc_mod)_clean:
> $(eval $(call clean_rule))
> Am I doing something wrong here? Just curious to know since I want to
> explore the eval function in detail.
Yes, you're doing something wrong: that's nothing like what was
recommended to you (as quoted above).
You can't put the eval INSIDE the command script, because you can't
create new rules inside a command script. What you're writing is
basically this (which is completely illegal in make):
$(loc_mod)_clean:
$(loc_mod)_clean:
@echo $(foo_CLCMD)
In other words, a rule where the target is only evaluated when the
target is run; this doesn't even make sense.
--
-------------------------------------------------------------------------------
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