Re: Call the AC_CHECK_HEADER macro on a condition

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

 



Hi,

On 2016-04-12, YuGiOhJCJ Mailing-List <yugiohjcj-mailinglist@xxxxxxxxxxx>
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

_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
https://lists.gnu.org/mailman/listinfo/autoconf



[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux