merge from guile master
[bpt/guile.git] / m4 / include_next.m4
1 # include_next.m4 serial 6
2 dnl Copyright (C) 2006-2008 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Paul Eggert and Derek Price.
8
9 AC_DEFUN([gl_INCLUDE_NEXT],
10 [
11 AC_LANG_PREPROC_REQUIRE()
12 AC_CACHE_CHECK([whether the preprocessor supports include_next],
13 [gl_cv_have_include_next],
14 [rm -rf conftestd1 conftestd2
15 mkdir conftestd1 conftestd2
16 cat <<EOF > conftestd1/conftest.h
17 #define DEFINED_IN_CONFTESTD1
18 #include_next <conftest.h>
19 #ifdef DEFINED_IN_CONFTESTD2
20 int foo;
21 #else
22 #error "include_next doesn't work"
23 #endif
24 EOF
25 cat <<EOF > conftestd2/conftest.h
26 #ifndef DEFINED_IN_CONFTESTD1
27 #error "include_next test doesn't work"
28 #endif
29 #define DEFINED_IN_CONFTESTD2
30 EOF
31 save_CPPFLAGS="$CPPFLAGS"
32 CPPFLAGS="$CPPFLAGS -Iconftestd1 -Iconftestd2"
33 AC_COMPILE_IFELSE([#include <conftest.h>],
34 [gl_cv_have_include_next=yes],
35 [gl_cv_have_include_next=no])
36 CPPFLAGS="$save_CPPFLAGS"
37 rm -rf conftestd1 conftestd2
38 ])
39 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
47 else
48 INCLUDE_NEXT=include
49 fi
50 AC_SUBST([INCLUDE_NEXT])
51 ])
52
53 # gl_CHECK_NEXT_HEADERS(HEADER1 HEADER2 ...)
54 # ------------------------------------------
55 # For each arg foo.h, if #include_next works, define NEXT_FOO_H to be
56 # '<foo.h>'; otherwise define it to be
57 # '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
58 # That way, a header file with the following line:
59 # #@INCLUDE_NEXT@ @NEXT_FOO_H@
60 # behaves (after sed substitution) as if it contained
61 # #include_next <foo.h>
62 # even if the compiler does not support include_next.
63 # The three "///" are to pacify Sun C 5.8, which otherwise would say
64 # "warning: #include of /usr/include/... may be non-portable".
65 # Use `""', not `<>', so that the /// cannot be confused with a C99 comment.
66 # Note: This macro assumes that the header file is not empty after
67 # preprocessing, i.e. it does not only define preprocessor macros but also
68 # provides some type/enum definitions or function/variable declarations.
69 AC_DEFUN([gl_CHECK_NEXT_HEADERS],
70 [
71 AC_REQUIRE([gl_INCLUDE_NEXT])
72 AC_CHECK_HEADERS_ONCE([$1])
73
74 m4_foreach_w([gl_HEADER_NAME], [$1],
75 [AS_VAR_PUSHDEF([gl_next_header],
76 [gl_cv_next_]m4_quote(m4_defn([gl_HEADER_NAME])))
77 if test $gl_cv_have_include_next = yes; then
78 AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
79 else
80 AC_CACHE_CHECK(
81 [absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>],
82 m4_quote(m4_defn([gl_next_header])),
83 [AS_VAR_PUSHDEF([gl_header_exists],
84 [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME])))
85 if test AS_VAR_GET(gl_header_exists) = yes; then
86 AC_LANG_CONFTEST(
87 [AC_LANG_SOURCE(
88 [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]]
89 )])
90 dnl eval is necessary to expand ac_cpp.
91 dnl Ultrix and Pyramid sh refuse to redirect output of eval,
92 dnl so use subshell.
93 AS_VAR_SET([gl_next_header],
94 ['"'`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
95 sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{
96 s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#
97 s#^/[^/]#//&#
98 p
99 q
100 }'`'"'])
101 else
102 AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
103 fi
104 AS_VAR_POPDEF([gl_header_exists])])
105 fi
106 AC_SUBST(
107 AS_TR_CPP([NEXT_]m4_quote(m4_defn([gl_HEADER_NAME]))),
108 [AS_VAR_GET([gl_next_header])])
109 AS_VAR_POPDEF([gl_next_header])])
110 ])