Blame m4/intl-thread-locale.m4

Packit Service 991b93
# intl-thread-locale.m4 serial 8
Packit Service 991b93
dnl Copyright (C) 2015-2020 Free Software Foundation, Inc.
Packit aea12f
dnl This file is free software; the Free Software Foundation
Packit aea12f
dnl gives unlimited permission to copy and/or distribute it,
Packit aea12f
dnl with or without modifications, as long as this notice is preserved.
Packit aea12f
dnl
Packit aea12f
dnl This file can be used in projects which are not available under
Packit Service 991b93
dnl the GNU General Public License or the GNU Lesser General Public
Packit aea12f
dnl License but which still want to provide support for the GNU gettext
Packit aea12f
dnl functionality.
Packit aea12f
dnl Please note that the actual code of the GNU gettext library is covered
Packit Service 991b93
dnl by the GNU Lesser General Public License, and the rest of the GNU
Packit aea12f
dnl gettext package is covered by the GNU General Public License.
Packit aea12f
dnl They are *not* in the public domain.
Packit aea12f
Packit aea12f
dnl Check how to retrieve the name of a per-thread locale (POSIX locale_t).
Packit aea12f
dnl Sets gt_nameless_locales.
Packit aea12f
AC_DEFUN([gt_INTL_THREAD_LOCALE_NAME],
Packit aea12f
[
Packit Service 991b93
  AC_REQUIRE([AC_CANONICAL_HOST])
Packit aea12f
Packit aea12f
  dnl Persuade Solaris <locale.h> to define 'locale_t'.
Packit aea12f
  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
Packit aea12f
Packit aea12f
  dnl Test whether uselocale() exists and works at all.
Packit aea12f
  gt_FUNC_USELOCALE
Packit aea12f
Packit aea12f
  dnl On OpenBSD >= 6.2, the locale_t type and the uselocale(), newlocale(),
Packit aea12f
  dnl duplocale(), freelocale() functions exist but are effectively useless,
Packit aea12f
  dnl because the locale_t value depends only on the LC_CTYPE category of the
Packit aea12f
  dnl locale and furthermore contains only one bit of information (it
Packit aea12f
  dnl distinguishes the "C" locale from the *.UTF-8 locales). See
Packit aea12f
  dnl <https://cvsweb.openbsd.org/src/lib/libc/locale/newlocale.c?rev=1.1&content-type=text/x-cvsweb-markup>.
Packit aea12f
  dnl In the setlocale() implementation they have thought about the programs
Packit aea12f
  dnl that use the API ("Even though only LC_CTYPE has any effect in the
Packit aea12f
  dnl OpenBSD base system, store complete information about the global locale,
Packit aea12f
  dnl such that third-party software can access it"), but for uselocale()
Packit aea12f
  dnl they did not think about the programs.
Packit aea12f
  dnl In this situation, even the HAVE_NAMELESS_LOCALES support does not work.
Packit aea12f
  dnl So, define HAVE_FAKE_LOCALES and disable all locale_t support.
Packit aea12f
  case "$gt_cv_func_uselocale_works" in
Packit aea12f
    *yes)
Packit aea12f
      AC_CHECK_HEADERS_ONCE([xlocale.h])
Packit aea12f
      AC_CACHE_CHECK([for fake locale system (OpenBSD)],
Packit aea12f
        [gt_cv_locale_fake],
Packit aea12f
        [AC_RUN_IFELSE(
Packit aea12f
           [AC_LANG_SOURCE([[
Packit aea12f
#include <locale.h>
Packit aea12f
#if HAVE_XLOCALE_H
Packit aea12f
# include <xlocale.h>
Packit aea12f
#endif
Packit aea12f
int main ()
Packit aea12f
{
Packit aea12f
  locale_t loc1, loc2;
Packit aea12f
  if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL) return 1;
Packit aea12f
  if (setlocale (LC_ALL, "fr_FR.UTF-8") == NULL) return 1;
Packit aea12f
  loc1 = newlocale (LC_ALL_MASK, "de_DE.UTF-8", (locale_t)0);
Packit aea12f
  loc2 = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", (locale_t)0);
Packit aea12f
  return !(loc1 == loc2);
Packit aea12f
}]])],
Packit aea12f
           [gt_cv_locale_fake=yes],
Packit aea12f
           [gt_cv_locale_fake=no],
Packit aea12f
           [dnl Guess the locale system is fake only on OpenBSD.
Packit aea12f
            case "$host_os" in
Packit aea12f
              openbsd*) gt_cv_locale_fake="guessing yes" ;;
Packit aea12f
              *)        gt_cv_locale_fake="guessing no" ;;
Packit aea12f
            esac
Packit aea12f
           ])
Packit aea12f
        ])
Packit aea12f
      ;;
Packit aea12f
    *) gt_cv_locale_fake=no ;;
Packit aea12f
  esac
Packit aea12f
  case "$gt_cv_locale_fake" in
Packit aea12f
    *yes)
Packit aea12f
      AC_DEFINE([HAVE_FAKE_LOCALES], [1],
Packit aea12f
        [Define if the locale_t type contains insufficient information, as on OpenBSD.])
Packit aea12f
      ;;
Packit aea12f
  esac
Packit aea12f
Packit aea12f
  case "$gt_cv_func_uselocale_works" in
Packit aea12f
    *yes)
Packit aea12f
      AC_CACHE_CHECK([for Solaris 11.4 locale system],
Packit aea12f
        [gt_cv_locale_solaris114],
Packit aea12f
        [case "$host_os" in
Packit aea12f
           solaris*)
Packit aea12f
             dnl Test whether <locale.h> defines locale_t as a typedef of
Packit aea12f
             dnl 'struct _LC_locale_t **' (whereas Illumos defines it as a
Packit aea12f
             dnl typedef of 'struct _locale *').
Packit aea12f
             dnl Another possible test would be to include <sys/localedef.h>
Packit aea12f
             dnl and test whether it defines the _LC_core_data_locale_t type.
Packit aea12f
             dnl This type was added in Solaris 11.4.
Packit aea12f
             AC_COMPILE_IFELSE(
Packit aea12f
               [AC_LANG_PROGRAM([[
Packit aea12f
                  #include <locale.h>
Packit aea12f
                  struct _LC_locale_t *x;
Packit aea12f
                  locale_t y;
Packit aea12f
                ]],
Packit aea12f
                [[*y = x;]])],
Packit aea12f
               [gt_cv_locale_solaris114=yes],
Packit aea12f
               [gt_cv_locale_solaris114=no])
Packit aea12f
             ;;
Packit aea12f
           *) gt_cv_locale_solaris114=no ;;
Packit aea12f
         esac
Packit aea12f
        ])
Packit aea12f
      ;;
Packit aea12f
    *) gt_cv_locale_solaris114=no ;;
Packit aea12f
  esac
Packit aea12f
  if test $gt_cv_locale_solaris114 = yes; then
Packit aea12f
    AC_DEFINE([HAVE_SOLARIS114_LOCALES], [1],
Packit aea12f
      [Define if the locale_t type is as on Solaris 11.4.])
Packit aea12f
  fi
Packit aea12f
Packit aea12f
  dnl Solaris 12 will maybe provide getlocalename_l.  If it does, it will
Packit aea12f
  dnl improve the implementation of gl_locale_name_thread(), by removing
Packit aea12f
  dnl the use of undocumented structures.
Packit aea12f
  case "$gt_cv_func_uselocale_works" in
Packit aea12f
    *yes)
Packit aea12f
      AC_CHECK_FUNCS([getlocalename_l])
Packit aea12f
      ;;
Packit aea12f
  esac
Packit aea12f
Packit Service 991b93
  dnl This code is for platforms where the locale_t type does not provide access
Packit Service 991b93
  dnl to the name of each locale category.  This code has the drawback that it
Packit Service 991b93
  dnl requires the gnulib overrides of 'newlocale', 'duplocale', 'freelocale',
Packit Service 991b93
  dnl which is a problem for GNU libunistring.  Therefore try hard to avoid
Packit Service 991b93
  dnl enabling this code!
Packit aea12f
  gt_nameless_locales=no
Packit Service 991b93
  case "$host_os" in
Packit Service 991b93
    dnl It's needed on AIX 7.2.
Packit Service 991b93
    aix*)
Packit Service 991b93
      gt_nameless_locales=yes
Packit Service 991b93
      AC_DEFINE([HAVE_NAMELESS_LOCALES], [1],
Packit Service 991b93
        [Define if the locale_t type does not contain the name of each locale category.])
Packit Service 991b93
      ;;
Packit Service 991b93
  esac
Packit aea12f
])
Packit aea12f
Packit aea12f
dnl Tests whether uselocale() exists and is usable.
Packit aea12f
dnl Sets gt_cv_func_uselocale_works. Defines HAVE_WORKING_USELOCALE.
Packit aea12f
AC_DEFUN([gt_FUNC_USELOCALE],
Packit aea12f
[
Packit aea12f
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit aea12f
Packit Service 991b93
  dnl Persuade glibc and Solaris <locale.h> to define 'locale_t'.
Packit aea12f
  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
Packit aea12f
Packit aea12f
  AC_CHECK_FUNCS_ONCE([uselocale])
Packit aea12f
Packit aea12f
  dnl On AIX 7.2, the uselocale() function is not documented and leads to
Packit aea12f
  dnl crashes in subsequent setlocale() invocations.
Packit Service 991b93
  dnl In 2019, some versions of z/OS lack the locale_t type and have a broken
Packit Service 991b93
  dnl uselocale function.
Packit aea12f
  if test $ac_cv_func_uselocale = yes; then
Packit aea12f
    AC_CHECK_HEADERS_ONCE([xlocale.h])
Packit aea12f
    AC_CACHE_CHECK([whether uselocale works],
Packit aea12f
      [gt_cv_func_uselocale_works],
Packit aea12f
      [AC_RUN_IFELSE(
Packit aea12f
         [AC_LANG_SOURCE([[
Packit aea12f
#include <locale.h>
Packit aea12f
#if HAVE_XLOCALE_H
Packit aea12f
# include <xlocale.h>
Packit aea12f
#endif
Packit Service 991b93
locale_t loc1;
Packit aea12f
int main ()
Packit aea12f
{
Packit aea12f
  uselocale (NULL);
Packit aea12f
  setlocale (LC_ALL, "en_US.UTF-8");
Packit aea12f
  return 0;
Packit aea12f
}]])],
Packit aea12f
         [gt_cv_func_uselocale_works=yes],
Packit aea12f
         [gt_cv_func_uselocale_works=no],
Packit Service 991b93
         [# Guess no on AIX and z/OS, yes otherwise.
Packit aea12f
          case "$host_os" in
Packit Service 991b93
            aix* | openedition*) gt_cv_func_uselocale_works="guessing no" ;;
Packit Service 991b93
            *)                   gt_cv_func_uselocale_works="guessing yes" ;;
Packit aea12f
          esac
Packit aea12f
         ])
Packit aea12f
      ])
Packit aea12f
  else
Packit aea12f
    gt_cv_func_uselocale_works=no
Packit aea12f
  fi
Packit aea12f
  case "$gt_cv_func_uselocale_works" in
Packit aea12f
    *yes)
Packit aea12f
      AC_DEFINE([HAVE_WORKING_USELOCALE], [1],
Packit aea12f
        [Define if the uselocale function exists any may safely be called.])
Packit aea12f
      ;;
Packit aea12f
  esac
Packit aea12f
])