3 dnl Copyright (C) 2006-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 dnl From Paul Eggert and Derek Price.
10 dnl Sets INCLUDE_NEXT, INCLUDE_NEXT_AS_FIRST_DIRECTIVE, PRAGMA_SYSTEM_HEADER,
11 dnl and PRAGMA_COLUMNS.
13 dnl INCLUDE_NEXT expands to 'include_next' if the compiler supports it, or to
14 dnl 'include' otherwise.
16 dnl INCLUDE_NEXT_AS_FIRST_DIRECTIVE expands to 'include_next' if the compiler
17 dnl supports it in the special case that it is the first include directive in
18 dnl the given file, or to 'include' otherwise.
20 dnl PRAGMA_SYSTEM_HEADER can be used in files that contain #include_next,
21 dnl so as to avoid GCC warnings when the gcc option -pedantic is used.
22 dnl '#pragma GCC system_header' has the same effect as if the file was found
23 dnl through the include search path specified with '-isystem' options (as
24 dnl opposed to the search path specified with '-I' options). Namely, gcc
25 dnl does not warn about some things, and on some systems (Solaris and Interix)
26 dnl __STDC__ evaluates to 0 instead of to 1. The latter is an undesired side
27 dnl effect; we are therefore careful to use 'defined __STDC__' or '1' instead
28 dnl of plain '__STDC__'.
30 dnl PRAGMA_COLUMNS can be used in files that override system header files, so
31 dnl as to avoid compilation errors on HP NonStop systems when the gnulib file
32 dnl is included by a system header file that does a "#pragma COLUMNS 80" (which
33 dnl has the effect of truncating the lines of that file and all files that it
34 dnl includes to 80 columns) and the gnulib file has lines longer than 80
37 AC_DEFUN([gl_INCLUDE_NEXT],
39 AC_LANG_PREPROC_REQUIRE()
40 AC_CACHE_CHECK([whether the preprocessor supports include_next],
41 [gl_cv_have_include_next],
42 [rm -rf conftestd1a conftestd1b conftestd2
43 mkdir conftestd1a conftestd1b conftestd2
44 dnl IBM C 9.0, 10.1 (original versions, prior to the 2009-01 updates) on
45 dnl AIX 6.1 support include_next when used as first preprocessor directive
46 dnl in a file, but not when preceded by another include directive. Check
47 dnl for this bug by including <stdio.h>.
48 dnl Additionally, with this same compiler, include_next is a no-op when
49 dnl used in a header file that was included by specifying its absolute
50 dnl file name. Despite these two bugs, include_next is used in the
51 dnl compiler's <math.h>. By virtue of the second bug, we need to use
52 dnl include_next as well in this case.
53 cat <<EOF > conftestd1a/conftest.h
54 #define DEFINED_IN_CONFTESTD1
55 #include_next <conftest.h>
56 #ifdef DEFINED_IN_CONFTESTD2
59 #error "include_next doesn't work"
62 cat <<EOF > conftestd1b/conftest.h
63 #define DEFINED_IN_CONFTESTD1
65 #include_next <conftest.h>
66 #ifdef DEFINED_IN_CONFTESTD2
69 #error "include_next doesn't work"
72 cat <<EOF > conftestd2/conftest.h
73 #ifndef DEFINED_IN_CONFTESTD1
74 #error "include_next test doesn't work"
76 #define DEFINED_IN_CONFTESTD2
78 gl_saved_CPPFLAGS="$CPPFLAGS"
79 CPPFLAGS="$gl_saved_CPPFLAGS -Iconftestd1b -Iconftestd2"
80 dnl We intentionally avoid using AC_LANG_SOURCE here.
81 AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED[#include <conftest.h>]],
82 [gl_cv_have_include_next=yes],
83 [CPPFLAGS="$gl_saved_CPPFLAGS -Iconftestd1a -Iconftestd2"
84 AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED[#include <conftest.h>]],
85 [gl_cv_have_include_next=buggy],
86 [gl_cv_have_include_next=no])
88 CPPFLAGS="$gl_saved_CPPFLAGS"
89 rm -rf conftestd1a conftestd1b conftestd2
92 if test $gl_cv_have_include_next = yes; then
93 INCLUDE_NEXT=include_next
94 INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include_next
95 if test -n "$GCC"; then
96 PRAGMA_SYSTEM_HEADER='#pragma GCC system_header'
99 if test $gl_cv_have_include_next = buggy; then
101 INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include_next
104 INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include
107 AC_SUBST([INCLUDE_NEXT])
108 AC_SUBST([INCLUDE_NEXT_AS_FIRST_DIRECTIVE])
109 AC_SUBST([PRAGMA_SYSTEM_HEADER])
111 dnl HP NonStop systems, which define __TANDEM, limit the line length
112 dnl after including some system header files.
113 AC_CACHE_CHECK([whether source code line length is unlimited],
114 [gl_cv_source_line_length_unlimited],
115 [AC_EGREP_CPP([choke me],
121 [gl_cv_source_line_length_unlimited=no],
122 [gl_cv_source_line_length_unlimited=yes])
124 if test $gl_cv_source_line_length_unlimited = no; then
125 PRAGMA_COLUMNS="#pragma COLUMNS 10000"
129 AC_SUBST([PRAGMA_COLUMNS])
132 # gl_CHECK_NEXT_HEADERS(HEADER1 HEADER2 ...)
133 # ------------------------------------------
134 # For each arg foo.h, if #include_next works, define NEXT_FOO_H to be
135 # '<foo.h>'; otherwise define it to be
136 # '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
137 # Also, if #include_next works as first preprocessing directive in a file,
138 # define NEXT_AS_FIRST_DIRECTIVE_FOO_H to be '<foo.h>'; otherwise define it to
140 # '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
141 # That way, a header file with the following line:
142 # #@INCLUDE_NEXT@ @NEXT_FOO_H@
144 # #@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_FOO_H@
145 # behaves (after sed substitution) as if it contained
146 # #include_next <foo.h>
147 # even if the compiler does not support include_next.
148 # The three "///" are to pacify Sun C 5.8, which otherwise would say
149 # "warning: #include of /usr/include/... may be non-portable".
150 # Use '""', not '<>', so that the /// cannot be confused with a C99 comment.
151 # Note: This macro assumes that the header file is not empty after
152 # preprocessing, i.e. it does not only define preprocessor macros but also
153 # provides some type/enum definitions or function/variable declarations.
155 # This macro also checks whether each header exists, by invoking
156 # AC_CHECK_HEADERS_ONCE or AC_CHECK_HEADERS on each argument.
157 AC_DEFUN([gl_CHECK_NEXT_HEADERS],
159 gl_NEXT_HEADERS_INTERNAL([$1], [check])
162 # gl_NEXT_HEADERS(HEADER1 HEADER2 ...)
163 # ------------------------------------
164 # Like gl_CHECK_NEXT_HEADERS, except do not check whether the headers exist.
165 # This is suitable for headers like <stddef.h> that are standardized by C89
166 # and therefore can be assumed to exist.
167 AC_DEFUN([gl_NEXT_HEADERS],
169 gl_NEXT_HEADERS_INTERNAL([$1], [assume])
172 # The guts of gl_CHECK_NEXT_HEADERS and gl_NEXT_HEADERS.
173 AC_DEFUN([gl_NEXT_HEADERS_INTERNAL],
175 AC_REQUIRE([gl_INCLUDE_NEXT])
176 AC_REQUIRE([AC_CANONICAL_HOST])
179 [AC_CHECK_HEADERS_ONCE([$1])
182 m4_foreach_w([gl_HEADER_NAME], [$1],
183 [AS_VAR_PUSHDEF([gl_next_header],
184 [gl_cv_next_]m4_defn([gl_HEADER_NAME]))
185 if test $gl_cv_have_include_next = yes; then
186 AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
189 [absolute name of <]m4_defn([gl_HEADER_NAME])[>],
191 [m4_if([$2], [check],
192 [AS_VAR_PUSHDEF([gl_header_exists],
193 [ac_cv_header_]m4_defn([gl_HEADER_NAME]))
194 if test AS_VAR_GET([gl_header_exists]) = yes; then
195 AS_VAR_POPDEF([gl_header_exists])
197 gl_ABSOLUTE_HEADER_ONE(gl_HEADER_NAME)
198 AS_VAR_COPY([gl_header], [gl_cv_absolute_]AS_TR_SH(gl_HEADER_NAME))
199 AS_VAR_SET([gl_next_header], ['"'$gl_header'"'])
202 AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
208 AS_TR_CPP([NEXT_]m4_defn([gl_HEADER_NAME])),
209 [AS_VAR_GET([gl_next_header])])
210 if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then
211 # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next'
212 gl_next_as_first_directive='<'gl_HEADER_NAME'>'
214 # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include'
215 gl_next_as_first_directive=AS_VAR_GET([gl_next_header])
218 AS_TR_CPP([NEXT_AS_FIRST_DIRECTIVE_]m4_defn([gl_HEADER_NAME])),
219 [$gl_next_as_first_directive])
220 AS_VAR_POPDEF([gl_next_header])])
223 # Autoconf 2.68 added warnings for our use of AC_COMPILE_IFELSE;
224 # this fallback is safe for all earlier autoconf versions.
225 m4_define_default([AC_LANG_DEFINES_PROVIDED])