Subject: Re: bug#8718: error when using nested conditionals

From: "Ralf Wildenhues" <[email-masked]>
Date: Fri, 17 Jun 2011 08:59:30 +0200

* Ralf Wildenhues wrote on Fri, Jun 17, 2011 at 07:47:35AM CEST:
> * Bruno Haible wrote on Thu, Jun 16, 2011 at 11:42:51PM CEST:
> > > >   AM_CONDITIONAL([USE_VARIANT_A], [$use_variant_a])
> > > 
> > > Instead of this line, you could use
> > >   AC_CONFIG_COMMANDS_PRE([AM_CONDITIONAL([...])])
> > 
> > I cannot force the gnulib users to write autoconf macros which deviate that
> > much from the idioms promoted by the Automake manual. But I can override
> > AM_CONDITIONAL like this:
> 
> Or you could write a gl_AM_CONDITIONAL macro (or similarly) to use
> instead.
> 
> > m4_define([gl_CONDITIONAL_COUNTER], [0])
> > AC_DEFUN([gl_CONDITIONAL_LATER],
> > [
> >   m4_define([gl_CONDITIONAL_COUNTER], m4_incr(gl_CONDITIONAL_COUNTER))
> >   m4_divert_text([INIT_PREPARE], [[gl_CONDITIONAL_]gl_CONDITIONAL_COUNTER=false])
> >   if [$2]; then [gl_CONDITIONAL_]gl_CONDITIONAL_COUNTER=true; else [gl_CONDITIONAL_]gl_CONDITIONAL_COUNTER=false; fi
> >   AC_CONFIG_COMMANDS_PRE([AM_CONDITIONAL([$1], [[$gl_CONDITIONAL_]]]gl_CONDITIONAL_COUNTER[)])
> > ])
> > m4_pushdef([AM_CONDITIONAL], m4_defn([gl_CONDITIONAL_LATER]))
> 
> > This solves my problem. Thanks for the idea to use AC_CONFIG_COMMANDS_PRE.
> > I will add this workaround to gnulib.
> 
> Please note that this does have a small change in semantics, namely if
> there is code using AM_COND_IF: that is only valid after the
> AM_CONDITIONAL has been expanded.  Now, current gnulib does not use this
> (fairly new) macro, but there may be user code which does (or will) use
> it.  You could poison it in the above code, if you really want to keep
> overriding AM_CONDITIONAL itself.

More danger ahead:

if $foo; then result=ok; else result=bad; fi
AM_CONDITIONAL([COND1], [test $result = ok])
if $bar; then result=ok; else result=bad; fi
AM_CONDITIONAL([COND2], [test $result = ok])

I've seen such code in third party projects, it will break if you delay
the AM_CONDITIONAL evaluation.  Haven't checked whether gnulib uses
globally valid tests throughout.

Cheers,
Ralf