| 1 |
# libunistring.m4 |
| 2 |
# serial 13 |
| 3 |
dnl Copyright (C) 2009-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_PREREQ([2.64]) |
| 10 |
|
| 11 |
dnl gl_LIBUNISTRING |
| 12 |
dnl Searches for an installed libunistring. |
| 13 |
dnl If found, it sets and AC_SUBSTs HAVE_LIBUNISTRING=yes and the LIBUNISTRING |
| 14 |
dnl and LTLIBUNISTRING variables, sets the LIBUNISTRING_VERSION variable, and |
| 15 |
dnl augments the CPPFLAGS variable, and #defines HAVE_LIBUNISTRING to 1. |
| 16 |
dnl Otherwise, it sets and AC_SUBSTs HAVE_LIBUNISTRING=no and LIBUNISTRING and |
| 17 |
dnl LTLIBUNISTRING to empty. |
| 18 |
|
| 19 |
dnl Define gl_LIBUNISTRING using AC_DEFUN_ONCE, in order dnl to avoid warnings |
| 20 |
dnl like |
| 21 |
dnl "warning: AC_REQUIRE: `gl_LIBUNISTRING' was expanded before it was required". |
| 22 |
dnl This is tricky because of the way 'aclocal' is implemented: |
| 23 |
dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN. |
| 24 |
dnl Otherwise aclocal's initial scan pass would miss the macro definition. |
| 25 |
dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions. |
| 26 |
dnl Otherwise aclocal would emit many "Use of uninitialized value $1" |
| 27 |
dnl warnings. |
| 28 |
AC_DEFUN_ONCE([gl_LIBUNISTRING], |
| 29 |
[ |
| 30 |
AC_BEFORE([$0], [gl_LIBUNISTRING_MODULE]) |
| 31 |
AC_BEFORE([$0], [gl_LIBUNISTRING_LIBHEADER]) |
| 32 |
AC_BEFORE([$0], [gl_LIBUNISTRING_LIB_PREPARE]) |
| 33 |
|
| 34 |
m4_ifdef([gl_LIBUNISTRING_OPTIONAL], |
| 35 |
[ |
| 36 |
AC_MSG_CHECKING([whether included libunistring is requested]) |
| 37 |
AC_ARG_WITH([included-libunistring], |
| 38 |
[ --with-included-libunistring use the libunistring parts included here], |
| 39 |
[gl_libunistring_force_included=$withval], |
| 40 |
[gl_libunistring_force_included=no]) |
| 41 |
AC_MSG_RESULT([$gl_libunistring_force_included]) |
| 42 |
gl_libunistring_use_included="$gl_libunistring_force_included" |
| 43 |
if test "$gl_libunistring_use_included" = yes; then |
| 44 |
dnl Assume that libunistring is not installed until some other macro |
| 45 |
dnl explicitly invokes gl_LIBUNISTRING_CORE. |
| 46 |
if test -z "$HAVE_LIBUNISTRING"; then |
| 47 |
HAVE_LIBUNISTRING=no |
| 48 |
fi |
| 49 |
LIBUNISTRING= |
| 50 |
LTLIBUNISTRING= |
| 51 |
else |
| 52 |
gl_LIBUNISTRING_CORE |
| 53 |
if test $HAVE_LIBUNISTRING = no; then |
| 54 |
gl_libunistring_use_included=yes |
| 55 |
LIBUNISTRING= |
| 56 |
LTLIBUNISTRING= |
| 57 |
fi |
| 58 |
fi |
| 59 |
], |
| 60 |
[gl_LIBUNISTRING_CORE]) |
| 61 |
]) |
| 62 |
|
| 63 |
AC_DEFUN([gl_LIBUNISTRING_CORE], |
| 64 |
[ |
| 65 |
AC_REQUIRE([AM_ICONV]) |
| 66 |
if test -n "$LIBICONV"; then |
| 67 |
dnl First, try to link without -liconv. libunistring often depends on |
| 68 |
dnl libiconv, but we don't know (and often don't need to know) where |
| 69 |
dnl libiconv is installed. |
| 70 |
AC_LIB_HAVE_LINKFLAGS([unistring], [], |
| 71 |
[#include <uniconv.h>], [u8_strconv_from_locale((char*)0);], |
| 72 |
[no, trying again together with libiconv]) |
| 73 |
if test "$ac_cv_libunistring" != yes; then |
| 74 |
dnl Second try, with -liconv. |
| 75 |
dnl We have to erase the cached result of the first AC_LIB_HAVE_LINKFLAGS |
| 76 |
dnl invocation, otherwise the second one will not be run. |
| 77 |
unset ac_cv_libunistring |
| 78 |
glus_saved_LIBS="$LIBS" |
| 79 |
LIBS="$LIBS $LIBICONV" |
| 80 |
AC_LIB_HAVE_LINKFLAGS([unistring], [], |
| 81 |
[#include <uniconv.h>], [u8_strconv_from_locale((char*)0);], |
| 82 |
[no, consider installing GNU libunistring]) |
| 83 |
if test -n "$LIBUNISTRING"; then |
| 84 |
LIBUNISTRING="$LIBUNISTRING $LIBICONV" |
| 85 |
LTLIBUNISTRING="$LTLIBUNISTRING $LTLIBICONV" |
| 86 |
fi |
| 87 |
LIBS="$glus_saved_LIBS" |
| 88 |
fi |
| 89 |
else |
| 90 |
AC_LIB_HAVE_LINKFLAGS([unistring], [], |
| 91 |
[#include <uniconv.h>], [u8_strconv_from_locale((char*)0);], |
| 92 |
[no, consider installing GNU libunistring]) |
| 93 |
fi |
| 94 |
if test $HAVE_LIBUNISTRING = yes; then |
| 95 |
dnl Determine the installed version. |
| 96 |
AC_CACHE_CHECK([for libunistring version], [gl_cv_libunistring_version], |
| 97 |
[AC_COMPUTE_INT([gl_libunistring_hexversion], |
| 98 |
[_LIBUNISTRING_VERSION], |
| 99 |
[#include <unistring/version.h>]) |
| 100 |
dnl Versions <= 0.9.3 had a hexversion of 0x0009. |
| 101 |
dnl Use other tests to distinguish them. |
| 102 |
if test $gl_libunistring_hexversion = 9; then |
| 103 |
dnl Version 0.9.2 introduced the header <unistring/cdefs.h>. |
| 104 |
AC_COMPILE_IFELSE( |
| 105 |
[AC_LANG_PROGRAM([[#include <unistring/cdefs.h>]], [[]])], |
| 106 |
[gl_cv_libunistring_version092=true], |
| 107 |
[gl_cv_libunistring_version092=false]) |
| 108 |
if $gl_cv_libunistring_version092; then |
| 109 |
dnl Version 0.9.3 changed a comment in <unistr.h>. |
| 110 |
gl_ABSOLUTE_HEADER_ONE([unistr.h]) |
| 111 |
if test -n "$gl_cv_absolute_unistr_h" \ |
| 112 |
&& grep 'Copy no more than N units of SRC to DEST. Return a pointer' $gl_cv_absolute_unistr_h > /dev/null; then |
| 113 |
dnl Detected version 0.9.3. |
| 114 |
gl_libunistring_hexversion=2307 |
| 115 |
else |
| 116 |
dnl Detected version 0.9.2. |
| 117 |
gl_libunistring_hexversion=2306 |
| 118 |
fi |
| 119 |
else |
| 120 |
dnl Version 0.9.1 introduced the type casing_suffix_context_t. |
| 121 |
AC_COMPILE_IFELSE( |
| 122 |
[AC_LANG_PROGRAM( |
| 123 |
[[#include <unicase.h> |
| 124 |
casing_suffix_context_t ct;]], |
| 125 |
[[]])], |
| 126 |
[gl_cv_libunistring_version091=true], |
| 127 |
[gl_cv_libunistring_version091=false]) |
| 128 |
if $gl_cv_libunistring_version091; then |
| 129 |
dnl Detected version 0.9.1. |
| 130 |
gl_libunistring_hexversion=2305 |
| 131 |
else |
| 132 |
dnl Detected version 0.9. |
| 133 |
gl_libunistring_hexversion=2304 |
| 134 |
fi |
| 135 |
fi |
| 136 |
fi |
| 137 |
dnl Transform into the usual major.minor.subminor notation. |
| 138 |
gl_libunistring_major=`expr $gl_libunistring_hexversion / 65536` |
| 139 |
gl_libunistring_minor=`expr $gl_libunistring_hexversion / 256 % 256` |
| 140 |
gl_libunistring_subminor=`expr $gl_libunistring_hexversion % 256` |
| 141 |
gl_cv_libunistring_version="$gl_libunistring_major.$gl_libunistring_minor.$gl_libunistring_subminor" |
| 142 |
]) |
| 143 |
LIBUNISTRING_VERSION="$gl_cv_libunistring_version" |
| 144 |
fi |
| 145 |
]) |