1# setlocale.m4 serial 7
2dnl Copyright (C) 2011-2020 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_FUNC_SETLOCALE],
8[
9  AC_REQUIRE([gl_LOCALE_H_DEFAULTS])
10  AC_REQUIRE([gl_FUNC_SETLOCALE_NULL])
11  AC_REQUIRE([AC_CANONICAL_HOST])
12
13  dnl Test whether we need to improve on the general working of setlocale.
14  NEED_SETLOCALE_IMPROVED=0
15  case "$host_os" in
16    dnl On native Windows systems, setlocale(category,NULL) does not look at
17    dnl the environment variables LC_ALL, category, and LANG.
18    mingw*) NEED_SETLOCALE_IMPROVED=1 ;;
19    dnl On Cygwin 1.5.x, setlocale always succeeds but setlocale(LC_CTYPE,NULL)
20    dnl is then still "C".
21    cygwin*)
22      case `uname -r` in
23        1.5.*) NEED_SETLOCALE_IMPROVED=1 ;;
24      esac
25      ;;
26    dnl On Android 4.3, setlocale(category,"C") always fails.
27    *)
28      AC_CACHE_CHECK([whether setlocale supports the C locale],
29        [gl_cv_func_setlocale_works],
30        [AC_RUN_IFELSE(
31           [AC_LANG_SOURCE([[
32#include <locale.h>
33int main ()
34{
35  return setlocale (LC_ALL, "C") == NULL;
36}]])],
37           [gl_cv_func_setlocale_works=yes],
38           [gl_cv_func_setlocale_works=no],
39           [case "$host_os" in
40                               # Guess no on Android.
41              linux*-android*) gl_cv_func_setlocale_works="guessing no";;
42                               # Guess yes otherwise.
43              *)               gl_cv_func_setlocale_works="guessing yes";;
44            esac
45           ])
46        ])
47      case "$gl_cv_func_setlocale_works" in
48        *yes) ;;
49        *) NEED_SETLOCALE_IMPROVED=1 ;;
50      esac
51      ;;
52  esac
53  AC_DEFINE_UNQUOTED([NEED_SETLOCALE_IMPROVED], [$NEED_SETLOCALE_IMPROVED],
54    [Define to 1 to enable general improvements of setlocale.])
55
56  dnl Test whether we need a multithread-safe setlocale(category,NULL).
57  NEED_SETLOCALE_MTSAFE=0
58  if test $SETLOCALE_NULL_ALL_MTSAFE = 0 || test $SETLOCALE_NULL_ONE_MTSAFE = 0; then
59    NEED_SETLOCALE_MTSAFE=1
60  fi
61  AC_DEFINE_UNQUOTED([NEED_SETLOCALE_MTSAFE], [$NEED_SETLOCALE_MTSAFE],
62    [Define to 1 to enable a multithread-safety fix of setlocale.])
63
64  if test $NEED_SETLOCALE_IMPROVED = 1 || test $NEED_SETLOCALE_MTSAFE = 1; then
65    REPLACE_SETLOCALE=1
66  fi
67
68  if test $NEED_SETLOCALE_MTSAFE = 1; then
69    LIB_SETLOCALE="$LIB_SETLOCALE_NULL"
70  else
71    LIB_SETLOCALE=
72  fi
73  dnl LIB_SETLOCALE is expected to be '-pthread' or '-lpthread' on AIX with gcc
74  dnl or xlc, and empty otherwise.
75  AC_SUBST([LIB_SETLOCALE])
76])
77
78# Prerequisites of lib/setlocale.c.
79AC_DEFUN([gl_PREREQ_SETLOCALE],
80[
81  dnl No need to check for CFLocaleCopyPreferredLanguages and
82  dnl CFPreferencesCopyAppValue because lib/setlocale.c is not used on Mac OS X.
83  dnl (The Mac OS X specific code is only used in libintl.)
84  :
85])
86