Debian Codegraph @

m4/wchar_h.m4

raw
1 # wchar_h.m4
2 # serial 65
3 dnl Copyright (C) 2007-2024 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 dnl This file is offered as-is, without any warranty.
8
9 dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
10
11 dnl Written by Eric Blake.
12
13 AC_DEFUN_ONCE([gl_WCHAR_H],
14 [
15 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
16 AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
17 dnl Prepare for creating substitute <wchar.h>.
18 dnl Check for <wchar.h> (missing in Linux uClibc when built without wide
19 dnl character support).
20 dnl <wchar.h> is always overridden, because of GNULIB_POSIXCHECK.
21 gl_CHECK_NEXT_HEADERS([wchar.h])
22 if test $ac_cv_header_wchar_h = yes; then
23 HAVE_WCHAR_H=1
24 else
25 HAVE_WCHAR_H=0
26 fi
27 AC_SUBST([HAVE_WCHAR_H])
28
29 AC_REQUIRE([gl_FEATURES_H])
30
31 AC_REQUIRE([gt_TYPE_WINT_T])
32 if test $gt_cv_c_wint_t = yes; then
33 HAVE_WINT_T=1
34 else
35 HAVE_WINT_T=0
36 fi
37 AC_SUBST([HAVE_WINT_T])
38
39 AC_REQUIRE([gl_TYPE_WINT_T_PREREQ])
40
41 dnl Check for declarations of anything we want to poison if the
42 dnl corresponding gnulib module is not in use.
43 gl_WARN_ON_USE_PREPARE([[
44 #include <wchar.h>
45 ]],
46 [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb
47 wcsrtombs wcsnrtombs wcwidth
48 wmemchr wmemcmp wmemcpy wmemmove wmempcpy wmemset
49 wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp
50 wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr wcsrchr
51 wcscspn wcsspn wcspbrk wcsstr wcstok wcswidth wcsftime
52 ])
53
54 AC_REQUIRE([AC_C_RESTRICT])
55
56 AC_CHECK_DECLS([wcsdup], [], [], [[
57 #include <wchar.h>
58 ]])
59 if test $ac_cv_have_decl_wcsdup = no; then
60 HAVE_DECL_WCSDUP=0
61 fi
62 ])
63
64 dnl Check whether <wchar.h> is usable at all.
65 AC_DEFUN([gl_WCHAR_H_INLINE_OK],
66 [
67 dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
68 dnl 'gnu_inline'. See <https://sourceware.org/bugzilla/show_bug.cgi?id=4022>
69 dnl and <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
70 dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
71 dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
72 AC_REQUIRE([AC_CANONICAL_HOST])
73 AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
74 [gl_cv_header_wchar_h_correct_inline],
75 [gl_cv_header_wchar_h_correct_inline=yes
76 case "$host_os" in
77 *-gnu* | gnu*)
78 AC_LANG_CONFTEST([
79 AC_LANG_SOURCE([[
80 #define wcstod renamed_wcstod
81 #include <wchar.h>
82 extern int zero (void);
83 int main () { return zero(); }
84 ]])])
85 dnl Do not rename the object file from conftest.$ac_objext to
86 dnl conftest1.$ac_objext, as this will cause the link to fail on
87 dnl z/OS when using the XPLINK object format (due to duplicate
88 dnl CSECT names). Instead, temporarily redefine $ac_compile so
89 dnl that the object file has the latter name from the start.
90 saved_ac_compile="$ac_compile"
91 ac_compile=`echo "$saved_ac_compile" | sed s/conftest/conftest1/`
92 if echo '#include "conftest.c"' >conftest1.c \
93 && AC_TRY_EVAL([ac_compile]); then
94 AC_LANG_CONFTEST([
95 AC_LANG_SOURCE([[
96 #define wcstod renamed_wcstod
97 #include <wchar.h>
98 int zero (void) { return 0; }
99 ]])])
100 dnl See note above about renaming object files.
101 ac_compile=`echo "$saved_ac_compile" | sed s/conftest/conftest2/`
102 if echo '#include "conftest.c"' >conftest2.c \
103 && AC_TRY_EVAL([ac_compile]); then
104 if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
105 :
106 else
107 gl_cv_header_wchar_h_correct_inline=no
108 fi
109 fi
110 fi
111 ac_compile="$saved_ac_compile"
112 rm -f conftest[12].c conftest[12].$ac_objext conftest$ac_exeext
113 ;;
114 esac
115 ])
116 if test $gl_cv_header_wchar_h_correct_inline = no; then
117 AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
118 This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
119 C99 mode. You have four options:
120 - Add the flag -fgnu89-inline to CC and reconfigure, or
121 - Fix your include files, using parts of
122 <https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
123 - Use a gcc version older than 4.3, or
124 - Don't use the flags -std=c99 or -std=gnu99.
125 Configuration aborted.])
126 fi
127 ])
128
129 # gl_WCHAR_MODULE_INDICATOR([modulename])
130 # sets the shell variable that indicates the presence of the given module
131 # to a C preprocessor expression that will evaluate to 1.
132 # This macro invocation must not occur in macros that are AC_REQUIREd.
133 AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
134 [
135 dnl Ensure to expand the default settings once only.
136 gl_WCHAR_H_REQUIRE_DEFAULTS
137 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
138 dnl Define it also as a C macro, for the benefit of the unit tests.
139 gl_MODULE_INDICATOR_FOR_TESTS([$1])
140 ])
141
142 # Initializes the default values for AC_SUBSTed shell variables.
143 # This macro must not be AC_REQUIREd. It must only be invoked, and only
144 # outside of macros or in macros that are not AC_REQUIREd.
145 AC_DEFUN([gl_WCHAR_H_REQUIRE_DEFAULTS],
146 [
147 m4_defun(GL_MODULE_INDICATOR_PREFIX[_WCHAR_H_MODULE_INDICATOR_DEFAULTS], [
148 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_BTOWC])
149 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTOB])
150 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSINIT])
151 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSZERO])
152 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBRTOWC])
153 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBRLEN])
154 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSRTOWCS])
155 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSNRTOWCS])
156 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCRTOMB])
157 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSRTOMBS])
158 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNRTOMBS])
159 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCWIDTH])
160 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCHR])
161 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCMP])
162 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCPY])
163 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMMOVE])
164 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMPCPY])
165 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMSET])
166 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSLEN])
167 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNLEN])
168 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCPY])
169 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCPCPY])
170 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCPY])
171 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCPNCPY])
172 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCAT])
173 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCAT])
174 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCMP])
175 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCMP])
176 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCASECMP])
177 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCASECMP])
178 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCOLL])
179 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSXFRM])
180 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSDUP])
181 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCHR])
182 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSRCHR])
183 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCSPN])
184 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSSPN])
185 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSPBRK])
186 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSSTR])
187 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSTOK])
188 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSWIDTH])
189 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSFTIME])
190 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WGETCWD])
191 dnl Support Microsoft deprecated alias function names by default.
192 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_WCSDUP], [1])
193 ])
194 m4_require(GL_MODULE_INDICATOR_PREFIX[_WCHAR_H_MODULE_INDICATOR_DEFAULTS])
195 dnl Make sure the shell variable for GNULIB_FREE_POSIX is initialized.
196 gl_STDLIB_H_REQUIRE_DEFAULTS
197 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
198 ])
199
200 AC_DEFUN([gl_WCHAR_H_DEFAULTS],
201 [
202 dnl Assume proper GNU behavior unless another module says otherwise.
203 HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC])
204 HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT])
205 HAVE_MBRTOWC=1; AC_SUBST([HAVE_MBRTOWC])
206 HAVE_MBRLEN=1; AC_SUBST([HAVE_MBRLEN])
207 HAVE_MBSRTOWCS=1; AC_SUBST([HAVE_MBSRTOWCS])
208 HAVE_MBSNRTOWCS=1; AC_SUBST([HAVE_MBSNRTOWCS])
209 HAVE_WCRTOMB=1; AC_SUBST([HAVE_WCRTOMB])
210 HAVE_WCSRTOMBS=1; AC_SUBST([HAVE_WCSRTOMBS])
211 HAVE_WCSNRTOMBS=1; AC_SUBST([HAVE_WCSNRTOMBS])
212 HAVE_WMEMCHR=1; AC_SUBST([HAVE_WMEMCHR])
213 HAVE_WMEMCMP=1; AC_SUBST([HAVE_WMEMCMP])
214 HAVE_WMEMCPY=1; AC_SUBST([HAVE_WMEMCPY])
215 HAVE_WMEMMOVE=1; AC_SUBST([HAVE_WMEMMOVE])
216 HAVE_WMEMPCPY=1; AC_SUBST([HAVE_WMEMPCPY])
217 HAVE_WMEMSET=1; AC_SUBST([HAVE_WMEMSET])
218 HAVE_WCSLEN=1; AC_SUBST([HAVE_WCSLEN])
219 HAVE_WCSNLEN=1; AC_SUBST([HAVE_WCSNLEN])
220 HAVE_WCSCPY=1; AC_SUBST([HAVE_WCSCPY])
221 HAVE_WCPCPY=1; AC_SUBST([HAVE_WCPCPY])
222 HAVE_WCSNCPY=1; AC_SUBST([HAVE_WCSNCPY])
223 HAVE_WCPNCPY=1; AC_SUBST([HAVE_WCPNCPY])
224 HAVE_WCSCAT=1; AC_SUBST([HAVE_WCSCAT])
225 HAVE_WCSNCAT=1; AC_SUBST([HAVE_WCSNCAT])
226 HAVE_WCSCMP=1; AC_SUBST([HAVE_WCSCMP])
227 HAVE_WCSNCMP=1; AC_SUBST([HAVE_WCSNCMP])
228 HAVE_WCSCASECMP=1; AC_SUBST([HAVE_WCSCASECMP])
229 HAVE_WCSNCASECMP=1; AC_SUBST([HAVE_WCSNCASECMP])
230 HAVE_WCSCOLL=1; AC_SUBST([HAVE_WCSCOLL])
231 HAVE_WCSXFRM=1; AC_SUBST([HAVE_WCSXFRM])
232 HAVE_WCSDUP=1; AC_SUBST([HAVE_WCSDUP])
233 HAVE_WCSCHR=1; AC_SUBST([HAVE_WCSCHR])
234 HAVE_WCSRCHR=1; AC_SUBST([HAVE_WCSRCHR])
235 HAVE_WCSCSPN=1; AC_SUBST([HAVE_WCSCSPN])
236 HAVE_WCSSPN=1; AC_SUBST([HAVE_WCSSPN])
237 HAVE_WCSPBRK=1; AC_SUBST([HAVE_WCSPBRK])
238 HAVE_WCSSTR=1; AC_SUBST([HAVE_WCSSTR])
239 HAVE_WCSTOK=1; AC_SUBST([HAVE_WCSTOK])
240 HAVE_WCSWIDTH=1; AC_SUBST([HAVE_WCSWIDTH])
241 HAVE_WCSFTIME=1; AC_SUBST([HAVE_WCSFTIME])
242 HAVE_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB])
243 HAVE_DECL_WCSDUP=1; AC_SUBST([HAVE_DECL_WCSDUP])
244 HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH])
245 REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T])
246 REPLACE_BTOWC=0; AC_SUBST([REPLACE_BTOWC])
247 REPLACE_WCTOB=0; AC_SUBST([REPLACE_WCTOB])
248 REPLACE_MBSINIT=0; AC_SUBST([REPLACE_MBSINIT])
249 REPLACE_MBRTOWC=0; AC_SUBST([REPLACE_MBRTOWC])
250 REPLACE_MBRLEN=0; AC_SUBST([REPLACE_MBRLEN])
251 REPLACE_MBSRTOWCS=0; AC_SUBST([REPLACE_MBSRTOWCS])
252 REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
253 REPLACE_WCRTOMB=0; AC_SUBST([REPLACE_WCRTOMB])
254 REPLACE_WCSRTOMBS=0; AC_SUBST([REPLACE_WCSRTOMBS])
255 REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
256 REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH])
257 REPLACE_WCSWIDTH=0; AC_SUBST([REPLACE_WCSWIDTH])
258 REPLACE_WCSFTIME=0; AC_SUBST([REPLACE_WCSFTIME])
259 REPLACE_WCSCMP=0; AC_SUBST([REPLACE_WCSCMP])
260 REPLACE_WCSNCAT=0; AC_SUBST([REPLACE_WCSNCAT])
261 REPLACE_WCSNCMP=0; AC_SUBST([REPLACE_WCSNCMP])
262 REPLACE_WCSSTR=0; AC_SUBST([REPLACE_WCSSTR])
263 REPLACE_WCSTOK=0; AC_SUBST([REPLACE_WCSTOK])
264 REPLACE_WMEMCMP=0; AC_SUBST([REPLACE_WMEMCMP])
265 REPLACE_WMEMPCPY=0; AC_SUBST([REPLACE_WMEMPCPY])
266 ])