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