intl-thread-locale.m4 7.9 KB

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