aboutsummaryrefslogtreecommitdiff
path: root/m4/libunistring.m4
diff options
context:
space:
mode:
Diffstat (limited to 'm4/libunistring.m4')
-rw-r--r--m4/libunistring.m4150
1 files changed, 150 insertions, 0 deletions
diff --git a/m4/libunistring.m4 b/m4/libunistring.m4
new file mode 100644
index 000000000..c1bf4d553
--- /dev/null
+++ b/m4/libunistring.m4
@@ -0,0 +1,150 @@
1# libunistring.m4 serial 11
2dnl Copyright (C) 2009-2012 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl gl_LIBUNISTRING
8dnl Searches for an installed libunistring.
9dnl If found, it sets and AC_SUBSTs HAVE_LIBUNISTRING=yes and the LIBUNISTRING
10dnl and LTLIBUNISTRING variables, sets the LIBUNISTRING_VERSION variable, and
11dnl augments the CPPFLAGS variable, and #defines HAVE_LIBUNISTRING to 1.
12dnl Otherwise, it sets and AC_SUBSTs HAVE_LIBUNISTRING=no and LIBUNISTRING and
13dnl LTLIBUNISTRING to empty.
14
15dnl Define gl_LIBUNISTRING using AC_DEFUN_ONCE for Autoconf >= 2.64, in order
16dnl to avoid warnings like
17dnl "warning: AC_REQUIRE: `gl_LIBUNISTRING' was expanded before it was required".
18dnl This is tricky because of the way 'aclocal' is implemented:
19dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
20dnl Otherwise aclocal's initial scan pass would miss the macro definition.
21dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
22dnl Otherwise aclocal would emit many "Use of uninitialized value $1"
23dnl warnings.
24m4_define([gl_libunistring_AC_DEFUN],
25 m4_version_prereq([2.64],
26 [[AC_DEFUN_ONCE(
27 [$1], [$2])]],
28 [m4_ifdef([gl_00GNULIB],
29 [[AC_DEFUN_ONCE(
30 [$1], [$2])]],
31 [[AC_DEFUN(
32 [$1], [$2])]])]))
33gl_libunistring_AC_DEFUN([gl_LIBUNISTRING],
34[
35 AC_BEFORE([$0], [gl_LIBUNISTRING_MODULE])
36 AC_BEFORE([$0], [gl_LIBUNISTRING_LIBHEADER])
37 AC_BEFORE([$0], [gl_LIBUNISTRING_LIB_PREPARE])
38
39 m4_ifdef([gl_LIBUNISTRING_OPTIONAL],
40 [
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
52 HAVE_LIBUNISTRING=no
53 fi
54 LIBUNISTRING=
55 LTLIBUNISTRING=
56 else
57 gl_LIBUNISTRING_CORE
58 if test $HAVE_LIBUNISTRING = no; then
59 gl_libunistring_use_included=yes
60 LIBUNISTRING=
61 LTLIBUNISTRING=
62 fi
63 fi
64 ],
65 [gl_LIBUNISTRING_CORE])
66])
67
68AC_DEFUN([gl_LIBUNISTRING_CORE],
69[
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"
91 fi
92 LIBS="$glus_save_LIBS"
93 fi
94 else
95 AC_LIB_HAVE_LINKFLAGS([unistring], [],
96 [#include <uniconv.h>], [u8_strconv_from_locale((char*)0);],
97 [no, consider installing GNU libunistring])
98 fi
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>.
109 AC_COMPILE_IFELSE(
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
120 else
121 dnl Detected version 0.9.2.
122 gl_libunistring_hexversion=2306
123 fi
124 else
125 dnl Version 0.9.1 introduced the type casing_suffix_context_t.
126 AC_COMPILE_IFELSE(
127 [AC_LANG_PROGRAM(
128 [[#include <unicase.h>
129 casing_suffix_context_t ct;]],
130 [[]])],
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
136 else
137 dnl Detected version 0.9.
138 gl_libunistring_hexversion=2304
139 fi
140 fi
141 fi
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"
147 ])
148 LIBUNISTRING_VERSION="$gl_cv_libunistring_version"
149 fi
150])