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