summaryrefslogtreecommitdiffstats
path: root/gl/m4/include_next.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/include_next.m4')
-rw-r--r--gl/m4/include_next.m4103
1 files changed, 83 insertions, 20 deletions
diff --git a/gl/m4/include_next.m4 b/gl/m4/include_next.m4
index 7ce472bc..062753c5 100644
--- a/gl/m4/include_next.m4
+++ b/gl/m4/include_next.m4
@@ -1,19 +1,46 @@
1# include_next.m4 serial 4 1# include_next.m4 serial 10
2dnl Copyright (C) 2006, 2007 Free Software Foundation, Inc. 2dnl Copyright (C) 2006-2008 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
6 6
7dnl From Paul Eggert and Derek Price. 7dnl From Paul Eggert and Derek Price.
8 8
9dnl Sets INCLUDE_NEXT and PRAGMA_SYSTEM_HEADER.
10dnl
11dnl INCLUDE_NEXT expands to 'include_next' if the compiler supports it, or to
12dnl 'include' otherwise.
13dnl
14dnl INCLUDE_NEXT_AS_FIRST_DIRECTIVE expands to 'include_next' if the compiler
15dnl supports it in the special case that it is the first include directive in
16dnl the given file, or to 'include' otherwise.
17dnl
18dnl PRAGMA_SYSTEM_HEADER can be used in files that contain #include_next,
19dnl so as to avoid GCC warnings when the gcc option -pedantic is used.
20dnl '#pragma GCC system_header' has the same effect as if the file was found
21dnl through the include search path specified with '-isystem' options (as
22dnl opposed to the search path specified with '-I' options). Namely, gcc
23dnl does not warn about some things, and on some systems (Solaris and Interix)
24dnl __STDC__ evaluates to 0 instead of to 1. The latter is an undesired side
25dnl effect; we are therefore careful to use 'defined __STDC__' or '1' instead
26dnl of plain '__STDC__'.
27
9AC_DEFUN([gl_INCLUDE_NEXT], 28AC_DEFUN([gl_INCLUDE_NEXT],
10[ 29[
11 AC_LANG_PREPROC_REQUIRE() 30 AC_LANG_PREPROC_REQUIRE()
12 AC_CACHE_CHECK([whether the preprocessor supports include_next], 31 AC_CACHE_CHECK([whether the preprocessor supports include_next],
13 [gl_cv_have_include_next], 32 [gl_cv_have_include_next],
14 [rm -rf conftestd1 conftestd2 33 [rm -rf conftestd1a conftestd1b conftestd2
15 mkdir conftestd1 conftestd2 34 mkdir conftestd1a conftestd1b conftestd2
16 cat <<EOF > conftestd1/conftest.h 35 dnl The include of <stdio.h> is because IBM C 9.0 on AIX 6.1 supports
36 dnl include_next when used as first preprocessor directive in a file,
37 dnl but not when preceded by another include directive. Additionally,
38 dnl with this same compiler, include_next is a no-op when used in a
39 dnl header file that was included by specifying its absolute file name.
40 dnl Despite these two bugs, include_next is used in the compiler's
41 dnl <math.h>. By virtue of the second bug, we need to use include_next
42 dnl as well in this case.
43 cat <<EOF > conftestd1a/conftest.h
17#define DEFINED_IN_CONFTESTD1 44#define DEFINED_IN_CONFTESTD1
18#include_next <conftest.h> 45#include_next <conftest.h>
19#ifdef DEFINED_IN_CONFTESTD2 46#ifdef DEFINED_IN_CONFTESTD2
@@ -22,32 +49,53 @@ int foo;
22#error "include_next doesn't work" 49#error "include_next doesn't work"
23#endif 50#endif
24EOF 51EOF
52 cat <<EOF > conftestd1b/conftest.h
53#define DEFINED_IN_CONFTESTD1
54#include <stdio.h>
55#include_next <conftest.h>
56#ifdef DEFINED_IN_CONFTESTD2
57int foo;
58#else
59#error "include_next doesn't work"
60#endif
61EOF
25 cat <<EOF > conftestd2/conftest.h 62 cat <<EOF > conftestd2/conftest.h
26#ifndef DEFINED_IN_CONFTESTD1 63#ifndef DEFINED_IN_CONFTESTD1
27#error "include_next test doesn't work" 64#error "include_next test doesn't work"
28#endif 65#endif
29#define DEFINED_IN_CONFTESTD2 66#define DEFINED_IN_CONFTESTD2
30EOF 67EOF
31 save_CPPFLAGS="$CPPFLAGS" 68 gl_save_CPPFLAGS="$CPPFLAGS"
32 CPPFLAGS="$CPPFLAGS -Iconftestd1 -Iconftestd2" 69 CPPFLAGS="$gl_save_CPPFLAGS -Iconftestd1b -Iconftestd2"
33 AC_COMPILE_IFELSE([#include <conftest.h>], 70 AC_COMPILE_IFELSE([#include <conftest.h>],
34 [gl_cv_have_include_next=yes], 71 [gl_cv_have_include_next=yes],
35 [gl_cv_have_include_next=no]) 72 [CPPFLAGS="$gl_save_CPPFLAGS -Iconftestd1a -Iconftestd2"
36 CPPFLAGS="$save_CPPFLAGS" 73 AC_COMPILE_IFELSE([#include <conftest.h>],
37 rm -rf conftestd1 conftestd2 74 [gl_cv_have_include_next=buggy],
75 [gl_cv_have_include_next=no])
76 ])
77 CPPFLAGS="$gl_save_CPPFLAGS"
78 rm -rf conftestd1a conftestd1b conftestd2
38 ]) 79 ])
80 PRAGMA_SYSTEM_HEADER=
39 if test $gl_cv_have_include_next = yes; then 81 if test $gl_cv_have_include_next = yes; then
40
41 dnl FIXME: Remove HAVE_INCLUDE_NEXT and update everything that uses it
42 dnl to use @INCLUDE_NEXT@ instead.
43 AC_DEFINE([HAVE_INCLUDE_NEXT], 1,
44 [Define if your compiler supports the #include_next directive.])
45
46 INCLUDE_NEXT=include_next 82 INCLUDE_NEXT=include_next
83 INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include_next
84 if test -n "$GCC"; then
85 PRAGMA_SYSTEM_HEADER='#pragma GCC system_header'
86 fi
47 else 87 else
48 INCLUDE_NEXT=include 88 if test $gl_cv_have_include_next = buggy; then
89 INCLUDE_NEXT=include
90 INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include_next
91 else
92 INCLUDE_NEXT=include
93 INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include
94 fi
49 fi 95 fi
50 AC_SUBST([INCLUDE_NEXT]) 96 AC_SUBST([INCLUDE_NEXT])
97 AC_SUBST([INCLUDE_NEXT_AS_FIRST_DIRECTIVE])
98 AC_SUBST([PRAGMA_SYSTEM_HEADER])
51]) 99])
52 100
53# gl_CHECK_NEXT_HEADERS(HEADER1 HEADER2 ...) 101# gl_CHECK_NEXT_HEADERS(HEADER1 HEADER2 ...)
@@ -63,12 +111,16 @@ EOF
63# The three "///" are to pacify Sun C 5.8, which otherwise would say 111# The three "///" are to pacify Sun C 5.8, which otherwise would say
64# "warning: #include of /usr/include/... may be non-portable". 112# "warning: #include of /usr/include/... may be non-portable".
65# Use `""', not `<>', so that the /// cannot be confused with a C99 comment. 113# Use `""', not `<>', so that the /// cannot be confused with a C99 comment.
114# Note: This macro assumes that the header file is not empty after
115# preprocessing, i.e. it does not only define preprocessor macros but also
116# provides some type/enum definitions or function/variable declarations.
66AC_DEFUN([gl_CHECK_NEXT_HEADERS], 117AC_DEFUN([gl_CHECK_NEXT_HEADERS],
67[ 118[
68 AC_REQUIRE([gl_INCLUDE_NEXT]) 119 AC_REQUIRE([gl_INCLUDE_NEXT])
120 AC_REQUIRE([AC_CANONICAL_HOST])
69 AC_CHECK_HEADERS_ONCE([$1]) 121 AC_CHECK_HEADERS_ONCE([$1])
70 122
71 AC_FOREACH([gl_HEADER_NAME], [$1], 123 m4_foreach_w([gl_HEADER_NAME], [$1],
72 [AS_VAR_PUSHDEF([gl_next_header], 124 [AS_VAR_PUSHDEF([gl_next_header],
73 [gl_cv_next_]m4_quote(m4_defn([gl_HEADER_NAME]))) 125 [gl_cv_next_]m4_quote(m4_defn([gl_HEADER_NAME])))
74 if test $gl_cv_have_include_next = yes; then 126 if test $gl_cv_have_include_next = yes; then
@@ -84,11 +136,22 @@ AC_DEFUN([gl_CHECK_NEXT_HEADERS],
84 [AC_LANG_SOURCE( 136 [AC_LANG_SOURCE(
85 [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]] 137 [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]]
86 )]) 138 )])
87 dnl eval is necessary to expand ac_cpp. 139 dnl AIX "xlc -E" and "cc -E" omit #line directives for header files
140 dnl that contain only a #include of other header files and no
141 dnl non-comment tokens of their own. This leads to a failure to
142 dnl detect the absolute name of <dirent.h>, <signal.h>, <poll.h>
143 dnl and others. The workaround is to force preservation of comments
144 dnl through option -C. This ensures all necessary #line directives
145 dnl are present. GCC supports option -C as well.
146 case "$host_os" in
147 aix*) gl_absname_cpp="$ac_cpp -C" ;;
148 *) gl_absname_cpp="$ac_cpp" ;;
149 esac
150 dnl eval is necessary to expand gl_absname_cpp.
88 dnl Ultrix and Pyramid sh refuse to redirect output of eval, 151 dnl Ultrix and Pyramid sh refuse to redirect output of eval,
89 dnl so use subshell. 152 dnl so use subshell.
90 AS_VAR_SET([gl_next_header], 153 AS_VAR_SET([gl_next_header],
91 ['"'`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | 154 ['"'`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
92 sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{ 155 sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{
93 s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1# 156 s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#
94 s#^/[^/]#//&# 157 s#^/[^/]#//&#