Use orthodox libtoology in `guile'.
[bpt/guile.git] / m4 / include_next.m4
CommitLineData
e65fc94b 1# include_next.m4 serial 7
103dc4d4
LC
2dnl Copyright (C) 2006-2008 Free Software Foundation, Inc.
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
e65fc94b
LC
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 PRAGMA_SYSTEM_HEADER can be used in files that contain #include_next,
15dnl so as to avoid GCC warnings when the gcc option -pedantic is used.
16dnl '#pragma GCC system_header' has the same effect as if the file was found
17dnl through the include search path specified with '-isystem' options (as
18dnl opposed to the search path specified with '-I' options). Namely, gcc
19dnl does not warn about some things, and on some systems (Solaris and Interix)
20dnl __STDC__ evaluates to 0 instead of to 1. The latter is an undesired side
21dnl effect; we are therefore careful to use 'defined __STDC__' or '1' instead
22dnl of plain '__STDC__'.
23
103dc4d4
LC
24AC_DEFUN([gl_INCLUDE_NEXT],
25[
26 AC_LANG_PREPROC_REQUIRE()
27 AC_CACHE_CHECK([whether the preprocessor supports include_next],
28 [gl_cv_have_include_next],
29 [rm -rf conftestd1 conftestd2
30 mkdir conftestd1 conftestd2
31 cat <<EOF > conftestd1/conftest.h
32#define DEFINED_IN_CONFTESTD1
33#include_next <conftest.h>
34#ifdef DEFINED_IN_CONFTESTD2
35int foo;
36#else
37#error "include_next doesn't work"
38#endif
39EOF
40 cat <<EOF > conftestd2/conftest.h
41#ifndef DEFINED_IN_CONFTESTD1
42#error "include_next test doesn't work"
43#endif
44#define DEFINED_IN_CONFTESTD2
45EOF
46 save_CPPFLAGS="$CPPFLAGS"
47 CPPFLAGS="$CPPFLAGS -Iconftestd1 -Iconftestd2"
48 AC_COMPILE_IFELSE([#include <conftest.h>],
49 [gl_cv_have_include_next=yes],
50 [gl_cv_have_include_next=no])
51 CPPFLAGS="$save_CPPFLAGS"
52 rm -rf conftestd1 conftestd2
53 ])
e65fc94b 54 PRAGMA_SYSTEM_HEADER=
103dc4d4 55 if test $gl_cv_have_include_next = yes; then
103dc4d4 56 INCLUDE_NEXT=include_next
e65fc94b
LC
57 if test -n "$GCC"; then
58 PRAGMA_SYSTEM_HEADER='#pragma GCC system_header'
59 fi
103dc4d4
LC
60 else
61 INCLUDE_NEXT=include
62 fi
63 AC_SUBST([INCLUDE_NEXT])
e65fc94b 64 AC_SUBST([PRAGMA_SYSTEM_HEADER])
103dc4d4
LC
65])
66
67# gl_CHECK_NEXT_HEADERS(HEADER1 HEADER2 ...)
68# ------------------------------------------
69# For each arg foo.h, if #include_next works, define NEXT_FOO_H to be
70# '<foo.h>'; otherwise define it to be
71# '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
72# That way, a header file with the following line:
73# #@INCLUDE_NEXT@ @NEXT_FOO_H@
74# behaves (after sed substitution) as if it contained
75# #include_next <foo.h>
76# even if the compiler does not support include_next.
77# The three "///" are to pacify Sun C 5.8, which otherwise would say
78# "warning: #include of /usr/include/... may be non-portable".
79# Use `""', not `<>', so that the /// cannot be confused with a C99 comment.
80# Note: This macro assumes that the header file is not empty after
81# preprocessing, i.e. it does not only define preprocessor macros but also
82# provides some type/enum definitions or function/variable declarations.
83AC_DEFUN([gl_CHECK_NEXT_HEADERS],
84[
85 AC_REQUIRE([gl_INCLUDE_NEXT])
86 AC_CHECK_HEADERS_ONCE([$1])
87
88 m4_foreach_w([gl_HEADER_NAME], [$1],
89 [AS_VAR_PUSHDEF([gl_next_header],
90 [gl_cv_next_]m4_quote(m4_defn([gl_HEADER_NAME])))
91 if test $gl_cv_have_include_next = yes; then
92 AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
93 else
94 AC_CACHE_CHECK(
95 [absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>],
96 m4_quote(m4_defn([gl_next_header])),
97 [AS_VAR_PUSHDEF([gl_header_exists],
98 [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME])))
99 if test AS_VAR_GET(gl_header_exists) = yes; then
100 AC_LANG_CONFTEST(
101 [AC_LANG_SOURCE(
102 [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]]
103 )])
104 dnl eval is necessary to expand ac_cpp.
105 dnl Ultrix and Pyramid sh refuse to redirect output of eval,
106 dnl so use subshell.
107 AS_VAR_SET([gl_next_header],
108 ['"'`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
109 sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{
110 s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#
111 s#^/[^/]#//&#
112 p
113 q
114 }'`'"'])
115 else
116 AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
117 fi
118 AS_VAR_POPDEF([gl_header_exists])])
119 fi
120 AC_SUBST(
121 AS_TR_CPP([NEXT_]m4_quote(m4_defn([gl_HEADER_NAME]))),
122 [AS_VAR_GET([gl_next_header])])
123 AS_VAR_POPDEF([gl_next_header])])
124])