Debian Codegraph @

m4/uchar_h.m4

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