1 ##### http://autoconf-archive.cryp.to/ax_lib_expat.html
5 # AX_LIB_EXPAT([MINIMUM-VERSION])
9 # This macro provides tests of availability of Expat XML Parser of
10 # particular version or newer. This macro checks for Expat XML Parser
11 # headers and libraries and defines compilation flags
13 # Macro supports following options and their values:
15 # 1) Single-option usage:
17 # --with-expat -- yes, no, or path to Expat XML Parser
20 # 2) Three-options usage (all options are required):
23 # --with-expat-inc -- path to base directory with Expat headers
24 # --with-expat-lib -- linker flags for Expat
28 # AC_SUBST(EXPAT_CFLAGS)
29 # AC_SUBST(EXPAT_LDFLAGS)
30 # AC_SUBST(EXPAT_VERSION) -- only if version requirement is used
42 # Copyright (c) 2007 Mateusz Loskot <mateusz@loskot.net>
44 # Copying and distribution of this file, with or without
45 # modification, are permitted in any medium without royalty provided
46 # the copyright notice and this notice are preserved.
48 AC_DEFUN([AX_LIB_EXPAT],
51 AC_HELP_STRING([--with-expat=@<:@ARG@:>@],
52 [use Expat XML Parser from given prefix (ARG=path); check standard prefixes (ARG=yes); disable (ARG=no)]
55 if test "$withval" = "yes"; then
56 if test -f /usr/local/include/expat.h ; then
57 expat_prefix=/usr/local
58 elif test -f /usr/include/expat.h ; then
64 elif test -d "$withval"; then
65 expat_prefix="$withval"
73 # dnl Default behavior is implicit yes
74 # if test -f /usr/local/include/expat.h ; then
75 # expat_prefix=/usr/local
76 # elif test -f /usr/include/expat.h ; then
81 dnl Default behavior is implicit no
87 AC_ARG_WITH([expat-inc],
88 AC_HELP_STRING([--with-expat-inc=@<:@DIR@:>@],
89 [path to Expat XML Parser headers]
91 [expat_include_dir="$withval"],
92 [expat_include_dir=""]
94 AC_ARG_WITH([expat-lib],
95 AC_HELP_STRING([--with-expat-lib=@<:@ARG@:>@],
96 [link options for Expat XML Parser libraries]
98 [expat_lib_flags="$withval"],
107 dnl Collect include/lib paths and flags
111 if test -n "$expat_prefix"; then
112 expat_include_dir="$expat_prefix/include"
113 expat_lib_flags="-L$expat_prefix/lib64 -L$expat_prefix/lib -lexpat"
115 elif test "$expat_requested" = "yes"; then
116 if test -n "$expat_include_dir" -a -n "$expat_lib_flags"; then
124 dnl Check Expat XML Parser files
126 if test "$run_expat_test" = "yes"; then
128 saved_CPPFLAGS="$CPPFLAGS"
129 CPPFLAGS="$CPPFLAGS -I$expat_include_dir"
131 saved_LDFLAGS="$LDFLAGS"
132 LDFLAGS="$LDFLAGS $expat_lib_flags"
135 dnl Check Expat headers
137 AC_MSG_CHECKING([for Expat XML Parser headers in $expat_include_dir])
143 @%:@include <expat.h>
148 EXPAT_CFLAGS="-I$expat_include_dir"
149 expat_header_found="yes"
150 AC_MSG_RESULT([found])
153 expat_header_found="no"
154 AC_MSG_RESULT([not found])
160 dnl Check Expat libraries
162 if test "$expat_header_found" = "yes"; then
164 AC_MSG_CHECKING([for Expat XML Parser libraries])
170 @%:@include <expat.h>
173 XML_Parser p = XML_ParserCreate(NULL);
179 EXPAT_LDFLAGS="$expat_lib_flags"
180 expat_lib_found="yes"
181 AC_MSG_RESULT([found])
185 AC_MSG_RESULT([not found])
191 CPPFLAGS="$saved_CPPFLAGS"
192 LDFLAGS="$saved_LDFLAGS"
195 AC_MSG_CHECKING([for Expat XML Parser])
197 if test "$run_expat_test" = "yes"; then
198 if test "$expat_header_found" = "yes" -a "$expat_lib_found" = "yes"; then
200 AC_SUBST([EXPAT_CFLAGS])
201 AC_SUBST([EXPAT_LDFLAGS])
208 AC_MSG_RESULT([$HAVE_EXPAT])
211 dnl Check Expat version
213 if test "$HAVE_EXPAT" = "yes"; then
215 expat_version_req=ifelse([$1], [], [], [$1])
217 if test -n "$expat_version_req"; then
219 AC_MSG_CHECKING([if Expat XML Parser version is >= $expat_version_req])
221 if test -f "$expat_include_dir/expat.h"; then
223 expat_major=`cat $expat_include_dir/expat.h | \
224 grep '^#define.*XML_MAJOR_VERSION.*[0-9]$' | \
225 sed -e 's/#define XML_MAJOR_VERSION.//'`
227 expat_minor=`cat $expat_include_dir/expat.h | \
228 grep '^#define.*XML_MINOR_VERSION.*[0-9]$' | \
229 sed -e 's/#define XML_MINOR_VERSION.//'`
231 expat_revision=`cat $expat_include_dir/expat.h | \
232 grep '^#define.*XML_MICRO_VERSION.*[0-9]$' | \
233 sed -e 's/#define XML_MICRO_VERSION.//'`
235 EXPAT_VERSION="$expat_major.$expat_minor.$expat_revision"
236 AC_SUBST([EXPAT_VERSION])
238 dnl Decompose required version string and calculate numerical representation
239 expat_version_req_major=`expr $expat_version_req : '\([[0-9]]*\)'`
240 expat_version_req_minor=`expr $expat_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
241 expat_version_req_revision=`expr $expat_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
242 if test "x$expat_version_req_revision" = "x"; then
243 expat_version_req_revision="0"
246 expat_version_req_number=`expr $expat_version_req_major \* 10000 \
247 \+ $expat_version_req_minor \* 100 \
248 \+ $expat_version_req_revision`
250 dnl Calculate numerical representation of detected version
251 expat_version_number=`expr $expat_major \* 10000 \
252 \+ $expat_minor \* 100 \
255 expat_version_check=`expr $expat_version_number \>\= $expat_version_req_number`
256 if test "$expat_version_check" = "1"; then
260 AC_MSG_WARN([Found Expat XML Parser $EXPAT_VERSION, which is older than required. Possible compilation failure.])
264 AC_MSG_WARN([Missing expat.h header. Unable to determine Expat version.])
271 AC_MSG_RESULT([$HAVE_EXPAT])
273 if test "$expat_requested" = "yes"; then
274 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])
277 if test "$HAVE_EXPAT" = "yes"; then
278 CPPFLAGS="$CPPFLAGS $EXPAT_CFLAGS -DHAVE_EXPAT=1"
279 LDFLAGS="$LDFLAGS $EXPAT_LDFLAGS"