| 1 |
# setlocale_null.m4 |
| 2 |
# serial 9 |
| 3 |
dnl Copyright (C) 2019-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. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_SETLOCALE_NULL], |
| 10 |
[ |
| 11 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 12 |
AC_REQUIRE([gl_PTHREADLIB]) |
| 13 |
AC_CHECK_HEADERS_ONCE([threads.h]) |
| 14 |
|
| 15 |
AC_CACHE_CHECK([whether setlocale (LC_ALL, NULL) is multithread-safe], |
| 16 |
[gl_cv_func_setlocale_null_all_mtsafe], |
| 17 |
[case "$host_os" in |
| 18 |
# Guess no on musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku. |
| 19 |
*-musl* | midipix* | darwin* | freebsd* | midnightbsd* | netbsd* | openbsd* | aix* | haiku*) |
| 20 |
gl_cv_func_setlocale_null_all_mtsafe=no ;; |
| 21 |
# Guess no on Cygwin < 3.4.6. |
| 22 |
cygwin*) |
| 23 |
AC_EGREP_CPP([Lucky user], |
| 24 |
[ |
| 25 |
#if defined __CYGWIN__ |
| 26 |
#include <cygwin/version.h> |
| 27 |
#if CYGWIN_VERSION_DLL_COMBINED >= CYGWIN_VERSION_DLL_MAKE_COMBINED (3004, 6) |
| 28 |
Lucky user |
| 29 |
#endif |
| 30 |
#endif |
| 31 |
], |
| 32 |
[gl_cv_func_setlocale_null_all_mtsafe=yes], |
| 33 |
[gl_cv_func_setlocale_null_all_mtsafe=no]) |
| 34 |
;; |
| 35 |
# Guess yes on glibc, HP-UX, IRIX, Solaris, native Windows. |
| 36 |
*-gnu* | gnu* | hpux* | irix* | solaris* | mingw* | windows*) |
| 37 |
gl_cv_func_setlocale_null_all_mtsafe=yes ;; |
| 38 |
# If we don't know, obey --enable-cross-guesses. |
| 39 |
*) |
| 40 |
gl_cv_func_setlocale_null_all_mtsafe="$gl_cross_guess_normal" ;; |
| 41 |
esac |
| 42 |
]) |
| 43 |
dnl On platforms without multithreading, there is no issue. |
| 44 |
case "$host_os" in |
| 45 |
mingw* | windows*) ;; |
| 46 |
*) |
| 47 |
if test $gl_pthread_api = no && test $ac_cv_header_threads_h = no; then |
| 48 |
gl_cv_func_setlocale_null_all_mtsafe="trivially yes" |
| 49 |
fi |
| 50 |
;; |
| 51 |
esac |
| 52 |
case "$gl_cv_func_setlocale_null_all_mtsafe" in |
| 53 |
*yes) SETLOCALE_NULL_ALL_MTSAFE=1 ;; |
| 54 |
*) SETLOCALE_NULL_ALL_MTSAFE=0 ;; |
| 55 |
esac |
| 56 |
AC_DEFINE_UNQUOTED([SETLOCALE_NULL_ALL_MTSAFE], [$SETLOCALE_NULL_ALL_MTSAFE], |
| 57 |
[Define to 1 if setlocale (LC_ALL, NULL) is multithread-safe.]) |
| 58 |
|
| 59 |
dnl This is about a single category (not LC_ALL). |
| 60 |
AC_CACHE_CHECK([whether setlocale (category, NULL) is multithread-safe], |
| 61 |
[gl_cv_func_setlocale_null_one_mtsafe], |
| 62 |
[case "$host_os" in |
| 63 |
# Guess no on OpenBSD, AIX. |
| 64 |
openbsd* | aix*) |
| 65 |
gl_cv_func_setlocale_null_one_mtsafe=no ;; |
| 66 |
# Guess yes on glibc, musl libc, macOS, FreeBSD, NetBSD, HP-UX, IRIX, Solaris, Haiku, Cygwin, native Windows. |
| 67 |
*-gnu* | gnu* | *-musl* | midipix* | darwin* | freebsd* | midnightbsd* | netbsd* | hpux* | irix* | solaris* | haiku* | cygwin* | mingw* | windows*) |
| 68 |
gl_cv_func_setlocale_null_one_mtsafe=yes ;; |
| 69 |
# If we don't know, obey --enable-cross-guesses. |
| 70 |
*) |
| 71 |
gl_cv_func_setlocale_null_one_mtsafe="$gl_cross_guess_normal" ;; |
| 72 |
esac |
| 73 |
]) |
| 74 |
dnl On platforms without multithreading, there is no issue. |
| 75 |
case "$host_os" in |
| 76 |
mingw* | windows*) ;; |
| 77 |
*) |
| 78 |
if test $gl_pthread_api = no && test $ac_cv_header_threads_h = no; then |
| 79 |
gl_cv_func_setlocale_null_one_mtsafe="trivially yes" |
| 80 |
fi |
| 81 |
;; |
| 82 |
esac |
| 83 |
case "$gl_cv_func_setlocale_null_one_mtsafe" in |
| 84 |
*yes) SETLOCALE_NULL_ONE_MTSAFE=1 ;; |
| 85 |
*) SETLOCALE_NULL_ONE_MTSAFE=0 ;; |
| 86 |
esac |
| 87 |
AC_DEFINE_UNQUOTED([SETLOCALE_NULL_ONE_MTSAFE], [$SETLOCALE_NULL_ONE_MTSAFE], |
| 88 |
[Define to 1 if setlocale (category, NULL) is multithread-safe.]) |
| 89 |
|
| 90 |
dnl Determine link dependencies of lib/setlocale_null.c and lib/setlocale-lock.c. |
| 91 |
if test $SETLOCALE_NULL_ALL_MTSAFE = 0 || test $SETLOCALE_NULL_ONE_MTSAFE = 0; then |
| 92 |
case "$host_os" in |
| 93 |
mingw* | windows*) |
| 94 |
SETLOCALE_NULL_LIB= |
| 95 |
;; |
| 96 |
*) |
| 97 |
gl_WEAK_SYMBOLS |
| 98 |
case "$gl_cv_have_weak" in |
| 99 |
*yes) SETLOCALE_NULL_LIB= ;; |
| 100 |
*) SETLOCALE_NULL_LIB="$LIBPTHREAD" ;; |
| 101 |
esac |
| 102 |
;; |
| 103 |
esac |
| 104 |
else |
| 105 |
SETLOCALE_NULL_LIB= |
| 106 |
fi |
| 107 |
dnl SETLOCALE_NULL_LIB is expected to be '-pthread' or '-lpthread' on AIX |
| 108 |
dnl with gcc or xlc, and empty otherwise. |
| 109 |
AC_SUBST([SETLOCALE_NULL_LIB]) |
| 110 |
dnl For backward compatibility. |
| 111 |
LIB_SETLOCALE_NULL="$SETLOCALE_NULL_LIB" |
| 112 |
AC_SUBST([LIB_SETLOCALE_NULL]) |
| 113 |
]) |
| 114 |
|
| 115 |
# Prerequisites of lib/setlocale-lock.c. |
| 116 |
AC_DEFUN([gl_PREREQ_SETLOCALE_LOCK], |
| 117 |
[ |
| 118 |
gl_VISIBILITY |
| 119 |
]) |