Don't define HAVE_INCLUDE_NEXT any more.
[gnulib.git] / m4 / include_next.m4
1 # include_next.m4 serial 7
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     INCLUDE_NEXT=include_next
41   else
42     INCLUDE_NEXT=include
43   fi
44   AC_SUBST([INCLUDE_NEXT])
45 ])
46
47 # gl_CHECK_NEXT_HEADERS(HEADER1 HEADER2 ...)
48 # ------------------------------------------
49 # For each arg foo.h, if #include_next works, define NEXT_FOO_H to be
50 # '<foo.h>'; otherwise define it to be
51 # '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
52 # That way, a header file with the following line:
53 #       #@INCLUDE_NEXT@ @NEXT_FOO_H@
54 # behaves (after sed substitution) as if it contained
55 #       #include_next <foo.h>
56 # even if the compiler does not support include_next.
57 # The three "///" are to pacify Sun C 5.8, which otherwise would say
58 # "warning: #include of /usr/include/... may be non-portable".
59 # Use `""', not `<>', so that the /// cannot be confused with a C99 comment.
60 # Note: This macro assumes that the header file is not empty after
61 # preprocessing, i.e. it does not only define preprocessor macros but also
62 # provides some type/enum definitions or function/variable declarations.
63 AC_DEFUN([gl_CHECK_NEXT_HEADERS],
64 [
65   AC_REQUIRE([gl_INCLUDE_NEXT])
66   AC_CHECK_HEADERS_ONCE([$1])
67
68   m4_foreach_w([gl_HEADER_NAME], [$1],
69     [AS_VAR_PUSHDEF([gl_next_header],
70                     [gl_cv_next_]m4_quote(m4_defn([gl_HEADER_NAME])))
71      if test $gl_cv_have_include_next = yes; then
72        AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
73      else
74        AC_CACHE_CHECK(
75          [absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>],
76          m4_quote(m4_defn([gl_next_header])),
77          [AS_VAR_PUSHDEF([gl_header_exists],
78                          [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME])))
79           if test AS_VAR_GET(gl_header_exists) = yes; then
80             AC_LANG_CONFTEST(
81               [AC_LANG_SOURCE(
82                  [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]]
83                )])
84             dnl eval is necessary to expand ac_cpp.
85             dnl Ultrix and Pyramid sh refuse to redirect output of eval,
86             dnl so use subshell.
87             AS_VAR_SET([gl_next_header],
88               ['"'`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
89                sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{
90                  s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#
91                  s#^/[^/]#//&#
92                  p
93                  q
94                }'`'"'])
95           else
96             AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
97           fi
98           AS_VAR_POPDEF([gl_header_exists])])
99      fi
100      AC_SUBST(
101        AS_TR_CPP([NEXT_]m4_quote(m4_defn([gl_HEADER_NAME]))),
102        [AS_VAR_GET([gl_next_header])])
103      AS_VAR_POPDEF([gl_next_header])])
104 ])