Discussion:
Checking default headers
Ross Lagerwall
2013-09-02 14:03:51 UTC
Permalink
Hi,

I have a question about checking headers.

Suppose I have a simple program which includes unistd.h and nothing
else. I could AC_CHECK_HEADERS([unistd.h]) but then it checks for the
header twice because using AC_CHECK_HEADERS implies checking a whole
bunch of headers:
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/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 for unistd.h... (cached) yes

Is there a way of checking for the AC_INCLUDES_DEFAULT headers without
checking for anything else?
Calling _AC_INCLUDES_DEFAULT_REQUIREMENTS does this but it doesn't seem
to be a public macro.

Secondly, AC_TYPE_UINT32_T gives different results depending on whether
any headers have been checked before (eg. if I first check for dlfcn.h,
stdint.h is automatically checked for, but otherwise it is not).
This seems nonintuitive; is it supposed to be like this?

Lastly, AC_HEADER_STDC is declared obsolete yet it is required by
_AC_INCLUDES_DEFAULT_REQUIREMENTS. Why is this?

Thanks
--
Ross Lagerwall
Eric Blake
2013-09-03 14:52:54 UTC
Permalink
Post by Ross Lagerwall
Hi,
I have a question about checking headers.
Suppose I have a simple program which includes unistd.h and nothing
else. I could AC_CHECK_HEADERS([unistd.h]) but then it checks for the
header twice because using AC_CHECK_HEADERS implies checking a whole
Is there a way of checking for the AC_INCLUDES_DEFAULT headers without
checking for anything else?
Not particularly, but there IS a way to avoid AC_INCLUDES_DEFAULT in the
first place:

AC_CHECK_HEADERS([unistd.h], , , [ ])

to force a non-empty fourth argument to bypass the default use of
AC_INCLUDES_DEFAULT.
Post by Ross Lagerwall
Secondly, AC_TYPE_UINT32_T gives different results depending on whether
any headers have been checked before (eg. if I first check for dlfcn.h,
stdint.h is automatically checked for, but otherwise it is not).
This seems nonintuitive; is it supposed to be like this?
Probably means that AC_TYPE_UINT32_T is missing a prereq on the standard
headers; would you mind posting a reproducible test case, and we can
work on fixing the bug?
Post by Ross Lagerwall
Lastly, AC_HEADER_STDC is declared obsolete yet it is required by
_AC_INCLUDES_DEFAULT_REQUIREMENTS. Why is this?
Commit f52459d has already tried to address that, and is just awaiting
the release of autoconf 2.70. Is there anything further we need to fix?

git.sv.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=f52459d
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Ross Lagerwall
2013-09-03 17:42:39 UTC
Permalink
Post by Eric Blake
Post by Ross Lagerwall
Hi,
I have a question about checking headers.
Suppose I have a simple program which includes unistd.h and nothing
else. I could AC_CHECK_HEADERS([unistd.h]) but then it checks for the
header twice because using AC_CHECK_HEADERS implies checking a whole
Is there a way of checking for the AC_INCLUDES_DEFAULT headers without
checking for anything else?
Not particularly, but there IS a way to avoid AC_INCLUDES_DEFAULT in the
AC_CHECK_HEADERS([unistd.h], , , [ ])
to force a non-empty fourth argument to bypass the default use of
AC_INCLUDES_DEFAULT.
OK, thanks.
Post by Eric Blake
Post by Ross Lagerwall
Secondly, AC_TYPE_UINT32_T gives different results depending on whether
any headers have been checked before (eg. if I first check for dlfcn.h,
stdint.h is automatically checked for, but otherwise it is not).
This seems nonintuitive; is it supposed to be like this?
Probably means that AC_TYPE_UINT32_T is missing a prereq on the standard
headers; would you mind posting a reproducible test case, and we can
work on fixing the bug?
The following reproduces it:
"""
AC_INIT([test], [dev])
AC_PROG_CC

if false; then
AC_CHECK_HEADERS([pthread.h], [], [have_pthreads=no])
fi

AC_TYPE_UINT16_T
AC_OUTPUT
"""

There seems to be some interaction with AC_CHECK_HEADERS being performed
conditionally.
Post by Eric Blake
Post by Ross Lagerwall
Lastly, AC_HEADER_STDC is declared obsolete yet it is required by
_AC_INCLUDES_DEFAULT_REQUIREMENTS. Why is this?
Commit f52459d has already tried to address that, and is just awaiting
the release of autoconf 2.70. Is there anything further we need to fix?
git.sv.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=f52459d
Well the following removes the "checking for ANSI C header files... yes"
line which seems to appear when AC_HEADER_STDC is called.

Regards
Ross Lagerwall

8<------------------------------
From 5ef0afde59e1c3561df4462cfaa974706ffb8b76 Mon Sep 17 00:00:00 2001
From: Ross Lagerwall <***@gmail.com>
Date: Tue, 3 Sep 2013 19:40:09 +0200
Subject: [PATCH] Remove call to the obsolete AC_HEADER_STDC

---
lib/autoconf/headers.m4 | 1 -
1 file changed, 1 deletion(-)

diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4
index 7f5dbce..cc7e1c8 100644
--- a/lib/autoconf/headers.m4
+++ b/lib/autoconf/headers.m4
@@ -329,7 +329,6 @@ ac_includes_default="\
# include <unistd.h>
#endif"
])dnl
-AC_REQUIRE([AC_HEADER_STDC])dnl
# On IRIX 5.3, sys/types and inttypes.h are conflicting.
AC_CHECK_HEADERS([sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
inttypes.h stdint.h unistd.h],
--
1.8.4
Zack Weinberg
2013-09-07 02:30:23 UTC
Permalink
Post by Ross Lagerwall
diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4
index 7f5dbce..cc7e1c8 100644
--- a/lib/autoconf/headers.m4
+++ b/lib/autoconf/headers.m4
@@ -329,7 +329,6 @@ ac_includes_default="\
# include <unistd.h>
#endif"
])dnl
-AC_REQUIRE([AC_HEADER_STDC])dnl
# On IRIX 5.3, sys/types and inttypes.h are conflicting.
AC_CHECK_HEADERS([sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
inttypes.h stdint.h unistd.h],
This isn't quite enough for backward compatibility's sake. You've
reminded me that I had a half-completed patch series that addresses
this issue -- I've dusted them off and finished them now. Coming to
autoconf-patches shortly.

zw
Ross Lagerwall
2013-09-07 06:16:12 UTC
Permalink
Post by Zack Weinberg
Post by Ross Lagerwall
diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4
index 7f5dbce..cc7e1c8 100644
--- a/lib/autoconf/headers.m4
+++ b/lib/autoconf/headers.m4
@@ -329,7 +329,6 @@ ac_includes_default="\
# include <unistd.h>
#endif"
])dnl
-AC_REQUIRE([AC_HEADER_STDC])dnl
# On IRIX 5.3, sys/types and inttypes.h are conflicting.
AC_CHECK_HEADERS([sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
inttypes.h stdint.h unistd.h],
This isn't quite enough for backward compatibility's sake. You've
reminded me that I had a half-completed patch series that addresses
this issue -- I've dusted them off and finished them now. Coming to
autoconf-patches shortly.
OK, that makes sense.

Thanks
--
Ross Lagerwall
Zack Weinberg
2013-09-07 02:42:00 UTC
Permalink
Post by Ross Lagerwall
Post by Eric Blake
Probably means that AC_TYPE_UINT32_T is missing a prereq on the standard
headers; would you mind posting a reproducible test case, and we can
work on fixing the bug?
"""
AC_INIT([test], [dev])
AC_PROG_CC
if false; then
AC_CHECK_HEADERS([pthread.h], [], [have_pthreads=no])
fi
AC_TYPE_UINT16_T
AC_OUTPUT
"""
It looks like AC_TYPE_INT<n>_T are correct. The problem is that if
the very first AC_CHECK_HEADER[S] in the file is inside a shell
conditional, _AC_INCLUDES_DEFAULT_REQUIREMENTS gets expanded inside
the conditional, and so only executes if the shell conditional is
true. This is (one of) the problems AS_IF addresses:

AC_INIT([test], [dev])
AC_PROG_CC
AS_IF([false], [AC_CHECK_HEADERS([pthread.h])])
AC_TYPE_UINT16_T
AC_OUTPUT

does the right thing (because the conditional is now visible on the M4
expansion stack, so _AC_INCLUDES_DEFAULT_REQUIREMENTS gets placed just
before it instead of inside it).

I don't think there's anything we can reasonably do in Autoconf to
make this less troublesome.

zw
Ross Lagerwall
2013-09-07 06:20:56 UTC
Permalink
Post by Zack Weinberg
Post by Ross Lagerwall
Post by Eric Blake
Probably means that AC_TYPE_UINT32_T is missing a prereq on the standard
headers; would you mind posting a reproducible test case, and we can
work on fixing the bug?
"""
AC_INIT([test], [dev])
AC_PROG_CC
if false; then
AC_CHECK_HEADERS([pthread.h], [], [have_pthreads=no])
fi
AC_TYPE_UINT16_T
AC_OUTPUT
"""
It looks like AC_TYPE_INT<n>_T are correct. The problem is that if
the very first AC_CHECK_HEADER[S] in the file is inside a shell
conditional, _AC_INCLUDES_DEFAULT_REQUIREMENTS gets expanded inside
the conditional, and so only executes if the shell conditional is
AC_INIT([test], [dev])
AC_PROG_CC
AS_IF([false], [AC_CHECK_HEADERS([pthread.h])])
AC_TYPE_UINT16_T
AC_OUTPUT
does the right thing (because the conditional is now visible on the M4
expansion stack, so _AC_INCLUDES_DEFAULT_REQUIREMENTS gets placed just
before it instead of inside it).
I don't think there's anything we can reasonably do in Autoconf to
make this less troublesome.
Thanks for the explanation. Noting down AS_IF for the future...
--
Ross Lagerwall
Loading...