headers: make check of system header explicit
[gnulib.git] / m4 / wchar.m4
1 dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
2
3 dnl Copyright (C) 2007-2010 Free Software Foundation, 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 Written by Eric Blake.
9
10 # wchar.m4 serial 29
11
12 AC_DEFUN([gl_WCHAR_H],
13 [
14   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
15   AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
16   dnl Prepare for creating substitute <wchar.h>.
17   dnl Check for <wchar.h> (missing in Linux uClibc when built without wide
18   dnl character support).
19   dnl <wchar.h> is always overridden, because of GNULIB_POSIXCHECK.
20   AC_CHECK_HEADERS_ONCE([wchar.h])
21   gl_CHECK_NEXT_HEADERS([wchar.h])
22   if test $ac_cv_header_wchar_h = yes; then
23     HAVE_WCHAR_H=1
24     AC_CACHE_CHECK([whether <wchar.h> is standalone],
25       [gl_cv_header_wchar_h_standalone],
26       [AC_COMPILE_IFELSE([[#include <wchar.h>
27 wchar_t w;]],
28         [gl_cv_header_wchar_h_standalone=yes],
29         [gl_cv_header_wchar_h_standalone=no])])
30   else
31     HAVE_WCHAR_H=0
32   fi
33   AC_SUBST([HAVE_WCHAR_H])
34
35   AC_REQUIRE([gt_TYPE_WINT_T])
36   if test $gt_cv_c_wint_t = yes; then
37     HAVE_WINT_T=1
38   else
39     HAVE_WINT_T=0
40   fi
41   AC_SUBST([HAVE_WINT_T])
42 ])
43
44 dnl Check whether <wchar.h> is usable at all.
45 AC_DEFUN([gl_WCHAR_H_INLINE_OK],
46 [
47   dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
48   dnl 'gnu_inline'. See <http://sourceware.org/bugzilla/show_bug.cgi?id=4022>
49   dnl and <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
50   dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
51   dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
52   AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
53     [gl_cv_header_wchar_h_correct_inline],
54     [gl_cv_header_wchar_h_correct_inline=yes
55      AC_LANG_CONFTEST([
56        AC_LANG_SOURCE([[#define wcstod renamed_wcstod
57 #include <wchar.h>
58 extern int zero (void);
59 int main () { return zero(); }
60 ]])])
61      if AC_TRY_EVAL([ac_compile]); then
62        mv conftest.$ac_objext conftest1.$ac_objext
63        AC_LANG_CONFTEST([
64          AC_LANG_SOURCE([[#define wcstod renamed_wcstod
65 #include <wchar.h>
66 int zero (void) { return 0; }
67 ]])])
68        if AC_TRY_EVAL([ac_compile]); then
69          mv conftest.$ac_objext conftest2.$ac_objext
70          if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
71            :
72          else
73            gl_cv_header_wchar_h_correct_inline=no
74          fi
75        fi
76      fi
77      rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
78     ])
79   if test $gl_cv_header_wchar_h_correct_inline = no; then
80     AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
81 This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
82 C99 mode. You have four options:
83   - Add the flag -fgnu89-inline to CC and reconfigure, or
84   - Fix your include files, using parts of
85     <http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
86   - Use a gcc version older than 4.3, or
87   - Don't use the flags -std=c99 or -std=gnu99.
88 Configuration aborted.])
89   fi
90 ])
91
92 dnl Unconditionally enables the replacement of <wchar.h>.
93 AC_DEFUN([gl_REPLACE_WCHAR_H],
94 [
95   dnl This is a no-op, because <wchar.h> is always overridden.
96   :
97 ])
98
99 AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
100 [
101   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
102   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
103   GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
104 ])
105
106 AC_DEFUN([gl_WCHAR_H_DEFAULTS],
107 [
108   GNULIB_BTOWC=0;      AC_SUBST([GNULIB_BTOWC])
109   GNULIB_WCTOB=0;      AC_SUBST([GNULIB_WCTOB])
110   GNULIB_MBSINIT=0;    AC_SUBST([GNULIB_MBSINIT])
111   GNULIB_MBRTOWC=0;    AC_SUBST([GNULIB_MBRTOWC])
112   GNULIB_MBRLEN=0;     AC_SUBST([GNULIB_MBRLEN])
113   GNULIB_MBSRTOWCS=0;  AC_SUBST([GNULIB_MBSRTOWCS])
114   GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
115   GNULIB_WCRTOMB=0;    AC_SUBST([GNULIB_WCRTOMB])
116   GNULIB_WCSRTOMBS=0;  AC_SUBST([GNULIB_WCSRTOMBS])
117   GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
118   GNULIB_WCWIDTH=0;    AC_SUBST([GNULIB_WCWIDTH])
119   dnl Assume proper GNU behavior unless another module says otherwise.
120   HAVE_BTOWC=1;         AC_SUBST([HAVE_BTOWC])
121   HAVE_MBSINIT=1;       AC_SUBST([HAVE_MBSINIT])
122   HAVE_MBRTOWC=1;       AC_SUBST([HAVE_MBRTOWC])
123   HAVE_MBRLEN=1;        AC_SUBST([HAVE_MBRLEN])
124   HAVE_MBSRTOWCS=1;     AC_SUBST([HAVE_MBSRTOWCS])
125   HAVE_MBSNRTOWCS=1;    AC_SUBST([HAVE_MBSNRTOWCS])
126   HAVE_WCRTOMB=1;       AC_SUBST([HAVE_WCRTOMB])
127   HAVE_WCSRTOMBS=1;     AC_SUBST([HAVE_WCSRTOMBS])
128   HAVE_WCSNRTOMBS=1;    AC_SUBST([HAVE_WCSNRTOMBS])
129   HAVE_DECL_WCTOB=1;    AC_SUBST([HAVE_DECL_WCTOB])
130   HAVE_DECL_WCWIDTH=1;  AC_SUBST([HAVE_DECL_WCWIDTH])
131   REPLACE_MBSTATE_T=0;  AC_SUBST([REPLACE_MBSTATE_T])
132   REPLACE_BTOWC=0;      AC_SUBST([REPLACE_BTOWC])
133   REPLACE_WCTOB=0;      AC_SUBST([REPLACE_WCTOB])
134   REPLACE_MBSINIT=0;    AC_SUBST([REPLACE_MBSINIT])
135   REPLACE_MBRTOWC=0;    AC_SUBST([REPLACE_MBRTOWC])
136   REPLACE_MBRLEN=0;     AC_SUBST([REPLACE_MBRLEN])
137   REPLACE_MBSRTOWCS=0;  AC_SUBST([REPLACE_MBSRTOWCS])
138   REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
139   REPLACE_WCRTOMB=0;    AC_SUBST([REPLACE_WCRTOMB])
140   REPLACE_WCSRTOMBS=0;  AC_SUBST([REPLACE_WCSRTOMBS])
141   REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
142   REPLACE_WCWIDTH=0;    AC_SUBST([REPLACE_WCWIDTH])
143 ])