autoconf
[Top][All Lists]
Advanced

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

Re: Call the AC_CHECK_HEADER macro on a condition


From: YuGiOhJCJ Mailing-List
Subject: Re: Call the AC_CHECK_HEADER macro on a condition
Date: Wed, 13 Apr 2016 02:22:29 +0200

On Tue, 12 Apr 2016 11:05:51 -0400
Nick Bowler <address@hidden> wrote:

> Hi,
> 
> On 2016-04-12, YuGiOhJCJ Mailing-List <address@hidden>
> wrote:
> [snip exposition]
> > So, I would like to call the AC_CHECK_HEADER macro on a condition:
> > AC_INIT([my-project], [20160412])
> > AM_INIT_AUTOMAKE
> > AM_PROG_CC_C_O
> > if test "x$host" == xavr; then
> >     AC_CHECK_HEADER([avr/io.h], [], [AC_MSG_ERROR([missing header:
> > avr/io.h])])
> >     AC_CHECK_HEADER([util/delay.h], [], [AC_MSG_ERROR([missing header:
> > util/delay.h])])
> >     else
> >             AC_CHECK_HEADER([stdio.h], [],
> >                               [AC_MSG_ERROR([missing header: stdio.h])])
> >             AC_CHECK_HEADER([time.h], [],
> >                               [AC_MSG_ERROR([missing header: time.h])])
> > fi
> > AC_CONFIG_FILES([Makefile])
> > AC_OUTPUT
> 
> The basic problem with the above is that AC_PROG_CPP is not
> called properly in your configure.ac.  Because (simplifying
> a bit) AC_CHECK_HEADER requires a the preprocessor, it expands
> 
>   AC_REQUIRE([AC_PROG_CPP]).
> 
> Loosely, this means that the first expansion of AC_CHECK_HEADER
> will expand AC_PROG_CPP, if it was not already done.  In your
> original version, these expansions were unconditional and things
> worked fine.
> 
> But in your second instance, the first expansion of AC_CHECK_HEADER
> expands AC_PROG_CPP inside an "if".  The result is that no preprocessor
> is checked in the "else" case.  You can see this in the configure output,
> the following line is only printed in the avr case:
> 
>   checking how to run the C preprocessor... avr-gcc -E
> 
> There are several basic solutions:
> 
> - First, you can just expand AC_PROG_CPP directly and unconditionally
>   before your if.  This will ensure the macro is available in both cases.
> 
> - Second is to rewrite your condition using AS_IF, which automatically
>   "hoists" the dependency AC_PROG_CPP (and any other dependencies)
>   outside of the if condition.  For example:
> 
>   AS_IF([test x"$host" = x"avr"],
>     [AC_CHECK_HEADER([avr/io.h], [],
>                      [AC_MSG_ERROR([missing header: avr/io.h])])
>      AC_CHECK_HEADER([util/delay.h], [],
>                      [AC_MSG_ERROR([missing header: util/delay.h])])],
> 
>     [AC_CHECK_HEADER([stdio.h], [],
>                      [AC_MSG_ERROR([missing header: stdio.h])])
>      AC_CHECK_HEADER([time.h], [],
>                      [AC_MSG_ERROR([missing header: time.h])])])
> 
> - Third, you can make the checks unconditional but the hard
>   failures conditional, e.g.:
> 
>   AC_CHECK_HEADER([avr/io.h], [],
>     [if test x"$host" = x"avr"; then
>        AC_MSG_ERROR([missing header: avr/io.h])
>      fi])
> 
> Normally I would go with AS_IF.
> 
> Hope that helps,
>   Nick

It is a very useful answer with explanations.
I am using AS_IF now and it works perfectly.
Thank you.



reply via email to

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