New module 'wmemcmp'.
[gnulib.git] / m4 / wchar_h.m4
1 dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
2
3 dnl Copyright (C) 2007-2011 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_h.m4 serial 38
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   gl_CHECK_NEXT_HEADERS([wchar.h])
21   if test $ac_cv_header_wchar_h = yes; then
22     HAVE_WCHAR_H=1
23   else
24     HAVE_WCHAR_H=0
25   fi
26   AC_SUBST([HAVE_WCHAR_H])
27
28   AC_REQUIRE([gl_FEATURES_H])
29
30   AC_REQUIRE([gt_TYPE_WINT_T])
31   if test $gt_cv_c_wint_t = yes; then
32     HAVE_WINT_T=1
33   else
34     HAVE_WINT_T=0
35   fi
36   AC_SUBST([HAVE_WINT_T])
37
38   dnl Check for declarations of anything we want to poison if the
39   dnl corresponding gnulib module is not in use.
40   gl_WARN_ON_USE_PREPARE([[
41 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
42    <wchar.h>.
43    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
44    included before <wchar.h>.  */
45 #if !(defined __GLIBC__ && !defined __UCLIBC__)
46 # include <stddef.h>
47 # include <stdio.h>
48 # include <time.h>
49 #endif
50 #include <wchar.h>
51     ]],
52     [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb
53      wcsrtombs wcsnrtombs wcwidth wmemchr wmemcmp
54     ])
55 ])
56
57 dnl Check whether <wchar.h> is usable at all.
58 AC_DEFUN([gl_WCHAR_H_INLINE_OK],
59 [
60   dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
61   dnl 'gnu_inline'. See <http://sourceware.org/bugzilla/show_bug.cgi?id=4022>
62   dnl and <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
63   dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
64   dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
65   AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
66     [gl_cv_header_wchar_h_correct_inline],
67     [gl_cv_header_wchar_h_correct_inline=yes
68      AC_LANG_CONFTEST([
69        AC_LANG_SOURCE([[#define wcstod renamed_wcstod
70 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
71    <wchar.h>.
72    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
73    included before <wchar.h>.  */
74 #include <stddef.h>
75 #include <stdio.h>
76 #include <time.h>
77 #include <wchar.h>
78 extern int zero (void);
79 int main () { return zero(); }
80 ]])])
81      if AC_TRY_EVAL([ac_compile]); then
82        mv conftest.$ac_objext conftest1.$ac_objext
83        AC_LANG_CONFTEST([
84          AC_LANG_SOURCE([[#define wcstod renamed_wcstod
85 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
86    <wchar.h>.
87    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
88    included before <wchar.h>.  */
89 #include <stddef.h>
90 #include <stdio.h>
91 #include <time.h>
92 #include <wchar.h>
93 int zero (void) { return 0; }
94 ]])])
95        if AC_TRY_EVAL([ac_compile]); then
96          mv conftest.$ac_objext conftest2.$ac_objext
97          if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
98            :
99          else
100            gl_cv_header_wchar_h_correct_inline=no
101          fi
102        fi
103      fi
104      rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
105     ])
106   if test $gl_cv_header_wchar_h_correct_inline = no; then
107     AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
108 This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
109 C99 mode. You have four options:
110   - Add the flag -fgnu89-inline to CC and reconfigure, or
111   - Fix your include files, using parts of
112     <http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
113   - Use a gcc version older than 4.3, or
114   - Don't use the flags -std=c99 or -std=gnu99.
115 Configuration aborted.])
116   fi
117 ])
118
119 dnl Unconditionally enables the replacement of <wchar.h>.
120 AC_DEFUN([gl_REPLACE_WCHAR_H],
121 [
122   dnl This is a no-op, because <wchar.h> is always overridden.
123   :
124 ])
125
126 AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
127 [
128   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
129   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
130   gl_MODULE_INDICATOR_SET_VARIABLE([$1])
131   dnl Define it also as a C macro, for the benefit of the unit tests.
132   gl_MODULE_INDICATOR_FOR_TESTS([$1])
133 ])
134
135 AC_DEFUN([gl_WCHAR_H_DEFAULTS],
136 [
137   GNULIB_BTOWC=0;      AC_SUBST([GNULIB_BTOWC])
138   GNULIB_WCTOB=0;      AC_SUBST([GNULIB_WCTOB])
139   GNULIB_MBSINIT=0;    AC_SUBST([GNULIB_MBSINIT])
140   GNULIB_MBRTOWC=0;    AC_SUBST([GNULIB_MBRTOWC])
141   GNULIB_MBRLEN=0;     AC_SUBST([GNULIB_MBRLEN])
142   GNULIB_MBSRTOWCS=0;  AC_SUBST([GNULIB_MBSRTOWCS])
143   GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
144   GNULIB_WCRTOMB=0;    AC_SUBST([GNULIB_WCRTOMB])
145   GNULIB_WCSRTOMBS=0;  AC_SUBST([GNULIB_WCSRTOMBS])
146   GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
147   GNULIB_WCWIDTH=0;    AC_SUBST([GNULIB_WCWIDTH])
148   GNULIB_WMEMCHR=0;    AC_SUBST([GNULIB_WMEMCHR])
149   GNULIB_WMEMCMP=0;    AC_SUBST([GNULIB_WMEMCMP])
150   dnl Assume proper GNU behavior unless another module says otherwise.
151   HAVE_BTOWC=1;         AC_SUBST([HAVE_BTOWC])
152   HAVE_MBSINIT=1;       AC_SUBST([HAVE_MBSINIT])
153   HAVE_MBRTOWC=1;       AC_SUBST([HAVE_MBRTOWC])
154   HAVE_MBRLEN=1;        AC_SUBST([HAVE_MBRLEN])
155   HAVE_MBSRTOWCS=1;     AC_SUBST([HAVE_MBSRTOWCS])
156   HAVE_MBSNRTOWCS=1;    AC_SUBST([HAVE_MBSNRTOWCS])
157   HAVE_WCRTOMB=1;       AC_SUBST([HAVE_WCRTOMB])
158   HAVE_WCSRTOMBS=1;     AC_SUBST([HAVE_WCSRTOMBS])
159   HAVE_WCSNRTOMBS=1;    AC_SUBST([HAVE_WCSNRTOMBS])
160   HAVE_WMEMCHR=1;       AC_SUBST([HAVE_WMEMCHR])
161   HAVE_WMEMCMP=1;       AC_SUBST([HAVE_WMEMCMP])
162   HAVE_DECL_WCTOB=1;    AC_SUBST([HAVE_DECL_WCTOB])
163   HAVE_DECL_WCWIDTH=1;  AC_SUBST([HAVE_DECL_WCWIDTH])
164   REPLACE_MBSTATE_T=0;  AC_SUBST([REPLACE_MBSTATE_T])
165   REPLACE_BTOWC=0;      AC_SUBST([REPLACE_BTOWC])
166   REPLACE_WCTOB=0;      AC_SUBST([REPLACE_WCTOB])
167   REPLACE_MBSINIT=0;    AC_SUBST([REPLACE_MBSINIT])
168   REPLACE_MBRTOWC=0;    AC_SUBST([REPLACE_MBRTOWC])
169   REPLACE_MBRLEN=0;     AC_SUBST([REPLACE_MBRLEN])
170   REPLACE_MBSRTOWCS=0;  AC_SUBST([REPLACE_MBSRTOWCS])
171   REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
172   REPLACE_WCRTOMB=0;    AC_SUBST([REPLACE_WCRTOMB])
173   REPLACE_WCSRTOMBS=0;  AC_SUBST([REPLACE_WCSRTOMBS])
174   REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
175   REPLACE_WCWIDTH=0;    AC_SUBST([REPLACE_WCWIDTH])
176 ])