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