Call the AC_CHECK_HEADER macro on a condition

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

 



Hello,

This is my configure.ac file:
AC_INIT([my-project], [20160412])
AM_INIT_AUTOMAKE
AM_PROG_CC_C_O
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])])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

The two first header checks must be called only when host is "avr" whereas the two last checks must be called in other cases.

Currently, if I call my configure script with host set to "avr" that's what happens:
$ ./configure --host=avr
checking for a BSD-compatible install... /bin/ginstall -c
checking whether build environment is sane... yes
checking for avr-strip... avr-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking for avr-gcc... avr-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether avr-gcc accepts -g... yes
checking for avr-gcc option to accept ISO C89... none needed
checking dependency style of avr-gcc... gcc3
checking whether avr-gcc and cc understand -c and -o together... yes
checking how to run the C preprocessor... avr-gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... no
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... no
checking for strings.h... no
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking avr/io.h usability... yes
checking avr/io.h presence... yes
checking for avr/io.h... yes
checking util/delay.h usability... yes
checking util/delay.h presence... yes
checking for util/delay.h... yes
checking stdio.h usability... yes
checking stdio.h presence... yes
checking for stdio.h... yes
checking time.h usability... yes
checking time.h presence... yes
checking for time.h... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands

As you can see the :
AC_CHECK_HEADER([stdio.h], [], [AC_MSG_ERROR([missing header: stdio.h])])
AC_CHECK_HEADER([time.h], [], [AC_MSG_ERROR([missing header: time.h])])
calls are done whereas it is useless for my project when host is "avr".

And you can guess what happens when I call my configure script with host not set:
$ ./configure
checking for a BSD-compatible install... /bin/ginstall -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking whether gcc and cc understand -c and -o together... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking avr/io.h usability... no
checking avr/io.h presence... no
checking for avr/io.h... no
configure: error: missing header: avr/io.h

Here, the:
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])])
calls are done whereas when host is my linux machine, these checks should not be done.

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

With this new configure.ac file, if I call my configure script with host set to "avr" that's what happens:
$ ./configure --host=avr
checking for a BSD-compatible install... /bin/ginstall -c
checking whether build environment is sane... yes
checking for avr-strip... avr-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking for avr-gcc... avr-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether avr-gcc accepts -g... yes
checking for avr-gcc option to accept ISO C89... none needed
checking dependency style of avr-gcc... gcc3
checking whether avr-gcc and cc understand -c and -o together... yes
checking how to run the C preprocessor... avr-gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... no
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... no
checking for strings.h... no
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking avr/io.h usability... yes
checking avr/io.h presence... yes
checking for avr/io.h... yes
checking util/delay.h usability... yes
checking util/delay.h presence... yes
checking for util/delay.h... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands

It seems to do the job.
The:
AC_CHECK_HEADER([stdio.h], [], [AC_MSG_ERROR([missing header: stdio.h])])
AC_CHECK_HEADER([time.h], [], [AC_MSG_ERROR([missing header: time.h])])
calls are not anymore done.

And that's what happens when I call my configure script with host not set:
$ ./configure
checking for a BSD-compatible install... /bin/ginstall -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking whether gcc and cc understand -c and -o together... yes
checking stdio.h usability... yes
checking stdio.h presence... no
configure: WARNING: stdio.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: stdio.h: proceeding with the compiler's result
checking for stdio.h... yes
checking time.h usability... yes
checking time.h presence... no
configure: WARNING: time.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: time.h: proceeding with the compiler's result
checking for time.h... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands

As you can see, the good thing is that the:
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])])
calls are not anymore done.
However, the bad thing is that I got some warnings:
[...]
configure: WARNING: stdio.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: stdio.h: proceeding with the compiler's result
[...]
configure: WARNING: time.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: time.h: proceeding with the compiler's result
[...]

So, I guess my configure.ac file is wrong.

How to do the things correctly please to call the AC_CHECK_HEADER macro on a condition?

Thank you.
Best regards.

_______________________________________________
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