Debian Codegraph @

m4/uchar_h.m4

raw
1 # uchar_h.m4
2 # serial 31
3 dnl Copyright (C) 2019-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 From Bruno Haible.
10 dnl Prepare the overridden <uchar.h>.
11
12 AC_DEFUN_ONCE([gl_UCHAR_H],
13 [
14 AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
15
16 gl_CHECK_NEXT_HEADERS([uchar.h])
17 if test $ac_cv_header_uchar_h = yes; then
18 HAVE_UCHAR_H=1
19 else
20 HAVE_UCHAR_H=0
21 fi
22 AC_SUBST([HAVE_UCHAR_H])
23
24 gl_TYPE_CHAR8_T
25 gl_TYPE_CHAR16_T
26 gl_TYPE_CHAR32_T
27
28 dnl In C++ mode, clang defines 'char16_t' and 'char32_t' as built-in types
29 dnl on some platforms (e.g. OpenBSD 6.7), and as types defined by many
30 dnl header files (<limits.h>, <stddef.h>, <stdint.h>, <stdio.h>, <stdlib.h>
31 dnl and others) on some platforms (e.g. Mac OS X 10.13).
32 dnl The same thing may also happen for 'char8_t'; so, be prepared for it.
33 m4_ifdef([gl_ANSI_CXX], [AC_REQUIRE([gl_ANSI_CXX])])
34 CXX_HAS_UCHAR_TYPES=0
35 if test $HAVE_UCHAR_H = 0; then
36 if test "$CXX" != no; then
37 AC_CACHE_CHECK([whether the C++ compiler predefines the <uchar.h> types],
38 [gl_cv_cxx_has_uchar_types],
39 [dnl We can't use AC_LANG_PUSH([C++]) and AC_LANG_POP([C++]) here, due to
40 dnl an autoconf bug <https://savannah.gnu.org/support/?110294>.
41 cat > conftest.cpp <<\EOF
42 #include <stddef.h>
43 char16_t a;
44 char32_t b;
45 EOF
46 gl_command="$CXX $CXXFLAGS $CPPFLAGS -c conftest.cpp"
47 if AC_TRY_EVAL([gl_command]); then
48 gl_cv_cxx_has_uchar_types=yes
49 else
50 gl_cv_cxx_has_uchar_types=no
51 fi
52 rm -fr conftest*
53 ])
54 if test $gl_cv_cxx_has_uchar_types = yes; then
55 CXX_HAS_UCHAR_TYPES=1
56 fi
57 fi
58 fi
59 AC_SUBST([CXX_HAS_UCHAR_TYPES])
60 CXX_HAS_CHAR8_TYPE=0
61 if test $HAVE_UCHAR_H = 0; then
62 if test "$CXX" != no; then
63 AC_CACHE_CHECK([whether the C++ compiler predefines the char8_t types],
64 [gl_cv_cxx_has_char8_type],
65 [dnl We can't use AC_LANG_PUSH([C++]) and AC_LANG_POP([C++]) here, due to
66 dnl an autoconf bug <https://savannah.gnu.org/support/?110294>.
67 cat > conftest.cpp <<\EOF
68 #include <stddef.h>
69 char8_t a;
70 EOF
71 gl_command="$CXX $CXXFLAGS $CPPFLAGS -c conftest.cpp"
72 if AC_TRY_EVAL([gl_command]); then
73 gl_cv_cxx_has_char8_type=yes
74 else
75 gl_cv_cxx_has_char8_type=no
76 fi
77 rm -fr conftest*
78 ])
79 if test $gl_cv_cxx_has_char8_type = yes; then
80 CXX_HAS_CHAR8_TYPE=1
81 fi
82 fi
83 fi
84 AC_SUBST([CXX_HAS_CHAR8_TYPE])
85
86 dnl Test whether a 'char32_t' can hold more characters than a 'wchar_t'.
87 gl_STDINT_BITSIZEOF([wchar_t], [gl_STDINT_INCLUDES])
88 if test $BITSIZEOF_WCHAR_T -lt 32; then
89 SMALL_WCHAR_T=1
90 else
91 SMALL_WCHAR_T=0
92 fi
93 dnl SMALL_WCHAR_T is expected to be 1 on 32-bit AIX, Cygwin, native Windows.
94 AC_SUBST([SMALL_WCHAR_T])
95
96 dnl Check for declarations of anything we want to poison if the
97 dnl corresponding gnulib module is not in use, and which is not
98 dnl guaranteed by C11.
99 gl_WARN_ON_USE_PREPARE([[
100 #ifdef __HAIKU__
101 #include <stdint.h>
102 #endif
103 #include <uchar.h>
104 ]], [c32rtomb mbrtoc16 mbrtoc32])
105 ])
106
107 AC_DEFUN_ONCE([gl_TYPE_CHAR8_T],
108 [
109 dnl Determine whether gnulib's <uchar.h> would, if present, override char8_t.
110 AC_CACHE_CHECK([whether char8_t is correctly defined],
111 [gl_cv_type_char8_t_works],
112 [AC_COMPILE_IFELSE(
113 [AC_LANG_PROGRAM([[
114 #ifdef __HAIKU__
115 #include <stdint.h>
116 #endif
117 #include <uchar.h>
118 int verify[(char8_t)(-1) >= 0 && sizeof (char8_t) == sizeof (unsigned char) ? 1 : -1];
119 ]])
120 ],
121 [gl_cv_type_char8_t_works=yes],
122 [gl_cv_type_char8_t_works=no])
123 ])
124 if test $gl_cv_type_char8_t_works = no; then
125 GNULIBHEADERS_OVERRIDE_CHAR8_T=1
126 else
127 GNULIBHEADERS_OVERRIDE_CHAR8_T=0
128 fi
129 AC_SUBST([GNULIBHEADERS_OVERRIDE_CHAR8_T])
130 ])
131
132 dnl On Haiku 2020, char16_t and char32_t are incorrectly defined.
133 dnl See <https://dev.haiku-os.org/ticket/15990>.
134 AC_DEFUN_ONCE([gl_TYPE_CHAR16_T],
135 [
136 dnl Determine whether gnulib's <uchar.h> would, if present, override char16_t.
137 AC_CACHE_CHECK([whether char16_t is correctly defined],
138 [gl_cv_type_char16_t_works],
139 [AC_COMPILE_IFELSE(
140 [AC_LANG_PROGRAM([[
141 #ifdef __HAIKU__
142 #include <stdint.h>
143 #endif
144 #include <uchar.h>
145 /* For simplicity, assume that uint16_least_t is equivalent to
146 'unsigned short'. */
147 int verify[(char16_t)(-1) >= 0 && sizeof (char16_t) == sizeof (unsigned short) ? 1 : -1];
148 ]])
149 ],
150 [gl_cv_type_char16_t_works=yes],
151 [gl_cv_type_char16_t_works=no])
152 ])
153 if test $gl_cv_type_char16_t_works = no; then
154 GNULIBHEADERS_OVERRIDE_CHAR16_T=1
155 else
156 GNULIBHEADERS_OVERRIDE_CHAR16_T=0
157 fi
158 AC_SUBST([GNULIBHEADERS_OVERRIDE_CHAR16_T])
159 ])
160 AC_DEFUN_ONCE([gl_TYPE_CHAR32_T],
161 [
162 dnl Determine whether gnulib's <uchar.h> would, if present, override char32_t.
163 AC_CACHE_CHECK([whether char32_t is correctly defined],
164 [gl_cv_type_char32_t_works],
165 [AC_COMPILE_IFELSE(
166 [AC_LANG_PROGRAM([[
167 #ifdef __HAIKU__
168 #include <stdint.h>
169 #endif
170 #include <uchar.h>
171 /* For simplicity, assume that uint32_least_t is equivalent to
172 'unsigned int'. */
173 int verify[(char32_t)(-1) >= 0 && sizeof (char32_t) == sizeof (unsigned int) ? 1 : -1];
174 ]])
175 ],
176 [gl_cv_type_char32_t_works=yes],
177 [gl_cv_type_char32_t_works=no])
178 ])
179 if test $gl_cv_type_char32_t_works = no; then
180 GNULIBHEADERS_OVERRIDE_CHAR32_T=1
181 else
182 GNULIBHEADERS_OVERRIDE_CHAR32_T=0
183 fi
184 AC_SUBST([GNULIBHEADERS_OVERRIDE_CHAR32_T])
185 ])
186
187 # gl_UCHAR_MODULE_INDICATOR([modulename])
188 # sets the shell variable that indicates the presence of the given module
189 # to a C preprocessor expression that will evaluate to 1.
190 # This macro invocation must not occur in macros that are AC_REQUIREd.
191 AC_DEFUN([gl_UCHAR_MODULE_INDICATOR],
192 [
193 dnl Ensure to expand the default settings once only.
194 gl_UCHAR_H_REQUIRE_DEFAULTS
195 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
196 dnl Define it also as a C macro, for the benefit of the unit tests.
197 gl_MODULE_INDICATOR_FOR_TESTS([$1])
198 ])
199
200 # Initializes the default values for AC_SUBSTed shell variables.
201 # This macro must not be AC_REQUIREd. It must only be invoked, and only
202 # outside of macros or in macros that are not AC_REQUIREd.
203 AC_DEFUN([gl_UCHAR_H_REQUIRE_DEFAULTS],
204 [
205 m4_defun(GL_MODULE_INDICATOR_PREFIX[_UCHAR_H_MODULE_INDICATOR_DEFAULTS], [
206 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_BTOC32])
207 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32ISALNUM])
208 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32ISALPHA])
209 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32ISBLANK])
210 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32ISCNTRL])
211 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32ISDIGIT])
212 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32ISGRAPH])
213 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32ISLOWER])
214 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32ISPRINT])
215 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32ISPUNCT])
216 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32ISSPACE])
217 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32ISUPPER])
218 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32ISXDIGIT])
219 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32TOLOWER])
220 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32TOUPPER])
221 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32WIDTH])
222 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32RTOMB])
223 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32SNRTOMBS])
224 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32SRTOMBS])
225 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32STOMBS])
226 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32SWIDTH])
227 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32TOB])
228 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32_APPLY_MAPPING])
229 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32_APPLY_TYPE_TEST])
230 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32_GET_MAPPING])
231 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_C32_GET_TYPE_TEST])
232 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBRTOC16])
233 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBRTOC32])
234 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSNRTOC32S])
235 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSRTOC32S])
236 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSTOC32S])
237 ])
238 m4_require(GL_MODULE_INDICATOR_PREFIX[_UCHAR_H_MODULE_INDICATOR_DEFAULTS])
239 AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
240 ])
241
242 AC_DEFUN([gl_UCHAR_H_DEFAULTS],
243 [
244 dnl Assume proper GNU behavior unless another module says otherwise.
245 HAVE_C32RTOMB=1; AC_SUBST([HAVE_C32RTOMB])
246 HAVE_MBRTOC16=1; AC_SUBST([HAVE_MBRTOC16])
247 HAVE_MBRTOC32=1; AC_SUBST([HAVE_MBRTOC32])
248 REPLACE_C32RTOMB=0; AC_SUBST([REPLACE_C32RTOMB])
249 REPLACE_MBRTOC16=0; AC_SUBST([REPLACE_MBRTOC16])
250 REPLACE_MBRTOC32=0; AC_SUBST([REPLACE_MBRTOC32])
251 ])