[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: another target variable question
From: |
cbrown |
Subject: |
Re: another target variable question |
Date: |
Sat, 04 Aug 2007 22:45:12 -0400 |
excellent. thank you.
On Fri, 2007-08-03 at 16:14 -0600, Philip Guenther wrote:
> On 8/3/07, cbrown <address@hidden> wrote:
> ...
> > $(PROJECTS):
> > ifeq ($(MAKECMDGOALS),clean)
> > @echo "($@,$(CURR))"
> > ifeq ($@,$(CURR))
> > @echo gonna clean $@
> > else
> > @echo NOT gonna clean $@
> > endif
> > else
> > @echo gonna $(MAKECMDGOALS) $@
> > endif
> >
> > When I execute "make CURR=a clean", I get;
> >
> > (b,a)
> > NOT gonna clean b
> > (a,a)
> > NOT gonna clean a
> >
> > How come the "ifeq ($@,$(CURR))" doesn't work?
>
> Because make's conditionals are evaluated during the parse of the
> makefile, while target-specific variables like $@ are only set during
> the evaluation of the target's rules.
>
>
> > Is there an easier path to my goal?
>
> Yes: use a shell conditional for the test of $@:
>
> $(PROJECTS):
> ifeq ($(MAKECMDGOALS),clean)
> @echo "($@,$(CURR))"
> @if [ x"$@" = x"$(CURR)" ]; then \
> echo gonna clean $@; \
> else \
> echo NOT gonna clean $@; \
> fi
> else
> @echo gonna $(MAKECMDGOALS) $@
> endif
>
>
> Note the placement of semicolons and backslashes and that the leading
> '@' is only on the first line of the multi-line command.
>
>
> Philip Guenther