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