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