help-make
[Top][All Lists]
Advanced

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

Re: How does $@ work in a make conditional?


From: Björn Michaelsen
Subject: Re: How does $@ work in a make conditional?
Date: Fri, 14 Jan 2011 20:03:07 +0100

Hi Jeff,

Am Fri, 14 Jan 2011 11:38:29 -0600
schrieb JeffS <address@hidden>:

> 
> Hi!  I'm using GNU Make 3.80.  In my Makefile, I use automatic
> variable $@  to refer to the current target, as shown below.
> 
>         |     @echo current target is ... address@hidden
>         ifeq ($@,sms)
>              @echo yep, they are equal
>         else
>              @echo no, they are not equal
>         endif
>         |
> 
> It seems that $@  expands to sms , as shown in the output below.
> 
> Output is:
> 
>         |current target is ... [sms]
>         no, they are not equal
>         |
> 
> My question: since $@  (apparently) expands to sms 
at rule execution time
> , shouldn't the  "true" branch of the ifeq  conditional be executed
> (with the consequence that the output should read yep, they are
> equal)? 
No, as that get evaluated at rule parsing long before rule execution.
>[I am at a loss as to why the output is no, they are not equal.]
> 
> Thank you for any advice you can provide.

try this:

COMMA := ,
sms:
        @echo $(if $(filter sms,$@),\
                yep$(COMMA) they are equal,\
                no$(COMMA) they are not equal)

notsms:
        @echo $(if $(filter sms,$@),\
                yep$(COMMA) they are equal,\
                no$(COMMA) they are not equal)

BR,

Bjoern




reply via email to

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