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