autoconf
[Top][All Lists]
Advanced

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

Re: Empty else part in AS_IF


From: Eric Blake
Subject: Re: Empty else part in AS_IF
Date: Wed, 09 Oct 2013 13:31:59 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130923 Thunderbird/17.0.9

On 10/09/2013 01:18 PM, Julien ÉLIE wrote:
> Hi,
> 
> The following piece of code:
> 
>  AS_IF([test x"$var" != xfalse],
>      [$test=1],
>      [m4_ifdef([AM_CONDITIONAL],
>          [AM_CONDITIONAL([TEST], [false])])])
> 
> gives the following configure code with autoconf 2.69:
> 
>  if test x"$var" != xfalse; then :
>   $test=1

That's unusual shell syntax (it does NOT do a variable assignment; did
you mean 'test=1' instead of trying to execute the program whose name is
the expansion of $test concatenated with '=1'?)

> else
> 
> fi
> 
> which is not a valid syntax.

Indeed.  The problem is that autoconf cannot tell if a non-empty literal
will expand to empty text (m4_ifdef results in no output).  You'll have
to workaround it yourself:

AS_IF([test x"$var" != xfalse],
    [$test=1],
    [: m4_ifdef(...)])


> 
> Is it the expected behaviour of AS_IF when the else part is empty?

Yes, it's expected that autoconf can't predict which macros expand to
nothing.  It's a dark corner case, where it costs far more m4 time to
try and work around it (and probably get things wrong in the process)
than it does to just say "don't do that".


> A possible workaround I found out to work is to add a no-op [:] else
> part to m4_ifdef:

Yep.


> 
> Is it the right thing to do?  What would you otherwise suggest?
> Is there something I am missing?

Nope, your analysis was spot on for what you need to do.


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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