New module 'wcsdup'.
[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 wmemcpy wmemmove wmemset
54      wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp
55      wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup
56     ])
57 ])
58
59 dnl Check whether <wchar.h> is usable at all.
60 AC_DEFUN([gl_WCHAR_H_INLINE_OK],
61 [
62   dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
63   dnl 'gnu_inline'. See <http://sourceware.org/bugzilla/show_bug.cgi?id=4022>
64   dnl and <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
65   dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
66   dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
67   AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
68     [gl_cv_header_wchar_h_correct_inline],
69     [gl_cv_header_wchar_h_correct_inline=yes
70      AC_LANG_CONFTEST([
71        AC_LANG_SOURCE([[#define wcstod renamed_wcstod
72 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
73    <wchar.h>.
74    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
75    included before <wchar.h>.  */
76 #include <stddef.h>
77 #include <stdio.h>
78 #include <time.h>
79 #include <wchar.h>
80 extern int zero (void);
81 int main () { return zero(); }
82 ]])])
83      if AC_TRY_EVAL([ac_compile]); then
84        mv conftest.$ac_objext conftest1.$ac_objext
85        AC_LANG_CONFTEST([
86          AC_LANG_SOURCE([[#define wcstod renamed_wcstod
87 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
88    <wchar.h>.
89    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
90    included before <wchar.h>.  */
91 #include <stddef.h>
92 #include <stdio.h>
93 #include <time.h>
94 #include <wchar.h>
95 int zero (void) { return 0; }
96 ]])])
97        if AC_TRY_EVAL([ac_compile]); then
98          mv conftest.$ac_objext conftest2.$ac_objext
99          if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
100            :
101          else
102            gl_cv_header_wchar_h_correct_inline=no
103          fi
104        fi
105      fi
106      rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
107     ])
108   if test $gl_cv_header_wchar_h_correct_inline = no; then
109     AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
110 This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
111 C99 mode. You have four options:
112   - Add the flag -fgnu89-inline to CC and reconfigure, or
113   - Fix your include files, using parts of
114     <http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
115   - Use a gcc version older than 4.3, or
116   - Don't use the flags -std=c99 or -std=gnu99.
117 Configuration aborted.])
118   fi
119 ])
120
121 dnl Unconditionally enables the replacement of <wchar.h>.
122 AC_DEFUN([gl_REPLACE_WCHAR_H],
123 [
124   dnl This is a no-op, because <wchar.h> is always overridden.
125   :
126 ])
127
128 AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
129 [
130   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
131   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
132   gl_MODULE_INDICATOR_SET_VARIABLE([$1])
133   dnl Define it also as a C macro, for the benefit of the unit tests.
134   gl_MODULE_INDICATOR_FOR_TESTS([$1])
135 ])
136
137 AC_DEFUN([gl_WCHAR_H_DEFAULTS],
138 [
139   GNULIB_BTOWC=0;       AC_SUBST([GNULIB_BTOWC])
140   GNULIB_WCTOB=0;       AC_SUBST([GNULIB_WCTOB])
141   GNULIB_MBSINIT=0;     AC_SUBST([GNULIB_MBSINIT])
142   GNULIB_MBRTOWC=0;     AC_SUBST([GNULIB_MBRTOWC])
143   GNULIB_MBRLEN=0;      AC_SUBST([GNULIB_MBRLEN])
144   GNULIB_MBSRTOWCS=0;   AC_SUBST([GNULIB_MBSRTOWCS])
145   GNULIB_MBSNRTOWCS=0;  AC_SUBST([GNULIB_MBSNRTOWCS])
146   GNULIB_WCRTOMB=0;     AC_SUBST([GNULIB_WCRTOMB])
147   GNULIB_WCSRTOMBS=0;   AC_SUBST([GNULIB_WCSRTOMBS])
148   GNULIB_WCSNRTOMBS=0;  AC_SUBST([GNULIB_WCSNRTOMBS])
149   GNULIB_WCWIDTH=0;     AC_SUBST([GNULIB_WCWIDTH])
150   GNULIB_WMEMCHR=0;     AC_SUBST([GNULIB_WMEMCHR])
151   GNULIB_WMEMCMP=0;     AC_SUBST([GNULIB_WMEMCMP])
152   GNULIB_WMEMCPY=0;     AC_SUBST([GNULIB_WMEMCPY])
153   GNULIB_WMEMMOVE=0;    AC_SUBST([GNULIB_WMEMMOVE])
154   GNULIB_WMEMSET=0;     AC_SUBST([GNULIB_WMEMSET])
155   GNULIB_WCSLEN=0;      AC_SUBST([GNULIB_WCSLEN])
156   GNULIB_WCSNLEN=0;     AC_SUBST([GNULIB_WCSNLEN])
157   GNULIB_WCSCPY=0;      AC_SUBST([GNULIB_WCSCPY])
158   GNULIB_WCPCPY=0;      AC_SUBST([GNULIB_WCPCPY])
159   GNULIB_WCSNCPY=0;     AC_SUBST([GNULIB_WCSNCPY])
160   GNULIB_WCPNCPY=0;     AC_SUBST([GNULIB_WCPNCPY])
161   GNULIB_WCSCAT=0;      AC_SUBST([GNULIB_WCSCAT])
162   GNULIB_WCSNCAT=0;     AC_SUBST([GNULIB_WCSNCAT])
163   GNULIB_WCSCMP=0;      AC_SUBST([GNULIB_WCSCMP])
164   GNULIB_WCSNCMP=0;     AC_SUBST([GNULIB_WCSNCMP])
165   GNULIB_WCSCASECMP=0;  AC_SUBST([GNULIB_WCSCASECMP])
166   GNULIB_WCSNCASECMP=0; AC_SUBST([GNULIB_WCSNCASECMP])
167   GNULIB_WCSCOLL=0;     AC_SUBST([GNULIB_WCSCOLL])
168   GNULIB_WCSXFRM=0;     AC_SUBST([GNULIB_WCSXFRM])
169   GNULIB_WCSDUP=0;      AC_SUBST([GNULIB_WCSDUP])
170   dnl Assume proper GNU behavior unless another module says otherwise.
171   HAVE_BTOWC=1;         AC_SUBST([HAVE_BTOWC])
172   HAVE_MBSINIT=1;       AC_SUBST([HAVE_MBSINIT])
173   HAVE_MBRTOWC=1;       AC_SUBST([HAVE_MBRTOWC])
174   HAVE_MBRLEN=1;        AC_SUBST([HAVE_MBRLEN])
175   HAVE_MBSRTOWCS=1;     AC_SUBST([HAVE_MBSRTOWCS])
176   HAVE_MBSNRTOWCS=1;    AC_SUBST([HAVE_MBSNRTOWCS])
177   HAVE_WCRTOMB=1;       AC_SUBST([HAVE_WCRTOMB])
178   HAVE_WCSRTOMBS=1;     AC_SUBST([HAVE_WCSRTOMBS])
179   HAVE_WCSNRTOMBS=1;    AC_SUBST([HAVE_WCSNRTOMBS])
180   HAVE_WMEMCHR=1;       AC_SUBST([HAVE_WMEMCHR])
181   HAVE_WMEMCMP=1;       AC_SUBST([HAVE_WMEMCMP])
182   HAVE_WMEMCPY=1;       AC_SUBST([HAVE_WMEMCPY])
183   HAVE_WMEMMOVE=1;      AC_SUBST([HAVE_WMEMMOVE])
184   HAVE_WMEMSET=1;       AC_SUBST([HAVE_WMEMSET])
185   HAVE_WCSLEN=1;        AC_SUBST([HAVE_WCSLEN])
186   HAVE_WCSNLEN=1;       AC_SUBST([HAVE_WCSNLEN])
187   HAVE_WCSCPY=1;        AC_SUBST([HAVE_WCSCPY])
188   HAVE_WCPCPY=1;        AC_SUBST([HAVE_WCPCPY])
189   HAVE_WCSNCPY=1;       AC_SUBST([HAVE_WCSNCPY])
190   HAVE_WCPNCPY=1;       AC_SUBST([HAVE_WCPNCPY])
191   HAVE_WCSCAT=1;        AC_SUBST([HAVE_WCSCAT])
192   HAVE_WCSNCAT=1;       AC_SUBST([HAVE_WCSNCAT])
193   HAVE_WCSCMP=1;        AC_SUBST([HAVE_WCSCMP])
194   HAVE_WCSNCMP=1;       AC_SUBST([HAVE_WCSNCMP])
195   HAVE_WCSCASECMP=1;    AC_SUBST([HAVE_WCSCASECMP])
196   HAVE_WCSNCASECMP=1;   AC_SUBST([HAVE_WCSNCASECMP])
197   HAVE_WCSCOLL=1;       AC_SUBST([HAVE_WCSCOLL])
198   HAVE_WCSXFRM=1;       AC_SUBST([HAVE_WCSXFRM])
199   HAVE_WCSDUP=1;        AC_SUBST([HAVE_WCSDUP])
200   HAVE_DECL_WCTOB=1;    AC_SUBST([HAVE_DECL_WCTOB])
201   HAVE_DECL_WCWIDTH=1;  AC_SUBST([HAVE_DECL_WCWIDTH])
202   REPLACE_MBSTATE_T=0;  AC_SUBST([REPLACE_MBSTATE_T])
203   REPLACE_BTOWC=0;      AC_SUBST([REPLACE_BTOWC])
204   REPLACE_WCTOB=0;      AC_SUBST([REPLACE_WCTOB])
205   REPLACE_MBSINIT=0;    AC_SUBST([REPLACE_MBSINIT])
206   REPLACE_MBRTOWC=0;    AC_SUBST([REPLACE_MBRTOWC])
207   REPLACE_MBRLEN=0;     AC_SUBST([REPLACE_MBRLEN])
208   REPLACE_MBSRTOWCS=0;  AC_SUBST([REPLACE_MBSRTOWCS])
209   REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
210   REPLACE_WCRTOMB=0;    AC_SUBST([REPLACE_WCRTOMB])
211   REPLACE_WCSRTOMBS=0;  AC_SUBST([REPLACE_WCSRTOMBS])
212   REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
213   REPLACE_WCWIDTH=0;    AC_SUBST([REPLACE_WCWIDTH])
214 ])