Eric Blake wrote:
This is a known 'feature' of autoconf. In general, invoking macros with side-
effects inside of raw 'if' blocks is dangerous; there are two common failure
scenarios - side effects happen regardless of whether the shell code containing
the macro name is executed (because autoconf generates the side-effect code
into a different m4 diversion), or, as in your case, side effects only happen
on the first use of the macro (because autoconf AC_REQUIRE's the side-effect to
avoid redundant output of one-shot initialization). You can try using AS_IF
instead of raw shell 'if' for wrapping the AC_PROG_CC calls, since the purpose
of AS_IF is to output a shell conditional AND correctly handle side effects of
macros within that shell conditional. But in your case, the easiest thing to
do is fix your autoconf.ac:
AC_INIT
AC_ARG_ENABLE(foo)
AC_PROG_CC([gcc])
if test "$enable_foo"; then
echo "enabled"
else
echo "disabled"
fi
Thanks! Unfortunately, however, that "fixes" it by breaking the desired
functionality. The point of enable_foo is not the echo statements, but
the fact that AC_PROG_CC uses the "[gcc]" list when foo is enabled, and
uses the default program list when foo is disabled.
Is there some way to define a variable argument to AC_PROG_CC to get
this functionality? I'd like to do something like the following, if I
could:
AC_INIT
AC_ARG_ENABLE(foo)
if test "$enable_foo"; then
echo "enabled"
cc_list=[gcc]
else
echo "disabled"
cc_list=
fi
AC_PROG_CC($cc_list)
However, this doesn't actually work; with foo disabled, AC_PROG_CC just
looks in the empty list for acceptable C compilers, and of course
doesn't find anything.
If it's not possible to do something like this, I'll have a look at AS_IF.
- Brooks
_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf