1 # libunistring.m4 serial 7
2 dnl Copyright (C) 2009-2010 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 m4_version_prereq([2.64],[AC_DEFUN_ONCE],[AC_DEFUN])([gl_LIBUNISTRING],
20 AC_BEFORE([$0], [gl_LIBUNISTRING_LIBSOURCE])
21 AC_BEFORE([$0], [gl_LIBUNISTRING_LIBHEADER])
22 AC_BEFORE([$0], [gl_LIBUNISTRING_LIB_PREPARE])
24 m4_ifdef([gl_LIBUNISTRING_OPTIONAL],
26 AC_MSG_CHECKING([whether included libunistring is requested])
27 AC_ARG_WITH([included-libunistring],
28 [ --with-included-libunistring use the libunistring parts included here],
29 [gl_libunistring_force_included=$withval],
30 [gl_libunistring_force_included=no])
31 AC_MSG_RESULT([$gl_libunistring_force_included])
32 gl_libunistring_use_included="$gl_libunistring_force_included"
33 if test "$gl_libunistring_use_included" = yes; then
34 dnl Assume that libunistring is not installed until some other macro
35 dnl explicitly invokes gl_LIBUNISTRING_CORE.
36 if test -z "$HAVE_LIBUNISTRING"; then
43 if test $HAVE_LIBUNISTRING = no; then
44 gl_libunistring_use_included=yes
50 [gl_LIBUNISTRING_CORE])
53 AC_DEFUN([gl_LIBUNISTRING_CORE],
55 AC_REQUIRE([AM_ICONV])
56 if test -n "$LIBICONV"; then
57 dnl First, try to link without -liconv. libunistring often depends on
58 dnl libiconv, but we don't know (and often don't need to know) where
59 dnl libiconv is installed.
60 AC_LIB_HAVE_LINKFLAGS([unistring], [],
61 [#include <uniconv.h>], [u8_strconv_from_locale((char*)0);],
62 [no, trying again together with libiconv])
63 if test "$ac_cv_libunistring" != yes; then
64 dnl Second try, with -liconv.
65 dnl We have to erase the cached result of the first AC_LIB_HAVE_LINKFLAGS
66 dnl invocation, otherwise the second one will not be run.
67 unset ac_cv_libunistring
68 glus_save_LIBS="$LIBS"
69 LIBS="$LIBS $LIBICONV"
70 AC_LIB_HAVE_LINKFLAGS([unistring], [],
71 [#include <uniconv.h>], [u8_strconv_from_locale((char*)0);],
72 [no, consider installing GNU libunistring])
73 if test -n "$LIBUNISTRING"; then
74 LIBUNISTRING="$LIBUNISTRING $LIBICONV"
75 LTLIBUNISTRING="$LTLIBUNISTRING $LTLIBICONV"
77 LIBS="$glus_save_LIBS"
80 AC_LIB_HAVE_LINKFLAGS([unistring], [],
81 [#include <uniconv.h>], [u8_strconv_from_locale((char*)0);],
82 [no, consider installing GNU libunistring])
84 if test $HAVE_LIBUNISTRING = yes; then
85 dnl Determine the installed version.
86 AC_CACHE_CHECK([for libunistring version], [gl_cv_libunistring_version],
87 [AC_COMPUTE_INT([gl_libunistring_hexversion],
88 [_LIBUNISTRING_VERSION],
89 [#include <unistring/version.h>])
90 dnl Versions <= 0.9.3 had a hexversion of 0x0009.
91 dnl Use other tests to distinguish them.
92 if test $gl_libunistring_hexversion = 9; then
93 dnl Version 0.9.2 introduced the header <unistring/cdefs.h>.
94 AC_TRY_COMPILE([#include <unistring/cdefs.h>], ,
95 [gl_cv_libunistring_version092=true],
96 [gl_cv_libunistring_version092=false]);
97 if $gl_cv_libunistring_version092; then
98 dnl Version 0.9.3 changed a comment in <unistr.h>.
99 gl_ABSOLUTE_HEADER_ONE([unistr.h])
100 if test -n "$gl_cv_absolute_unistr_h" \
101 && grep 'Copy no more than N units of SRC to DEST. Return a pointer' $gl_cv_absolute_unistr_h > /dev/null; then
102 dnl Detected version 0.9.3.
103 gl_libunistring_hexversion=2307
105 dnl Detected version 0.9.2.
106 gl_libunistring_hexversion=2306
109 dnl Version 0.9.1 introduced the type casing_suffix_context_t.
110 AC_TRY_COMPILE([#include <unicase.h>
111 casing_suffix_context_t ct;], ,
112 [gl_cv_libunistring_version091=true],
113 [gl_cv_libunistring_version091=false])
114 if $gl_cv_libunistring_version091; then
115 dnl Detected version 0.9.1.
116 gl_libunistring_hexversion=2305
118 dnl Detected version 0.9.
119 gl_libunistring_hexversion=2304
123 dnl Transform into the usual major.minor.subminor notation.
124 gl_libunistring_major=`expr $gl_libunistring_hexversion / 65536`
125 gl_libunistring_minor=`expr $gl_libunistring_hexversion / 256 % 256`
126 gl_libunistring_subminor=`expr $gl_libunistring_hexversion % 256`
127 gl_cv_libunistring_version="$gl_libunistring_major.$gl_libunistring_minor.$gl_libunistring_subminor"
129 LIBUNISTRING_VERSION="$gl_cv_libunistring_version"