| 1 |
# intl-thread-locale.m4 |
| 2 |
# serial 15 |
| 3 |
dnl Copyright (C) 2015-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 |
dnl |
| 9 |
dnl This file can be used in projects which are not available under |
| 10 |
dnl the GNU General Public License or the GNU Lesser General Public |
| 11 |
dnl License but which still want to provide support for the GNU gettext |
| 12 |
dnl functionality. |
| 13 |
dnl Please note that the actual code of the GNU gettext library is covered |
| 14 |
dnl by the GNU Lesser General Public License, and the rest of the GNU |
| 15 |
dnl gettext package is covered by the GNU General Public License. |
| 16 |
dnl They are *not* in the public domain. |
| 17 |
|
| 18 |
dnl Check how to retrieve the name of a per-thread locale (POSIX locale_t). |
| 19 |
dnl Sets gt_nameless_locales. |
| 20 |
AC_DEFUN([gt_INTL_THREAD_LOCALE_NAME], |
| 21 |
[ |
| 22 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 23 |
|
| 24 |
dnl Persuade Solaris <locale.h> to define 'locale_t'. |
| 25 |
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) |
| 26 |
|
| 27 |
dnl Test whether uselocale() exists and works at all. |
| 28 |
gt_FUNC_USELOCALE |
| 29 |
|
| 30 |
dnl On OpenBSD >= 6.2, the locale_t type and the uselocale(), newlocale(), |
| 31 |
dnl duplocale(), freelocale() functions exist but are effectively useless, |
| 32 |
dnl because the locale_t value depends only on the LC_CTYPE category of the |
| 33 |
dnl locale and furthermore contains only one bit of information (it |
| 34 |
dnl distinguishes the "C" locale from the *.UTF-8 locales). See |
| 35 |
dnl <https://cvsweb.openbsd.org/src/lib/libc/locale/newlocale.c?rev=1.1&content-type=text/x-cvsweb-markup>. |
| 36 |
dnl In the setlocale() implementation they have thought about the programs |
| 37 |
dnl that use the API ("Even though only LC_CTYPE has any effect in the |
| 38 |
dnl OpenBSD base system, store complete information about the global locale, |
| 39 |
dnl such that third-party software can access it"), but for uselocale() |
| 40 |
dnl they did not think about the programs. |
| 41 |
dnl In this situation, even the HAVE_NAMELESS_LOCALES support cannot make |
| 42 |
dnl uselocale() work. |
| 43 |
dnl Similarly on Android. See |
| 44 |
dnl <https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/bionic/locale.cpp>. |
| 45 |
dnl So, define HAVE_FAKE_LOCALES and disable all per-thread locale support. |
| 46 |
dnl Expected result: |
| 47 |
dnl - HAVE_FAKE_LOCALES is defined on OpenBSD ≥ 6.2, Android API level >= 21. |
| 48 |
case "$gt_cv_func_uselocale_works" in |
| 49 |
*yes) |
| 50 |
AC_CHECK_HEADERS_ONCE([xlocale.h]) |
| 51 |
AC_CACHE_CHECK([for fake locale system (OpenBSD, Android)], |
| 52 |
[gt_cv_locale_fake], |
| 53 |
[case "$host_os" in |
| 54 |
*-android*) gt_cv_locale_fake=yes ;; |
| 55 |
*) |
| 56 |
AC_RUN_IFELSE( |
| 57 |
[AC_LANG_SOURCE([[ |
| 58 |
#include <locale.h> |
| 59 |
#if HAVE_XLOCALE_H |
| 60 |
# include <xlocale.h> |
| 61 |
#endif |
| 62 |
int main () |
| 63 |
{ |
| 64 |
locale_t loc1, loc2; |
| 65 |
if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL) return 1; |
| 66 |
if (setlocale (LC_ALL, "fr_FR.UTF-8") == NULL) return 1; |
| 67 |
loc1 = newlocale (LC_ALL_MASK, "de_DE.UTF-8", (locale_t)0); |
| 68 |
loc2 = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", (locale_t)0); |
| 69 |
return !(loc1 == loc2); |
| 70 |
}]])], |
| 71 |
[gt_cv_locale_fake=yes], |
| 72 |
[gt_cv_locale_fake=no], |
| 73 |
[dnl Guess the locale system is fake only on OpenBSD. |
| 74 |
case "$host_os" in |
| 75 |
openbsd*) gt_cv_locale_fake="guessing yes" ;; |
| 76 |
*) gt_cv_locale_fake="guessing no" ;; |
| 77 |
esac |
| 78 |
]) |
| 79 |
;; |
| 80 |
esac |
| 81 |
]) |
| 82 |
;; |
| 83 |
*) gt_cv_locale_fake=no ;; |
| 84 |
esac |
| 85 |
case "$gt_cv_locale_fake" in |
| 86 |
*yes) |
| 87 |
gt_fake_locales=yes |
| 88 |
AC_DEFINE([HAVE_FAKE_LOCALES], [1], |
| 89 |
[Define if the locale_t type contains insufficient information, as on OpenBSD.]) |
| 90 |
;; |
| 91 |
*) |
| 92 |
gt_fake_locales=no |
| 93 |
;; |
| 94 |
esac |
| 95 |
|
| 96 |
dnl Expected result: HAVE_SOLARIS114_LOCALES is defined on Solaris ≥ 11.4. |
| 97 |
case "$gt_cv_func_uselocale_works" in |
| 98 |
*yes) |
| 99 |
AC_CACHE_CHECK([for Solaris 11.4 locale system], |
| 100 |
[gt_cv_locale_solaris114], |
| 101 |
[case "$host_os" in |
| 102 |
solaris*) |
| 103 |
dnl Test whether <locale.h> defines locale_t as a typedef of |
| 104 |
dnl 'struct _LC_locale_t **' (whereas Illumos defines it as a |
| 105 |
dnl typedef of 'struct _locale *'). |
| 106 |
dnl Another possible test would be to include <sys/localedef.h> |
| 107 |
dnl and test whether it defines the _LC_core_data_locale_t type. |
| 108 |
dnl This type was added in Solaris 11.4. |
| 109 |
AC_COMPILE_IFELSE( |
| 110 |
[AC_LANG_PROGRAM([[ |
| 111 |
#include <locale.h> |
| 112 |
struct _LC_locale_t *x; |
| 113 |
locale_t y; |
| 114 |
]], |
| 115 |
[[*y = x;]])], |
| 116 |
[gt_cv_locale_solaris114=yes], |
| 117 |
[gt_cv_locale_solaris114=no]) |
| 118 |
;; |
| 119 |
*) gt_cv_locale_solaris114=no ;; |
| 120 |
esac |
| 121 |
]) |
| 122 |
;; |
| 123 |
*) gt_cv_locale_solaris114=no ;; |
| 124 |
esac |
| 125 |
if test $gt_cv_locale_solaris114 = yes; then |
| 126 |
AC_DEFINE([HAVE_SOLARIS114_LOCALES], [1], |
| 127 |
[Define if the locale_t type is as on Solaris 11.4.]) |
| 128 |
fi |
| 129 |
|
| 130 |
dnl This code is for platforms where the locale_t type does not provide access |
| 131 |
dnl to the name of each locale category. This code has the drawback that it |
| 132 |
dnl requires the gnulib overrides of 'newlocale', 'duplocale', 'freelocale', |
| 133 |
dnl which is a problem for GNU libunistring. Therefore try hard to avoid |
| 134 |
dnl enabling this code! |
| 135 |
dnl Expected result: |
| 136 |
dnl - HAVE_NAMELESS_LOCALES is defined on OpenBSD ≥ 6.2, AIX, |
| 137 |
dnl Android API level >= 21, |
| 138 |
dnl - HAVE_AIX72_LOCALES is defined on AIX ≥ 7.2. |
| 139 |
gt_nameless_locales=$gt_fake_locales |
| 140 |
case "$host_os" in |
| 141 |
dnl It's needed on AIX 7.2. |
| 142 |
aix*) |
| 143 |
gt_nameless_locales=yes |
| 144 |
dnl In AIX ≥ 7.2, a locale contains at least the name of the LC_MESSAGES |
| 145 |
dnl category (fix of defect 823926). |
| 146 |
AC_CACHE_CHECK([for AIX locales with LC_MESSAGES name], |
| 147 |
[gt_cv_locale_aix72], |
| 148 |
[AC_COMPILE_IFELSE( |
| 149 |
[AC_LANG_PROGRAM([[ |
| 150 |
#include <locale.h> |
| 151 |
/* Include <sys/localedef.h>, which defines __locale_t. */ |
| 152 |
#include <stdlib.h> |
| 153 |
locale_t x; |
| 154 |
]], |
| 155 |
[[return ((__locale_t) x)->locale_name[0];]])], |
| 156 |
[gt_cv_locale_aix72=yes], |
| 157 |
[gt_cv_locale_aix72=no]) |
| 158 |
]) |
| 159 |
if test $gt_cv_locale_aix72 = yes; then |
| 160 |
AC_DEFINE([HAVE_AIX72_LOCALES], [1], |
| 161 |
[Define if the __locale_t type contains the name of the LC_MESSAGES category.]) |
| 162 |
fi |
| 163 |
;; |
| 164 |
esac |
| 165 |
if test $gt_nameless_locales = yes; then |
| 166 |
AC_DEFINE([HAVE_NAMELESS_LOCALES], [1], |
| 167 |
[Define if the locale_t type does not contain the name of each locale category.]) |
| 168 |
fi |
| 169 |
|
| 170 |
dnl We cannot support uselocale() on platforms where the locale_t type is |
| 171 |
dnl fake. So, set |
| 172 |
dnl gt_good_uselocale = gt_working_uselocale && !gt_fake_locales. |
| 173 |
dnl Expected result: HAVE_GOOD_USELOCALE is defined on all platforms except |
| 174 |
dnl FreeBSD < 9.1, NetBSD, OpenBSD, Minix, AIX < 7, AIX 7.2, HP-UX, IRIX, |
| 175 |
dnl Solaris < 11.4, Cygwin < 2.6, mingw, MSVC 14, Android. |
| 176 |
if test $gt_working_uselocale = yes && test $gt_fake_locales = no; then |
| 177 |
gt_good_uselocale=yes |
| 178 |
AC_DEFINE([HAVE_GOOD_USELOCALE], [1], |
| 179 |
[Define if the uselocale function exists, may be safely called, and returns sufficient information.]) |
| 180 |
else |
| 181 |
gt_good_uselocale=no |
| 182 |
fi |
| 183 |
|
| 184 |
dnl Set gt_localename_enhances_locale_funcs to indicate whether localename.c |
| 185 |
dnl overrides newlocale(), duplocale(), freelocale() to keep track of locale |
| 186 |
dnl names. |
| 187 |
dnl Expected result: LOCALENAME_ENHANCE_LOCALE_FUNCS is defined on |
| 188 |
dnl OpenBSD ≥ 6.2, AIX 7.1, AIX ≥ 7.3, Android API level >= 21. |
| 189 |
if test $gt_working_uselocale = yes && test $gt_nameless_locales = yes; then |
| 190 |
gt_localename_enhances_locale_funcs=yes |
| 191 |
LOCALENAME_ENHANCE_LOCALE_FUNCS=1 |
| 192 |
AC_DEFINE([LOCALENAME_ENHANCE_LOCALE_FUNCS], [1], |
| 193 |
[Define if localename.c overrides newlocale(), duplocale(), freelocale().]) |
| 194 |
else |
| 195 |
gt_localename_enhances_locale_funcs=no |
| 196 |
fi |
| 197 |
]) |
| 198 |
|
| 199 |
dnl Tests whether uselocale() exists and is usable. |
| 200 |
dnl Sets gt_working_uselocale and defines HAVE_WORKING_USELOCALE. |
| 201 |
dnl Expected result: HAVE_WORKING_USELOCALE is defined on all platforms except |
| 202 |
dnl FreeBSD < 9.1, NetBSD, OpenBSD < 6.2, Minix, AIX < 7, AIX 7.2, HP-UX, IRIX, |
| 203 |
dnl Solaris < 11.4, Cygwin < 2.6, mingw, MSVC 14, Android API level < 21. |
| 204 |
AC_DEFUN([gt_FUNC_USELOCALE], |
| 205 |
[ |
| 206 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 207 |
|
| 208 |
dnl Persuade glibc and Solaris <locale.h> to define 'locale_t'. |
| 209 |
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) |
| 210 |
|
| 211 |
gl_CHECK_FUNCS_ANDROID([uselocale], [[#include <locale.h>]]) |
| 212 |
|
| 213 |
dnl On AIX 7.2, the uselocale() function is not documented and leads to |
| 214 |
dnl crashes in subsequent setlocale() invocations. |
| 215 |
dnl In 2019, some versions of z/OS lack the locale_t type and have a broken |
| 216 |
dnl uselocale function. |
| 217 |
if test $ac_cv_func_uselocale = yes; then |
| 218 |
AC_CHECK_HEADERS_ONCE([xlocale.h]) |
| 219 |
AC_CACHE_CHECK([whether uselocale works], |
| 220 |
[gt_cv_func_uselocale_works], |
| 221 |
[AC_RUN_IFELSE( |
| 222 |
[AC_LANG_SOURCE([[ |
| 223 |
#include <locale.h> |
| 224 |
#if HAVE_XLOCALE_H |
| 225 |
# include <xlocale.h> |
| 226 |
#endif |
| 227 |
locale_t loc1; |
| 228 |
int main () |
| 229 |
{ |
| 230 |
uselocale (NULL); |
| 231 |
setlocale (LC_ALL, "en_US.UTF-8"); |
| 232 |
return 0; |
| 233 |
}]])], |
| 234 |
[gt_cv_func_uselocale_works=yes], |
| 235 |
[gt_cv_func_uselocale_works=no], |
| 236 |
[# Guess no on AIX and z/OS, yes otherwise. |
| 237 |
case "$host_os" in |
| 238 |
aix* | openedition*) gt_cv_func_uselocale_works="guessing no" ;; |
| 239 |
*) gt_cv_func_uselocale_works="guessing yes" ;; |
| 240 |
esac |
| 241 |
]) |
| 242 |
]) |
| 243 |
else |
| 244 |
gt_cv_func_uselocale_works=no |
| 245 |
fi |
| 246 |
case "$gt_cv_func_uselocale_works" in |
| 247 |
*yes) |
| 248 |
gt_working_uselocale=yes |
| 249 |
AC_DEFINE([HAVE_WORKING_USELOCALE], [1], |
| 250 |
[Define if the uselocale function exists and may safely be called.]) |
| 251 |
;; |
| 252 |
*) |
| 253 |
gt_working_uselocale=no |
| 254 |
;; |
| 255 |
esac |
| 256 |
]) |