autoconf
[Top][All Lists]
Advanced

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

Re: if (...) then; AC_PROG_CC else AC_PROG_CC fi doesn't work?


From: Eric Blake
Subject: Re: if (...) then; AC_PROG_CC else AC_PROG_CC fi doesn't work?
Date: Tue, 23 Oct 2007 22:13:44 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Brooks Moses <brooks <at> codesourcery.com> writes:

> AC_INIT
> AC_ARG_ENABLE(foo)
> 
> if test "$enable_foo"; then
>    echo "enabled"
>    AC_PROG_CC([gcc])
> else
>    echo "disabled"
>    AC_PROG_CC
> fi
> =================================
> 
> This does not work correctly;

> This is happening both with autoconf 2.59 and 2.61.  I haven't checked 
> other versions.
> 
> Is this a known bug?  Is there a suggested workaround?

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

-- 
Eric Blake






reply via email to

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