Re: AM_CONDITIONAL fails with line break at the end of $2

Eric Blake <[email protected]>
Newsgroups gmane.comp.sysutils.autoconf.patches,gmane.comp.sysutils.automake.patches
Organization Red Hat, Inc.
Message-ID <[email protected]>
[adding automake]

On 07/17/2014 10:00 AM, Dimitrios Apostolou wrote:
> Hello list,
> 
> the following snippet generates invalid shell code (and a cryptic error
> message) because of the line break right before the closing parenthesis.
> 
> AM_CONDITIONAL([HAVE_LIBXML2],
>     [test "x$with_libxml2" != xno &&
>      test "x$ac_cv_lib_xml2_xmlFirstElementChild" = xyes]
> )
> 

AM_CONDITIONAL is not an autoconf macro, and your patch is to an
automake file, so you mailed the wrong list.  But that's okay, I've
redirected it.

> 
> Generated code (semi-colon at beginning of line creates problems):
> 
>  if test "x$with_libxml2" != xno &&
>      test "x$ac_cv_lib_xml2_xmlFirstElementChild" = xyes
> ; then
>   HAVE_LIBXML2_TRUE=
>   HAVE_LIBXML2_FALSE='#'
> else
>   HAVE_LIBXML2_TRUE='#'
>   HAVE_LIBXML2_FALSE=
> fi
> 
> 
> The attached patch attempts to fix the issue, do you think it is the
> right approach?

I don't know if automake should work around your bad syntax, or if you
should just fix your configure.ac to use correct syntax to begin with. I
also wonder if automake could use AS_IF instead of open-coding the if to
try and take advantage of autoconf's smarts for trying to sanitize
conditions.

However, even autoconf's AS_IF current implementation prefers the 'if
cond; then' rather than 'if cond $newline then', so it is likewise not
robust to conditions ending in a spurious newline.  If changing AS_IF to
use newline separator does not increase configure size, I could see
making that change in autoconf.  I'll play with the idea.


> --- cond.m4	2014-07-17 17:46:37.741723897 +0200
> +++ cond.2.m4	2014-07-17 17:50:43.456076469 +0200
> @@ -13,17 +13,18 @@
>  [AC_PREREQ([2.52])dnl
>   m4_if([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
>         [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
>  AC_SUBST([$1_TRUE])dnl
>  AC_SUBST([$1_FALSE])dnl
>  _AM_SUBST_NOTMAKE([$1_TRUE])dnl
>  _AM_SUBST_NOTMAKE([$1_FALSE])dnl
>  m4_define([_AM_COND_VALUE_$1], [$2])dnl
> -if $2; then
> +if $2
> +then
>    $1_TRUE=
>    $1_FALSE='#'
>  else
>    $1_TRUE='#'
>    $1_FALSE=
>  fi
>  AC_CONFIG_COMMANDS_PRE(
>  [if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc (application/pgp-signature, 604 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCAAGBQJTx/inAAoJEKeha0olJ0NqP90H/20aq0ljwx2CeCELgh/kK5US
1acWLu949M7WDcK/T3QEMAF5NVVhGe04DYGfB2PQjC5QVHQfEGIQ5OshmXfiibO1
18121rva8VT8VLcV3rgSdfLOhCv18BiNvY6fPUv3q00Z0N3lu6h6r5I1Zc587W3H
8JmY3zRwthq+txQolyjJOCT0yqB1VdPMKE1xcCvMvdtzWjRsYs3QHgQP3rAWENfs
JsVb2RW0Qs83xXThHFZ5kHrnlldCpJgMyFvCUU+Ssfyu9lnPsl8pNz/jwhNMGmlD
Ztoa6nFOXP0Gai4tmdP9hZoaJuMv2Gb5SCNFp2vURentgNOWn4dSaRpyxsYcA/U=
=fsGS
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.