1 dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
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.
8 dnl Written by Eric Blake.
10 # wchar_h.m4 serial 38
12 AC_DEFUN([gl_WCHAR_H],
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
26 AC_SUBST([HAVE_WCHAR_H])
28 AC_REQUIRE([gl_FEATURES_H])
30 AC_REQUIRE([gt_TYPE_WINT_T])
31 if test $gt_cv_c_wint_t = yes; then
36 AC_SUBST([HAVE_WINT_T])
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
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__)
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
58 dnl Check whether <wchar.h> is usable at all.
59 AC_DEFUN([gl_WCHAR_H_INLINE_OK],
61 dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
62 dnl 'gnu_inline'. See <http://sourceware.org/bugzilla/show_bug.cgi?id=4022>
63 dnl and <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
64 dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
65 dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
66 AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
67 [gl_cv_header_wchar_h_correct_inline],
68 [gl_cv_header_wchar_h_correct_inline=yes
70 AC_LANG_SOURCE([[#define wcstod renamed_wcstod
71 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
73 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
74 included before <wchar.h>. */
79 extern int zero (void);
80 int main () { return zero(); }
82 if AC_TRY_EVAL([ac_compile]); then
83 mv conftest.$ac_objext conftest1.$ac_objext
85 AC_LANG_SOURCE([[#define wcstod renamed_wcstod
86 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
88 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
89 included before <wchar.h>. */
94 int zero (void) { return 0; }
96 if AC_TRY_EVAL([ac_compile]); then
97 mv conftest.$ac_objext conftest2.$ac_objext
98 if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
101 gl_cv_header_wchar_h_correct_inline=no
105 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
107 if test $gl_cv_header_wchar_h_correct_inline = no; then
108 AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
109 This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
110 C99 mode. You have four options:
111 - Add the flag -fgnu89-inline to CC and reconfigure, or
112 - Fix your include files, using parts of
113 <http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
114 - Use a gcc version older than 4.3, or
115 - Don't use the flags -std=c99 or -std=gnu99.
116 Configuration aborted.])
120 dnl Unconditionally enables the replacement of <wchar.h>.
121 AC_DEFUN([gl_REPLACE_WCHAR_H],
123 dnl This is a no-op, because <wchar.h> is always overridden.
127 AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
129 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
130 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
131 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
132 dnl Define it also as a C macro, for the benefit of the unit tests.
133 gl_MODULE_INDICATOR_FOR_TESTS([$1])
136 AC_DEFUN([gl_WCHAR_H_DEFAULTS],
138 GNULIB_BTOWC=0; AC_SUBST([GNULIB_BTOWC])
139 GNULIB_WCTOB=0; AC_SUBST([GNULIB_WCTOB])
140 GNULIB_MBSINIT=0; AC_SUBST([GNULIB_MBSINIT])
141 GNULIB_MBRTOWC=0; AC_SUBST([GNULIB_MBRTOWC])
142 GNULIB_MBRLEN=0; AC_SUBST([GNULIB_MBRLEN])
143 GNULIB_MBSRTOWCS=0; AC_SUBST([GNULIB_MBSRTOWCS])
144 GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
145 GNULIB_WCRTOMB=0; AC_SUBST([GNULIB_WCRTOMB])
146 GNULIB_WCSRTOMBS=0; AC_SUBST([GNULIB_WCSRTOMBS])
147 GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
148 GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH])
149 GNULIB_WMEMCHR=0; AC_SUBST([GNULIB_WMEMCHR])
150 GNULIB_WMEMCMP=0; AC_SUBST([GNULIB_WMEMCMP])
151 GNULIB_WMEMCPY=0; AC_SUBST([GNULIB_WMEMCPY])
152 GNULIB_WMEMMOVE=0; AC_SUBST([GNULIB_WMEMMOVE])
153 GNULIB_WMEMSET=0; AC_SUBST([GNULIB_WMEMSET])
154 GNULIB_WCSLEN=0; AC_SUBST([GNULIB_WCSLEN])
155 GNULIB_WCSNLEN=0; AC_SUBST([GNULIB_WCSNLEN])
156 GNULIB_WCSCPY=0; AC_SUBST([GNULIB_WCSCPY])
157 GNULIB_WCPCPY=0; AC_SUBST([GNULIB_WCPCPY])
158 GNULIB_WCSNCPY=0; AC_SUBST([GNULIB_WCSNCPY])
159 GNULIB_WCPNCPY=0; AC_SUBST([GNULIB_WCPNCPY])
160 GNULIB_WCSCAT=0; AC_SUBST([GNULIB_WCSCAT])
161 GNULIB_WCSNCAT=0; AC_SUBST([GNULIB_WCSNCAT])
162 GNULIB_WCSCMP=0; AC_SUBST([GNULIB_WCSCMP])
163 dnl Assume proper GNU behavior unless another module says otherwise.
164 HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC])
165 HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT])
166 HAVE_MBRTOWC=1; AC_SUBST([HAVE_MBRTOWC])
167 HAVE_MBRLEN=1; AC_SUBST([HAVE_MBRLEN])
168 HAVE_MBSRTOWCS=1; AC_SUBST([HAVE_MBSRTOWCS])
169 HAVE_MBSNRTOWCS=1; AC_SUBST([HAVE_MBSNRTOWCS])
170 HAVE_WCRTOMB=1; AC_SUBST([HAVE_WCRTOMB])
171 HAVE_WCSRTOMBS=1; AC_SUBST([HAVE_WCSRTOMBS])
172 HAVE_WCSNRTOMBS=1; AC_SUBST([HAVE_WCSNRTOMBS])
173 HAVE_WMEMCHR=1; AC_SUBST([HAVE_WMEMCHR])
174 HAVE_WMEMCMP=1; AC_SUBST([HAVE_WMEMCMP])
175 HAVE_WMEMCPY=1; AC_SUBST([HAVE_WMEMCPY])
176 HAVE_WMEMMOVE=1; AC_SUBST([HAVE_WMEMMOVE])
177 HAVE_WMEMSET=1; AC_SUBST([HAVE_WMEMSET])
178 HAVE_WCSLEN=1; AC_SUBST([HAVE_WCSLEN])
179 HAVE_WCSNLEN=1; AC_SUBST([HAVE_WCSNLEN])
180 HAVE_WCSCPY=1; AC_SUBST([HAVE_WCSCPY])
181 HAVE_WCPCPY=1; AC_SUBST([HAVE_WCPCPY])
182 HAVE_WCSNCPY=1; AC_SUBST([HAVE_WCSNCPY])
183 HAVE_WCPNCPY=1; AC_SUBST([HAVE_WCPNCPY])
184 HAVE_WCSCAT=1; AC_SUBST([HAVE_WCSCAT])
185 HAVE_WCSNCAT=1; AC_SUBST([HAVE_WCSNCAT])
186 HAVE_WCSCMP=1; AC_SUBST([HAVE_WCSCMP])
187 HAVE_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB])
188 HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH])
189 REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T])
190 REPLACE_BTOWC=0; AC_SUBST([REPLACE_BTOWC])
191 REPLACE_WCTOB=0; AC_SUBST([REPLACE_WCTOB])
192 REPLACE_MBSINIT=0; AC_SUBST([REPLACE_MBSINIT])
193 REPLACE_MBRTOWC=0; AC_SUBST([REPLACE_MBRTOWC])
194 REPLACE_MBRLEN=0; AC_SUBST([REPLACE_MBRLEN])
195 REPLACE_MBSRTOWCS=0; AC_SUBST([REPLACE_MBSRTOWCS])
196 REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
197 REPLACE_WCRTOMB=0; AC_SUBST([REPLACE_WCRTOMB])
198 REPLACE_WCSRTOMBS=0; AC_SUBST([REPLACE_WCSRTOMBS])
199 REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
200 REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH])