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
84 AC_ARG_WITH([expat-inc],
85 AC_HELP_STRING([--with-expat-inc=@<:@DIR@:>@],
86 [path to Expat XML Parser headers]
88 [expat_include_dir="$withval"],
89 [expat_include_dir=""]
91 AC_ARG_WITH([expat-lib],
92 AC_HELP_STRING([--with-expat-lib=@<:@ARG@:>@],
93 [link options for Expat XML Parser libraries]
95 [expat_lib_flags="$withval"],
104 dnl Collect include/lib paths and flags
108 if test -n "$expat_prefix"; then
109 expat_include_dir="$expat_prefix/include"
110 expat_lib_flags="-L$expat_prefix/lib -lexpat"
112 elif test "$expat_requested" = "yes"; then
113 if test -n "$expat_include_dir" -a -n "$expat_lib_flags"; then
121 dnl Check Expat XML Parser files
123 if test "$run_expat_test" = "yes"; then
125 saved_CPPFLAGS="$CPPFLAGS"
126 CPPFLAGS="$CPPFLAGS -I$expat_include_dir"
128 saved_LDFLAGS="$LDFLAGS"
129 LDFLAGS="$LDFLAGS $expat_lib_flags"
132 dnl Check Expat headers
134 AC_MSG_CHECKING([for Expat XML Parser headers in $expat_include_dir])
140 @%:@include <expat.h>
145 EXPAT_CFLAGS="-I$expat_include_dir"
146 expat_header_found="yes"
147 AC_MSG_RESULT([found])
150 expat_header_found="no"
151 AC_MSG_RESULT([not found])
157 dnl Check Expat libraries
159 if test "$expat_header_found" = "yes"; then
161 AC_MSG_CHECKING([for Expat XML Parser libraries])
167 @%:@include <expat.h>
170 XML_Parser p = XML_ParserCreate(NULL);
176 EXPAT_LDFLAGS="$expat_lib_flags"
177 expat_lib_found="yes"
178 AC_MSG_RESULT([found])
182 AC_MSG_RESULT([not found])
188 CPPFLAGS="$saved_CPPFLAGS"
189 LDFLAGS="$saved_LDFLAGS"
192 AC_MSG_CHECKING([for Expat XML Parser])
194 if test "$run_expat_test" = "yes"; then
195 if test "$expat_header_found" = "yes" -a "$expat_lib_found" = "yes"; then
197 AC_SUBST([EXPAT_CFLAGS])
198 AC_SUBST([EXPAT_LDFLAGS])
205 AC_MSG_RESULT([$HAVE_EXPAT])
208 dnl Check Expat version
210 if test "$HAVE_EXPAT" = "yes"; then
212 expat_version_req=ifelse([$1], [], [], [$1])
214 if test -n "$expat_version_req"; then
216 AC_MSG_CHECKING([if Expat XML Parser version is >= $expat_version_req])
218 if test -f "$expat_include_dir/expat.h"; then
220 expat_major=`cat $expat_include_dir/expat.h | \
221 grep '^#define.*XML_MAJOR_VERSION.*[0-9]$' | \
222 sed -e 's/#define XML_MAJOR_VERSION.//'`
224 expat_minor=`cat $expat_include_dir/expat.h | \
225 grep '^#define.*XML_MINOR_VERSION.*[0-9]$' | \
226 sed -e 's/#define XML_MINOR_VERSION.//'`
228 expat_revision=`cat $expat_include_dir/expat.h | \
229 grep '^#define.*XML_MICRO_VERSION.*[0-9]$' | \
230 sed -e 's/#define XML_MICRO_VERSION.//'`
232 EXPAT_VERSION="$expat_major.$expat_minor.$expat_revision"
233 AC_SUBST([EXPAT_VERSION])
235 dnl Decompose required version string and calculate numerical representation
236 expat_version_req_major=`expr $expat_version_req : '\([[0-9]]*\)'`
237 expat_version_req_minor=`expr $expat_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
238 expat_version_req_revision=`expr $expat_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
239 if test "x$expat_version_req_revision" = "x"; then
240 expat_version_req_revision="0"
243 expat_version_req_number=`expr $expat_version_req_major \* 10000 \
244 \+ $expat_version_req_minor \* 100 \
245 \+ $expat_version_req_revision`
247 dnl Calculate numerical representation of detected version
248 expat_version_number=`expr $expat_major \* 10000 \
249 \+ $expat_minor \* 100 \
252 expat_version_check=`expr $expat_version_number \>\= $expat_version_req_number`
253 if test "$expat_version_check" = "1"; then
257 AC_MSG_WARN([Found Expat XML Parser $EXPAT_VERSION, which is older than required. Possible compilation failure.])
261 AC_MSG_WARN([Missing expat.h header. Unable to determine Expat version.])
268 AC_MSG_RESULT([$HAVE_EXPAT])
270 if test "$expat_requested" = "yes"; then
271 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])