1 # setlocale.m4 serial 7
2 dnl Copyright (C) 2011-2020 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.
7 AC_DEFUN([gl_FUNC_SETLOCALE],
9 AC_REQUIRE([gl_LOCALE_H_DEFAULTS])
10 AC_REQUIRE([gl_FUNC_SETLOCALE_NULL])
11 AC_REQUIRE([AC_CANONICAL_HOST])
13 dnl Test whether we need to improve on the general working of setlocale.
14 NEED_SETLOCALE_IMPROVED=0
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".
23 1.5.*) NEED_SETLOCALE_IMPROVED=1 ;;
26 dnl On Android 4.3, setlocale(category,"C") always fails.
28 AC_CACHE_CHECK([whether setlocale supports the C locale],
29 [gl_cv_func_setlocale_works],
35 return setlocale (LC_ALL, "C") == NULL;
37 [gl_cv_func_setlocale_works=yes],
38 [gl_cv_func_setlocale_works=no],
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";;
47 case "$gl_cv_func_setlocale_works" in
49 *) NEED_SETLOCALE_IMPROVED=1 ;;
53 AC_DEFINE_UNQUOTED([NEED_SETLOCALE_IMPROVED], [$NEED_SETLOCALE_IMPROVED],
54 [Define to 1 to enable general improvements of setlocale.])
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
61 AC_DEFINE_UNQUOTED([NEED_SETLOCALE_MTSAFE], [$NEED_SETLOCALE_MTSAFE],
62 [Define to 1 to enable a multithread-safety fix of setlocale.])
64 if test $NEED_SETLOCALE_IMPROVED = 1 || test $NEED_SETLOCALE_MTSAFE = 1; then
68 if test $NEED_SETLOCALE_MTSAFE = 1; then
69 LIB_SETLOCALE="$LIB_SETLOCALE_NULL"
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])
78 # Prerequisites of lib/setlocale.c.
79 AC_DEFUN([gl_PREREQ_SETLOCALE],
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.)