setlocale_null.m4 3.6 KB

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