comparison m4/m4_ax_lib_expat.m4 @ 1:c230e6da3ff6

Discovered LiveJournal endpoint
author Adam Chlipala <adam@chlipala.net>
date Sun, 26 Dec 2010 13:10:36 -0500
parents
children
comparison
equal deleted inserted replaced
0:3c209338e596 1:c230e6da3ff6
1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_lib_expat.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 # AX_LIB_EXPAT([MINIMUM-VERSION])
8 #
9 # DESCRIPTION
10 #
11 # This macro provides tests of availability of Expat XML Parser of
12 # particular version or newer. This macro checks for Expat XML Parser
13 # headers and libraries and defines compilation flags
14 #
15 # Macro supports following options and their values:
16 #
17 # 1) Single-option usage:
18 #
19 # --with-expat -- yes, no, or path to Expat XML Parser
20 # installation prefix
21 #
22 # 2) Three-options usage (all options are required):
23 #
24 # --with-expat=yes
25 # --with-expat-inc -- path to base directory with Expat headers
26 # --with-expat-lib -- linker flags for Expat
27 #
28 # This macro calls:
29 #
30 # AC_SUBST(EXPAT_CFLAGS)
31 # AC_SUBST(EXPAT_LDFLAGS)
32 # AC_SUBST(EXPAT_VERSION) -- only if version requirement is used
33 #
34 # And sets:
35 #
36 # HAVE_EXPAT
37 #
38 # LICENSE
39 #
40 # Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net>
41 #
42 # Copying and distribution of this file, with or without modification, are
43 # permitted in any medium without royalty provided the copyright notice
44 # and this notice are preserved. This file is offered as-is, without any
45 # warranty.
46
47 #serial 8
48
49 AC_DEFUN([AX_LIB_EXPAT],
50 [
51 AC_ARG_WITH([expat],
52 AS_HELP_STRING([--with-expat=@<:@ARG@:>@],
53 [use Expat XML Parser from given prefix (ARG=path); check standard prefixes (ARG=yes); disable (ARG=no)]
54 ),
55 [
56 if test "$withval" = "yes"; then
57 if test -f /usr/local/include/expat.h ; then
58 expat_prefix=/usr/local
59 elif test -f /usr/include/expat.h ; then
60 expat_prefix=/usr
61 else
62 expat_prefix=""
63 fi
64 expat_requested="yes"
65 elif test -d "$withval"; then
66 expat_prefix="$withval"
67 expat_requested="yes"
68 else
69 expat_prefix=""
70 expat_requested="no"
71 fi
72 ],
73 [
74 dnl Default behavior is implicit yes
75 if test -f /usr/local/include/expat.h ; then
76 expat_prefix=/usr/local
77 elif test -f /usr/include/expat.h ; then
78 expat_prefix=/usr
79 else
80 expat_prefix=""
81 fi
82 ]
83 )
84
85 AC_ARG_WITH([expat-inc],
86 AS_HELP_STRING([--with-expat-inc=@<:@DIR@:>@],
87 [path to Expat XML Parser headers]
88 ),
89 [expat_include_dir="$withval"],
90 [expat_include_dir=""]
91 )
92 AC_ARG_WITH([expat-lib],
93 AS_HELP_STRING([--with-expat-lib=@<:@ARG@:>@],
94 [link options for Expat XML Parser libraries]
95 ),
96 [expat_lib_flags="$withval"],
97 [expat_lib_flags=""]
98 )
99
100 EXPAT_CFLAGS=""
101 EXPAT_LDFLAGS=""
102 EXPAT_VERSION=""
103
104 dnl
105 dnl Collect include/lib paths and flags
106 dnl
107 run_expat_test="no"
108
109 if test -n "$expat_prefix"; then
110 expat_include_dir="$expat_prefix/include"
111 expat_lib_flags="-L$expat_prefix/lib -lexpat"
112 run_expat_test="yes"
113 elif test "$expat_requested" = "yes"; then
114 if test -n "$expat_include_dir" -a -n "$expat_lib_flags"; then
115 run_expat_test="yes"
116 fi
117 else
118 run_expat_test="no"
119 fi
120
121 dnl
122 dnl Check Expat XML Parser files
123 dnl
124 if test "$run_expat_test" = "yes"; then
125
126 saved_CPPFLAGS="$CPPFLAGS"
127 CPPFLAGS="$CPPFLAGS -I$expat_include_dir"
128
129 saved_LDFLAGS="$LDFLAGS"
130 LDFLAGS="$LDFLAGS $expat_lib_flags"
131
132 dnl
133 dnl Check Expat headers
134 dnl
135 AC_MSG_CHECKING([for Expat XML Parser headers in $expat_include_dir])
136
137 AC_LANG_PUSH([C++])
138 AC_COMPILE_IFELSE([
139 AC_LANG_PROGRAM(
140 [[
141 @%:@include <expat.h>
142 ]],
143 [[]]
144 )],
145 [
146 EXPAT_CFLAGS="-I$expat_include_dir"
147 expat_header_found="yes"
148 AC_MSG_RESULT([found])
149 ],
150 [
151 expat_header_found="no"
152 AC_MSG_RESULT([not found])
153 ]
154 )
155 AC_LANG_POP([C++])
156
157 dnl
158 dnl Check Expat libraries
159 dnl
160 if test "$expat_header_found" = "yes"; then
161
162 AC_MSG_CHECKING([for Expat XML Parser libraries])
163
164 AC_LANG_PUSH([C++])
165 AC_LINK_IFELSE([
166 AC_LANG_PROGRAM(
167 [[
168 @%:@include <expat.h>
169 ]],
170 [[
171 XML_Parser p = XML_ParserCreate(NULL);
172 XML_ParserFree(p);
173 p = NULL;
174 ]]
175 )],
176 [
177 EXPAT_LDFLAGS="$expat_lib_flags"
178 expat_lib_found="yes"
179 AC_MSG_RESULT([found])
180 ],
181 [
182 expat_lib_found="no"
183 AC_MSG_RESULT([not found])
184 ]
185 )
186 AC_LANG_POP([C++])
187 fi
188
189 CPPFLAGS="$saved_CPPFLAGS"
190 LDFLAGS="$saved_LDFLAGS"
191 fi
192
193 AC_MSG_CHECKING([for Expat XML Parser])
194
195 if test "$run_expat_test" = "yes"; then
196 if test "$expat_header_found" = "yes" -a "$expat_lib_found" = "yes"; then
197
198 AC_SUBST([EXPAT_CFLAGS])
199 AC_SUBST([EXPAT_LDFLAGS])
200
201 HAVE_EXPAT="yes"
202 else
203 HAVE_EXPAT="no"
204 fi
205
206 AC_MSG_RESULT([$HAVE_EXPAT])
207
208 dnl
209 dnl Check Expat version
210 dnl
211 if test "$HAVE_EXPAT" = "yes"; then
212
213 expat_version_req=ifelse([$1], [], [], [$1])
214
215 if test -n "$expat_version_req"; then
216
217 AC_MSG_CHECKING([if Expat XML Parser version is >= $expat_version_req])
218
219 if test -f "$expat_include_dir/expat.h"; then
220
221 expat_major=`cat $expat_include_dir/expat.h | \
222 grep '^#define.*XML_MAJOR_VERSION.*[0-9]$' | \
223 sed -e 's/#define XML_MAJOR_VERSION.//'`
224
225 expat_minor=`cat $expat_include_dir/expat.h | \
226 grep '^#define.*XML_MINOR_VERSION.*[0-9]$' | \
227 sed -e 's/#define XML_MINOR_VERSION.//'`
228
229 expat_revision=`cat $expat_include_dir/expat.h | \
230 grep '^#define.*XML_MICRO_VERSION.*[0-9]$' | \
231 sed -e 's/#define XML_MICRO_VERSION.//'`
232
233 EXPAT_VERSION="$expat_major.$expat_minor.$expat_revision"
234 AC_SUBST([EXPAT_VERSION])
235
236 dnl Decompose required version string and calculate numerical representation
237 expat_version_req_major=`expr $expat_version_req : '\([[0-9]]*\)'`
238 expat_version_req_minor=`expr $expat_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
239 expat_version_req_revision=`expr $expat_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
240 if test "x$expat_version_req_revision" = "x"; then
241 expat_version_req_revision="0"
242 fi
243
244 expat_version_req_number=`expr $expat_version_req_major \* 10000 \
245 \+ $expat_version_req_minor \* 100 \
246 \+ $expat_version_req_revision`
247
248 dnl Calculate numerical representation of detected version
249 expat_version_number=`expr $expat_major \* 10000 \
250 \+ $expat_minor \* 100 \
251 \+ $expat_revision`
252
253 expat_version_check=`expr $expat_version_number \>\= $expat_version_req_number`
254 if test "$expat_version_check" = "1"; then
255 AC_MSG_RESULT([yes])
256 else
257 AC_MSG_RESULT([no])
258 AC_MSG_WARN([Found Expat XML Parser $EXPAT_VERSION, which is older than required. Possible compilation failure.])
259 fi
260 else
261 AC_MSG_RESULT([no])
262 AC_MSG_WARN([Missing expat.h header. Unable to determine Expat version.])
263 fi
264 fi
265 fi
266
267 else
268 HAVE_EXPAT="no"
269 AC_MSG_RESULT([$HAVE_EXPAT])
270
271 if test "$expat_requested" = "yes"; then
272 AC_MSG_WARN([Expat XML Parser support requested but headers or library not found. Specify valid prefix of Expat using --with-expat=@<:@DIR@:>@ or provide include directory and linker flags using --with-expat-inc and --with-expat-lib])
273 fi
274 fi
275 ])