| 1 |
dnl Checks for libclocale required headers and functions |
| 2 |
dnl |
| 3 |
dnl Version: 20240513 |
| 4 |
|
| 5 |
dnl Function to detect if libclocale is available |
| 6 |
dnl ac_libclocale_dummy is used to prevent AC_CHECK_LIB adding unnecessary -l<library> arguments |
| 7 |
AC_DEFUN([AX_LIBCLOCALE_CHECK_LIB], |
| 8 |
[AS_IF( |
| 9 |
[test "x$ac_cv_enable_shared_libs" = xno || test "x$ac_cv_with_libclocale" = xno], |
| 10 |
[ac_cv_libclocale=no], |
| 11 |
[ac_cv_libclocale=check |
| 12 |
dnl Check if the directory provided as parameter exists |
| 13 |
dnl For both --with-libclocale which returns "yes" and --with-libclocale= which returns "" |
| 14 |
dnl treat them as auto-detection. |
| 15 |
AS_IF( |
| 16 |
[test "x$ac_cv_with_libclocale" != x && test "x$ac_cv_with_libclocale" != xauto-detect && test "x$ac_cv_with_libclocale" != xyes], |
| 17 |
[AX_CHECK_LIB_DIRECTORY_EXISTS([libclocale])], |
| 18 |
[dnl Check for a pkg-config file |
| 19 |
AS_IF( |
| 20 |
[test "x$cross_compiling" != "xyes" && test "x$PKGCONFIG" != "x"], |
| 21 |
[PKG_CHECK_MODULES( |
| 22 |
[libclocale], |
| 23 |
[libclocale >= 20120425], |
| 24 |
[ac_cv_libclocale=yes], |
| 25 |
[ac_cv_libclocale=check]) |
| 26 |
]) |
| 27 |
AS_IF( |
| 28 |
[test "x$ac_cv_libclocale" = xyes && test "x$ac_cv_enable_wide_character_type" != xno], |
| 29 |
[AC_CACHE_CHECK( |
| 30 |
[whether libclocale/features.h defines LIBCLOCALE_HAVE_WIDE_CHARACTER_TYPE as 1], |
| 31 |
[ac_cv_header_libclocale_features_h_have_wide_character_type], |
| 32 |
[AC_LANG_PUSH(C) |
| 33 |
AC_COMPILE_IFELSE( |
| 34 |
[AC_LANG_PROGRAM( |
| 35 |
[[#include <libclocale/features.h>]], |
| 36 |
[[#if !defined( LIBCLOCALE_HAVE_WIDE_CHARACTER_TYPE ) || ( LIBCLOCALE_HAVE_WIDE_CHARACTER_TYPE != 1 ) |
| 37 |
#error LIBCLOCALE_HAVE_WIDE_CHARACTER_TYPE not defined |
| 38 |
#endif]] )], |
| 39 |
[ac_cv_header_libclocale_features_h_have_wide_character_type=yes], |
| 40 |
[ac_cv_header_libclocale_features_h_have_wide_character_type=no]) |
| 41 |
AC_LANG_POP(C)], |
| 42 |
[ac_cv_header_libclocale_features_h_have_wide_character_type=no]) |
| 43 |
|
| 44 |
AS_IF( |
| 45 |
[test "x$ac_cv_header_libclocale_features_h_have_wide_character_type" = xno], |
| 46 |
[ac_cv_libclocale=no]) |
| 47 |
]) |
| 48 |
AS_IF( |
| 49 |
[test "x$ac_cv_libclocale" = xyes], |
| 50 |
[ac_cv_libclocale_CPPFLAGS="$pkg_cv_libclocale_CFLAGS" |
| 51 |
ac_cv_libclocale_LIBADD="$pkg_cv_libclocale_LIBS"]) |
| 52 |
]) |
| 53 |
|
| 54 |
AS_IF( |
| 55 |
[test "x$ac_cv_libclocale" = xcheck], |
| 56 |
[dnl Check for headers |
| 57 |
AC_CHECK_HEADERS([libclocale.h]) |
| 58 |
|
| 59 |
AS_IF( |
| 60 |
[test "x$ac_cv_header_libclocale_h" = xno], |
| 61 |
[ac_cv_libclocale=no], |
| 62 |
[ac_cv_libclocale=yes |
| 63 |
|
| 64 |
AX_CHECK_LIB_FUNCTIONS( |
| 65 |
[libclocale], |
| 66 |
[clocale], |
| 67 |
[[libclocale_get_version], |
| 68 |
[libclocale_codepage], |
| 69 |
[libclocale_codepage_get], |
| 70 |
[libclocale_codepage_set], |
| 71 |
[libclocale_codepage_copy_from_string], |
| 72 |
[libclocale_locale_get_codepage], |
| 73 |
[libclocale_locale_get_decimal_point], |
| 74 |
[libclocale_initialize]]) |
| 75 |
|
| 76 |
AS_IF( |
| 77 |
[test "x$ac_cv_enable_wide_character_type" != xno], |
| 78 |
[AC_CHECK_LIB( |
| 79 |
clocale, |
| 80 |
libclocale_codepage_copy_from_string_wide, |
| 81 |
[ac_cv_libclocale_dummy=yes], |
| 82 |
[ac_cv_libclocale=no]) |
| 83 |
]) |
| 84 |
|
| 85 |
ac_cv_libclocale_LIBADD="-lclocale"]) |
| 86 |
]) |
| 87 |
|
| 88 |
AX_CHECK_LIB_DIRECTORY_MSG_ON_FAILURE([libclocale]) |
| 89 |
]) |
| 90 |
|
| 91 |
AS_IF( |
| 92 |
[test "x$ac_cv_libclocale" = xyes], |
| 93 |
[AC_DEFINE( |
| 94 |
[HAVE_LIBCLOCALE], |
| 95 |
[1], |
| 96 |
[Define to 1 if you have the `clocale' library (-lclocale).]) |
| 97 |
]) |
| 98 |
|
| 99 |
AS_IF( |
| 100 |
[test "x$ac_cv_libclocale" = xyes], |
| 101 |
[AC_SUBST( |
| 102 |
[HAVE_LIBCLOCALE], |
| 103 |
[1]) ], |
| 104 |
[AC_SUBST( |
| 105 |
[HAVE_LIBCLOCALE], |
| 106 |
[0]) |
| 107 |
]) |
| 108 |
]) |
| 109 |
|
| 110 |
dnl Function to detect whether nl_langinfo supports CODESET |
| 111 |
AC_DEFUN([AX_LIBCLOCALE_CHECK_FUNC_LANGINFO_CODESET], |
| 112 |
[AC_CHECK_FUNCS([nl_langinfo]) |
| 113 |
|
| 114 |
AS_IF( |
| 115 |
[test "x$ac_cv_func_nl_langinfo" = xyes], |
| 116 |
[AC_CACHE_CHECK( |
| 117 |
[for nl_langinfo CODESET support], |
| 118 |
[ac_cv_cv_langinfo_codeset], |
| 119 |
[AC_LANG_PUSH(C) |
| 120 |
AC_LINK_IFELSE( |
| 121 |
[AC_LANG_PROGRAM( |
| 122 |
[[#include <langinfo.h>]], |
| 123 |
[[char* charset = nl_langinfo( CODESET );]] )], |
| 124 |
[ac_cv_cv_langinfo_codeset=yes], |
| 125 |
[ac_cv_cv_langinfo_codeset=no]) |
| 126 |
AC_LANG_POP(C) ]) ], |
| 127 |
[ac_cv_cv_langinfo_codeset=no]) |
| 128 |
|
| 129 |
AS_IF( |
| 130 |
[test "x$ac_cv_cv_langinfo_codeset" = xyes], |
| 131 |
[AC_DEFINE( |
| 132 |
[HAVE_LANGINFO_CODESET], |
| 133 |
[1], |
| 134 |
[Define if nl_langinfo has CODESET support.]) |
| 135 |
]) |
| 136 |
]) |
| 137 |
|
| 138 |
dnl Function to detect if libclocale dependencies are available |
| 139 |
AC_DEFUN([AX_LIBCLOCALE_CHECK_LOCAL], |
| 140 |
[dnl Headers included in libclocale/libclocale_locale.c |
| 141 |
AC_CHECK_HEADERS([langinfo.h locale.h]) |
| 142 |
|
| 143 |
dnl Check for environment functions in libclocale/libclocale_locale.c |
| 144 |
AC_CHECK_FUNCS([getenv]) |
| 145 |
|
| 146 |
AS_IF( |
| 147 |
[test "x$ac_cv_func_getenv" != xyes], |
| 148 |
[AC_MSG_FAILURE( |
| 149 |
[Missing function: getenv], |
| 150 |
[1]) |
| 151 |
]) |
| 152 |
|
| 153 |
dnl Check for localization functions in libclocale/libclocale_locale.c |
| 154 |
AS_IF( |
| 155 |
[test "x$ac_cv_enable_winapi" = xno], |
| 156 |
[AC_CHECK_FUNCS([localeconv]) |
| 157 |
|
| 158 |
AS_IF( |
| 159 |
[test "x$ac_cv_func_localeconv" != xyes], |
| 160 |
[AC_MSG_FAILURE( |
| 161 |
[Missing function: localeconv], |
| 162 |
[1]) |
| 163 |
]) |
| 164 |
]) |
| 165 |
|
| 166 |
AC_CHECK_FUNCS([setlocale]) |
| 167 |
|
| 168 |
AS_IF( |
| 169 |
[test "x$ac_cv_func_setlocale" != xyes], |
| 170 |
[AC_MSG_FAILURE( |
| 171 |
[Missing function: setlocale], |
| 172 |
[1]) |
| 173 |
]) |
| 174 |
|
| 175 |
AX_LIBCLOCALE_CHECK_FUNC_LANGINFO_CODESET |
| 176 |
|
| 177 |
ac_cv_libclocale_CPPFLAGS="-I../libclocale -I\$(top_srcdir)/libclocale"; |
| 178 |
ac_cv_libclocale_LIBADD="../libclocale/libclocale.la"; |
| 179 |
|
| 180 |
ac_cv_libclocale=local |
| 181 |
]) |
| 182 |
|
| 183 |
dnl Function to detect how to enable libclocale |
| 184 |
AC_DEFUN([AX_LIBCLOCALE_CHECK_ENABLE], |
| 185 |
[AX_COMMON_ARG_WITH( |
| 186 |
[libclocale], |
| 187 |
[libclocale], |
| 188 |
[search for libclocale in includedir and libdir or in the specified DIR, or no if to use local version], |
| 189 |
[auto-detect], |
| 190 |
[DIR]) |
| 191 |
|
| 192 |
dnl Check for a shared library version |
| 193 |
AX_LIBCLOCALE_CHECK_LIB |
| 194 |
|
| 195 |
dnl Check if the dependencies for the local library version |
| 196 |
AS_IF( |
| 197 |
[test "x$ac_cv_libclocale" != xyes], |
| 198 |
[AX_LIBCLOCALE_CHECK_LOCAL |
| 199 |
|
| 200 |
AC_DEFINE( |
| 201 |
[HAVE_LOCAL_LIBCLOCALE], |
| 202 |
[1], |
| 203 |
[Define to 1 if the local version of libclocale is used.]) |
| 204 |
AC_SUBST( |
| 205 |
[HAVE_LOCAL_LIBCLOCALE], |
| 206 |
[1]) |
| 207 |
]) |
| 208 |
|
| 209 |
AM_CONDITIONAL( |
| 210 |
[HAVE_LOCAL_LIBCLOCALE], |
| 211 |
[test "x$ac_cv_libclocale" = xlocal]) |
| 212 |
AS_IF( |
| 213 |
[test "x$ac_cv_libclocale_CPPFLAGS" != "x"], |
| 214 |
[AC_SUBST( |
| 215 |
[LIBCLOCALE_CPPFLAGS], |
| 216 |
[$ac_cv_libclocale_CPPFLAGS]) |
| 217 |
]) |
| 218 |
AS_IF( |
| 219 |
[test "x$ac_cv_libclocale_LIBADD" != "x"], |
| 220 |
[AC_SUBST( |
| 221 |
[LIBCLOCALE_LIBADD], |
| 222 |
[$ac_cv_libclocale_LIBADD]) |
| 223 |
]) |
| 224 |
|
| 225 |
AS_IF( |
| 226 |
[test "x$ac_cv_libclocale" = xyes], |
| 227 |
[AC_SUBST( |
| 228 |
[ax_libclocale_pc_libs_private], |
| 229 |
[-lclocale]) |
| 230 |
]) |
| 231 |
|
| 232 |
AS_IF( |
| 233 |
[test "x$ac_cv_libclocale" = xyes], |
| 234 |
[AC_SUBST( |
| 235 |
[ax_libclocale_spec_requires], |
| 236 |
[libclocale]) |
| 237 |
AC_SUBST( |
| 238 |
[ax_libclocale_spec_build_requires], |
| 239 |
[libclocale-devel]) |
| 240 |
]) |
| 241 |
]) |
| 242 |
|