File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / libiconv / srcm4 / intl-thread-locale.m4
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Mar 17 13:38:46 2021 UTC (3 years, 9 months ago) by misho
Branches: libiconv, MAIN
CVS tags: v1_16p0, HEAD
libiconv 1.16

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>