AS_VAR_IF and the resulting shell code

View: New views
3 Messages — Rating Filter:   Alert me  

AS_VAR_IF and the resulting shell code

by NightStrike :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This:

xx=yes
AS_VAR_IF([xx],[yes],[echo equal],[echo not equal])
results in this:

xx=yes
if test "x$xx" = x""yes; then
  echo equal
else
  echo not equal
fi
with autoconf 2.63.

How come the right hand side of the test is x""yes, as in, with two
double quotes between the x and the yes?  Why isn't it just "xyes", or
just xyesy?


_______________________________________________
Autoconf mailing list
Autoconf@...
http://lists.gnu.org/mailman/listinfo/autoconf

Re: AS_VAR_IF and the resulting shell code

by Ralf Wildenhues :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

* NightStrike wrote on Fri, Oct 16, 2009 at 06:45:57PM CEST:

> xx=yes
> AS_VAR_IF([xx],[yes],[echo equal],[echo not equal])
> results in this:
>
> xx=yes
> if test "x$xx" = x""yes; then
>   echo equal
> else
>   echo not equal
> fi
> with autoconf 2.63.
>
> How come the right hand side of the test is x""yes, as in, with two
> double quotes between the x and the yes?  Why isn't it just "xyes", or
> just xyesy?

It's not "xyes", because I think the quoting of the second argument to
AS_VAR_IF was to be the user's responsibility.  (FYI, if you pass a
nonliteral as first argument, then autoconf will expand different code.
xyesy would have been a problem if you pass $foo as second argument.

The two double quotes look a bit ugly in the output, but are not really
problematic.  They are not really needed for the shell, if I remember
correctly, but so that M4 splitting/macro expansion works as expected.

Hope that helps.  Is there an actual bug you've encountered with this
code?

Thanks,
Ralf


_______________________________________________
Autoconf mailing list
Autoconf@...
http://lists.gnu.org/mailman/listinfo/autoconf

Re: AS_VAR_IF and the resulting shell code

by NightStrike :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Oct 16, 2009 at 1:28 PM, Ralf Wildenhues <Ralf.Wildenhues@...> wrote:

> Hello,
>
> * NightStrike wrote on Fri, Oct 16, 2009 at 06:45:57PM CEST:
>> xx=yes
>> AS_VAR_IF([xx],[yes],[echo equal],[echo not equal])
>> results in this:
>>
>> xx=yes
>> if test "x$xx" = x""yes; then
>>   echo equal
>> else
>>   echo not equal
>> fi
>> with autoconf 2.63.
>>
>> How come the right hand side of the test is x""yes, as in, with two
>> double quotes between the x and the yes?  Why isn't it just "xyes", or
>> just xyesy?
>
> It's not "xyes", because I think the quoting of the second argument to
> AS_VAR_IF was to be the user's responsibility.  (FYI, if you pass a
> nonliteral as first argument, then autoconf will expand different code.
> xyesy would have been a problem if you pass $foo as second argument.
>
> The two double quotes look a bit ugly in the output, but are not really
> problematic.  They are not really needed for the shell, if I remember
> correctly, but so that M4 splitting/macro expansion works as expected.
>
> Hope that helps.  Is there an actual bug you've encountered with this
> code?

No bug in particular.  I just want to get rid of my hand-written tests
like this:

AS_IF([test "$enable_lib32" = no && test "$enable_lib64" = no],
        [],
      [test "$enable_libce" = yes],
        [AC_MSG_WARN([Building the runtime to use libce with lib32 or
lib64 is unsupported.])])


And make them less prone to my lack of knowledge of shell gotchas.

Ideally, I can use macros for everything.  That way, I don't have to
worry about getting tied up with "test x$ddd" stuff and quoting that I
don't understand.


_______________________________________________
Autoconf mailing list
Autoconf@...
http://lists.gnu.org/mailman/listinfo/autoconf