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.
7
dnl From Paul Eggert and Derek Price.
9
AC_DEFUN([gl_INCLUDE_NEXT],
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
22
#error "include_next doesn't work"
25
cat <<EOF > conftestd2/conftest.h
26
#ifndef DEFINED_IN_CONFTESTD1
27
#error "include_next test doesn't work"
29
#define DEFINED_IN_CONFTESTD2
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
39
if test $gl_cv_have_include_next = yes; then
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.])
46
INCLUDE_NEXT=include_next
50
AC_SUBST([INCLUDE_NEXT])
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],
71
AC_REQUIRE([gl_INCLUDE_NEXT])
72
AC_CHECK_HEADERS_ONCE([$1])
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'>'])
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
88
[[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]]
90
dnl eval is necessary to expand ac_cpp.
91
dnl Ultrix and Pyramid sh refuse to redirect output of eval,
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#
102
AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
104
AS_VAR_POPDEF([gl_header_exists])])
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])])