annotate m4/m4_ax_lib_expat.m4 @ 38:8d23d76b5d48

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