help-make
[Top][All Lists]
Advanced

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

Re: another target variable question


From: Philip Guenther
Subject: Re: another target variable question
Date: Fri, 3 Aug 2007 16:14:19 -0600

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




reply via email to

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