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