[Top][All Lists]

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

Re: Call the AC_CHECK_HEADER macro on a condition

From: Nick Bowler
Subject: Re: Call the AC_CHECK_HEADER macro on a condition
Date: Tue, 12 Apr 2016 11:05:51 -0400


On 2016-04-12, YuGiOhJCJ Mailing-List <address@hidden>
[snip exposition]
> So, I would like to call the AC_CHECK_HEADER macro on a condition:
> AC_INIT([my-project], [20160412])
> 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])

The basic problem with the above is that AC_PROG_CPP is not
called properly in your  Because (simplifying
a bit) AC_CHECK_HEADER requires a the preprocessor, it expands


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])

Normally I would go with AS_IF.

Hope that helps,

reply via email to

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