]> sjero.net Git - wget/blob - md5/m4/include_next.m4
Fix some build issues
[wget] / md5 / m4 / include_next.m4
1 # include_next.m4 serial 14
2 dnl Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation,
3 dnl Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7
8 dnl From Paul Eggert and Derek Price.
9
10 dnl Sets INCLUDE_NEXT and PRAGMA_SYSTEM_HEADER.
11 dnl
12 dnl INCLUDE_NEXT expands to 'include_next' if the compiler supports it, or to
13 dnl 'include' otherwise.
14 dnl
15 dnl INCLUDE_NEXT_AS_FIRST_DIRECTIVE expands to 'include_next' if the compiler
16 dnl supports it in the special case that it is the first include directive in
17 dnl the given file, or to 'include' otherwise.
18 dnl
19 dnl PRAGMA_SYSTEM_HEADER can be used in files that contain #include_next,
20 dnl so as to avoid GCC warnings when the gcc option -pedantic is used.
21 dnl '#pragma GCC system_header' has the same effect as if the file was found
22 dnl through the include search path specified with '-isystem' options (as
23 dnl opposed to the search path specified with '-I' options). Namely, gcc
24 dnl does not warn about some things, and on some systems (Solaris and Interix)
25 dnl __STDC__ evaluates to 0 instead of to 1. The latter is an undesired side
26 dnl effect; we are therefore careful to use 'defined __STDC__' or '1' instead
27 dnl of plain '__STDC__'.
28
29 AC_DEFUN([gl_INCLUDE_NEXT],
30 [
31   AC_LANG_PREPROC_REQUIRE()
32   AC_CACHE_CHECK([whether the preprocessor supports include_next],
33     [gl_cv_have_include_next],
34     [rm -rf conftestd1a conftestd1b conftestd2
35      mkdir conftestd1a conftestd1b conftestd2
36      dnl IBM C 9.0, 10.1 (original versions, prior to the 2009-01 updates) on
37      dnl AIX 6.1 support include_next when used as first preprocessor directive
38      dnl in a file, but not when preceded by another include directive. Check
39      dnl for this bug by including <stdio.h>.
40      dnl Additionally, with this same compiler, include_next is a no-op when
41      dnl used in a header file that was included by specifying its absolute
42      dnl file name. Despite these two bugs, include_next is used in the
43      dnl compiler's <math.h>. By virtue of the second bug, we need to use
44      dnl include_next as well in this case.
45      cat <<EOF > conftestd1a/conftest.h
46 #define DEFINED_IN_CONFTESTD1
47 #include_next <conftest.h>
48 #ifdef DEFINED_IN_CONFTESTD2
49 int foo;
50 #else
51 #error "include_next doesn't work"
52 #endif
53 EOF
54      cat <<EOF > conftestd1b/conftest.h
55 #define DEFINED_IN_CONFTESTD1
56 #include <stdio.h>
57 #include_next <conftest.h>
58 #ifdef DEFINED_IN_CONFTESTD2
59 int foo;
60 #else
61 #error "include_next doesn't work"
62 #endif
63 EOF
64      cat <<EOF > conftestd2/conftest.h
65 #ifndef DEFINED_IN_CONFTESTD1
66 #error "include_next test doesn't work"
67 #endif
68 #define DEFINED_IN_CONFTESTD2
69 EOF
70      gl_save_CPPFLAGS="$CPPFLAGS"
71      CPPFLAGS="$gl_save_CPPFLAGS -Iconftestd1b -Iconftestd2"
72      AC_COMPILE_IFELSE([#include <conftest.h>],
73        [gl_cv_have_include_next=yes],
74        [CPPFLAGS="$gl_save_CPPFLAGS -Iconftestd1a -Iconftestd2"
75         AC_COMPILE_IFELSE([#include <conftest.h>],
76           [gl_cv_have_include_next=buggy],
77           [gl_cv_have_include_next=no])
78        ])
79      CPPFLAGS="$gl_save_CPPFLAGS"
80      rm -rf conftestd1a conftestd1b conftestd2
81     ])
82   PRAGMA_SYSTEM_HEADER=
83   if test $gl_cv_have_include_next = yes; then
84     INCLUDE_NEXT=include_next
85     INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include_next
86     if test -n "$GCC"; then
87       PRAGMA_SYSTEM_HEADER='#pragma GCC system_header'
88     fi
89   else
90     if test $gl_cv_have_include_next = buggy; then
91       INCLUDE_NEXT=include
92       INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include_next
93     else
94       INCLUDE_NEXT=include
95       INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include
96     fi
97   fi
98   AC_SUBST([INCLUDE_NEXT])
99   AC_SUBST([INCLUDE_NEXT_AS_FIRST_DIRECTIVE])
100   AC_SUBST([PRAGMA_SYSTEM_HEADER])
101 ])
102
103 # gl_CHECK_NEXT_HEADERS(HEADER1 HEADER2 ...)
104 # ------------------------------------------
105 # For each arg foo.h, if #include_next works, define NEXT_FOO_H to be
106 # '<foo.h>'; otherwise define it to be
107 # '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
108 # Also, if #include_next works as first preprocessing directive in a file,
109 # define NEXT_AS_FIRST_DIRECTIVE_FOO_H to be '<foo.h>'; otherwise define it to
110 # be
111 # '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
112 # That way, a header file with the following line:
113 #       #@INCLUDE_NEXT@ @NEXT_FOO_H@
114 # or
115 #       #@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_FOO_H@
116 # behaves (after sed substitution) as if it contained
117 #       #include_next <foo.h>
118 # even if the compiler does not support include_next.
119 # The three "///" are to pacify Sun C 5.8, which otherwise would say
120 # "warning: #include of /usr/include/... may be non-portable".
121 # Use `""', not `<>', so that the /// cannot be confused with a C99 comment.
122 # Note: This macro assumes that the header file is not empty after
123 # preprocessing, i.e. it does not only define preprocessor macros but also
124 # provides some type/enum definitions or function/variable declarations.
125 AC_DEFUN([gl_CHECK_NEXT_HEADERS],
126 [
127   AC_REQUIRE([gl_INCLUDE_NEXT])
128   AC_REQUIRE([AC_CANONICAL_HOST])
129   AC_CHECK_HEADERS_ONCE([$1])
130
131   m4_foreach_w([gl_HEADER_NAME], [$1],
132     [AS_VAR_PUSHDEF([gl_next_header],
133                     [gl_cv_next_]m4_defn([gl_HEADER_NAME]))
134      if test $gl_cv_have_include_next = yes; then
135        AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
136      else
137        AC_CACHE_CHECK(
138          [absolute name of <]m4_defn([gl_HEADER_NAME])[>],
139          m4_defn([gl_next_header]),
140          [AS_VAR_PUSHDEF([gl_header_exists],
141                          [ac_cv_header_]m4_defn([gl_HEADER_NAME]))
142           if test AS_VAR_GET(gl_header_exists) = yes; then
143             AC_LANG_CONFTEST(
144               [AC_LANG_SOURCE(
145                  [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]]
146                )])
147             dnl AIX "xlc -E" and "cc -E" omit #line directives for header files
148             dnl that contain only a #include of other header files and no
149             dnl non-comment tokens of their own. This leads to a failure to
150             dnl detect the absolute name of <dirent.h>, <signal.h>, <poll.h>
151             dnl and others. The workaround is to force preservation of comments
152             dnl through option -C. This ensures all necessary #line directives
153             dnl are present. GCC supports option -C as well.
154             case "$host_os" in
155               aix*) gl_absname_cpp="$ac_cpp -C" ;;
156               *)    gl_absname_cpp="$ac_cpp" ;;
157             esac
158             dnl eval is necessary to expand gl_absname_cpp.
159             dnl Ultrix and Pyramid sh refuse to redirect output of eval,
160             dnl so use subshell.
161             AS_VAR_SET([gl_next_header],
162               ['"'`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
163                sed -n '\#/]m4_defn([gl_HEADER_NAME])[#{
164                  s#.*"\(.*/]m4_defn([gl_HEADER_NAME])[\)".*#\1#
165                  s#^/[^/]#//&#
166                  p
167                  q
168                }'`'"'])
169           else
170             AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
171           fi
172           AS_VAR_POPDEF([gl_header_exists])])
173      fi
174      AC_SUBST(
175        AS_TR_CPP([NEXT_]m4_defn([gl_HEADER_NAME])),
176        [AS_VAR_GET([gl_next_header])])
177      if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then
178        # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next'
179        gl_next_as_first_directive='<'gl_HEADER_NAME'>'
180      else
181        # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include'
182        gl_next_as_first_directive=AS_VAR_GET([gl_next_header])
183      fi
184      AC_SUBST(
185        AS_TR_CPP([NEXT_AS_FIRST_DIRECTIVE_]m4_defn([gl_HEADER_NAME])),
186        [$gl_next_as_first_directive])
187      AS_VAR_POPDEF([gl_next_header])])
188 ])