diff options
Diffstat (limited to 'gl/m4/include_next.m4')
-rw-r--r-- | gl/m4/include_next.m4 | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/gl/m4/include_next.m4 b/gl/m4/include_next.m4 new file mode 100644 index 00000000..7ce472bc --- /dev/null +++ b/gl/m4/include_next.m4 | |||
@@ -0,0 +1,107 @@ | |||
1 | # include_next.m4 serial 4 | ||
2 | dnl Copyright (C) 2006, 2007 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 | AC_DEFUN([gl_CHECK_NEXT_HEADERS], | ||
67 | [ | ||
68 | AC_REQUIRE([gl_INCLUDE_NEXT]) | ||
69 | AC_CHECK_HEADERS_ONCE([$1]) | ||
70 | |||
71 | AC_FOREACH([gl_HEADER_NAME], [$1], | ||
72 | [AS_VAR_PUSHDEF([gl_next_header], | ||
73 | [gl_cv_next_]m4_quote(m4_defn([gl_HEADER_NAME]))) | ||
74 | if test $gl_cv_have_include_next = yes; then | ||
75 | AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>']) | ||
76 | else | ||
77 | AC_CACHE_CHECK( | ||
78 | [absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>], | ||
79 | m4_quote(m4_defn([gl_next_header])), | ||
80 | [AS_VAR_PUSHDEF([gl_header_exists], | ||
81 | [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME]))) | ||
82 | if test AS_VAR_GET(gl_header_exists) = yes; then | ||
83 | AC_LANG_CONFTEST( | ||
84 | [AC_LANG_SOURCE( | ||
85 | [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]] | ||
86 | )]) | ||
87 | dnl eval is necessary to expand ac_cpp. | ||
88 | dnl Ultrix and Pyramid sh refuse to redirect output of eval, | ||
89 | dnl so use subshell. | ||
90 | AS_VAR_SET([gl_next_header], | ||
91 | ['"'`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | | ||
92 | sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{ | ||
93 | s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1# | ||
94 | s#^/[^/]#//&# | ||
95 | p | ||
96 | q | ||
97 | }'`'"']) | ||
98 | else | ||
99 | AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>']) | ||
100 | fi | ||
101 | AS_VAR_POPDEF([gl_header_exists])]) | ||
102 | fi | ||
103 | AC_SUBST( | ||
104 | AS_TR_CPP([NEXT_]m4_quote(m4_defn([gl_HEADER_NAME]))), | ||
105 | [AS_VAR_GET([gl_next_header])]) | ||
106 | AS_VAR_POPDEF([gl_next_header])]) | ||
107 | ]) | ||