Debian Codegraph @

config/ax_lib_expat.m4

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