adam@1: # =========================================================================== adam@1: # http://www.gnu.org/software/autoconf-archive/ax_lib_expat.html adam@1: # =========================================================================== adam@1: # adam@1: # SYNOPSIS adam@1: # adam@1: # AX_LIB_EXPAT([MINIMUM-VERSION]) adam@1: # adam@1: # DESCRIPTION adam@1: # adam@1: # This macro provides tests of availability of Expat XML Parser of adam@1: # particular version or newer. This macro checks for Expat XML Parser adam@1: # headers and libraries and defines compilation flags adam@1: # adam@1: # Macro supports following options and their values: adam@1: # adam@1: # 1) Single-option usage: adam@1: # adam@1: # --with-expat -- yes, no, or path to Expat XML Parser adam@1: # installation prefix adam@1: # adam@1: # 2) Three-options usage (all options are required): adam@1: # adam@1: # --with-expat=yes adam@1: # --with-expat-inc -- path to base directory with Expat headers adam@1: # --with-expat-lib -- linker flags for Expat adam@1: # adam@1: # This macro calls: adam@1: # adam@1: # AC_SUBST(EXPAT_CFLAGS) adam@1: # AC_SUBST(EXPAT_LDFLAGS) adam@1: # AC_SUBST(EXPAT_VERSION) -- only if version requirement is used adam@1: # adam@1: # And sets: adam@1: # adam@1: # HAVE_EXPAT adam@1: # adam@1: # LICENSE adam@1: # adam@1: # Copyright (c) 2008 Mateusz Loskot adam@1: # adam@1: # Copying and distribution of this file, with or without modification, are adam@1: # permitted in any medium without royalty provided the copyright notice adam@1: # and this notice are preserved. This file is offered as-is, without any adam@1: # warranty. adam@1: adam@1: #serial 8 adam@1: adam@1: AC_DEFUN([AX_LIB_EXPAT], adam@1: [ adam@1: AC_ARG_WITH([expat], adam@1: AS_HELP_STRING([--with-expat=@<:@ARG@:>@], adam@1: [use Expat XML Parser from given prefix (ARG=path); check standard prefixes (ARG=yes); disable (ARG=no)] adam@1: ), adam@1: [ adam@1: if test "$withval" = "yes"; then adam@1: if test -f /usr/local/include/expat.h ; then adam@1: expat_prefix=/usr/local adam@1: elif test -f /usr/include/expat.h ; then adam@1: expat_prefix=/usr adam@1: else adam@1: expat_prefix="" adam@1: fi adam@1: expat_requested="yes" adam@1: elif test -d "$withval"; then adam@1: expat_prefix="$withval" adam@1: expat_requested="yes" adam@1: else adam@1: expat_prefix="" adam@1: expat_requested="no" adam@1: fi adam@1: ], adam@1: [ adam@1: dnl Default behavior is implicit yes adam@1: if test -f /usr/local/include/expat.h ; then adam@1: expat_prefix=/usr/local adam@1: elif test -f /usr/include/expat.h ; then adam@1: expat_prefix=/usr adam@1: else adam@1: expat_prefix="" adam@1: fi adam@1: ] adam@1: ) adam@1: adam@1: AC_ARG_WITH([expat-inc], adam@1: AS_HELP_STRING([--with-expat-inc=@<:@DIR@:>@], adam@1: [path to Expat XML Parser headers] adam@1: ), adam@1: [expat_include_dir="$withval"], adam@1: [expat_include_dir=""] adam@1: ) adam@1: AC_ARG_WITH([expat-lib], adam@1: AS_HELP_STRING([--with-expat-lib=@<:@ARG@:>@], adam@1: [link options for Expat XML Parser libraries] adam@1: ), adam@1: [expat_lib_flags="$withval"], adam@1: [expat_lib_flags=""] adam@1: ) adam@1: adam@1: EXPAT_CFLAGS="" adam@1: EXPAT_LDFLAGS="" adam@1: EXPAT_VERSION="" adam@1: adam@1: dnl adam@1: dnl Collect include/lib paths and flags adam@1: dnl adam@1: run_expat_test="no" adam@1: adam@1: if test -n "$expat_prefix"; then adam@1: expat_include_dir="$expat_prefix/include" adam@1: expat_lib_flags="-L$expat_prefix/lib -lexpat" adam@1: run_expat_test="yes" adam@1: elif test "$expat_requested" = "yes"; then adam@1: if test -n "$expat_include_dir" -a -n "$expat_lib_flags"; then adam@1: run_expat_test="yes" adam@1: fi adam@1: else adam@1: run_expat_test="no" adam@1: fi adam@1: adam@1: dnl adam@1: dnl Check Expat XML Parser files adam@1: dnl adam@1: if test "$run_expat_test" = "yes"; then adam@1: adam@1: saved_CPPFLAGS="$CPPFLAGS" adam@1: CPPFLAGS="$CPPFLAGS -I$expat_include_dir" adam@1: adam@1: saved_LDFLAGS="$LDFLAGS" adam@1: LDFLAGS="$LDFLAGS $expat_lib_flags" adam@1: adam@1: dnl adam@1: dnl Check Expat headers adam@1: dnl adam@1: AC_MSG_CHECKING([for Expat XML Parser headers in $expat_include_dir]) adam@1: adam@1: AC_LANG_PUSH([C++]) adam@1: AC_COMPILE_IFELSE([ adam@1: AC_LANG_PROGRAM( adam@1: [[ adam@1: @%:@include adam@1: ]], adam@1: [[]] adam@1: )], adam@1: [ adam@1: EXPAT_CFLAGS="-I$expat_include_dir" adam@1: expat_header_found="yes" adam@1: AC_MSG_RESULT([found]) adam@1: ], adam@1: [ adam@1: expat_header_found="no" adam@1: AC_MSG_RESULT([not found]) adam@1: ] adam@1: ) adam@1: AC_LANG_POP([C++]) adam@1: adam@1: dnl adam@1: dnl Check Expat libraries adam@1: dnl adam@1: if test "$expat_header_found" = "yes"; then adam@1: adam@1: AC_MSG_CHECKING([for Expat XML Parser libraries]) adam@1: adam@1: AC_LANG_PUSH([C++]) adam@1: AC_LINK_IFELSE([ adam@1: AC_LANG_PROGRAM( adam@1: [[ adam@1: @%:@include adam@1: ]], adam@1: [[ adam@1: XML_Parser p = XML_ParserCreate(NULL); adam@1: XML_ParserFree(p); adam@1: p = NULL; adam@1: ]] adam@1: )], adam@1: [ adam@1: EXPAT_LDFLAGS="$expat_lib_flags" adam@1: expat_lib_found="yes" adam@1: AC_MSG_RESULT([found]) adam@1: ], adam@1: [ adam@1: expat_lib_found="no" adam@1: AC_MSG_RESULT([not found]) adam@1: ] adam@1: ) adam@1: AC_LANG_POP([C++]) adam@1: fi adam@1: adam@1: CPPFLAGS="$saved_CPPFLAGS" adam@1: LDFLAGS="$saved_LDFLAGS" adam@1: fi adam@1: adam@1: AC_MSG_CHECKING([for Expat XML Parser]) adam@1: adam@1: if test "$run_expat_test" = "yes"; then adam@1: if test "$expat_header_found" = "yes" -a "$expat_lib_found" = "yes"; then adam@1: adam@1: AC_SUBST([EXPAT_CFLAGS]) adam@1: AC_SUBST([EXPAT_LDFLAGS]) adam@1: adam@1: HAVE_EXPAT="yes" adam@1: else adam@1: HAVE_EXPAT="no" adam@1: fi adam@1: adam@1: AC_MSG_RESULT([$HAVE_EXPAT]) adam@1: adam@1: dnl adam@1: dnl Check Expat version adam@1: dnl adam@1: if test "$HAVE_EXPAT" = "yes"; then adam@1: adam@1: expat_version_req=ifelse([$1], [], [], [$1]) adam@1: adam@1: if test -n "$expat_version_req"; then adam@1: adam@1: AC_MSG_CHECKING([if Expat XML Parser version is >= $expat_version_req]) adam@1: adam@1: if test -f "$expat_include_dir/expat.h"; then adam@1: adam@1: expat_major=`cat $expat_include_dir/expat.h | \ adam@1: grep '^#define.*XML_MAJOR_VERSION.*[0-9]$' | \ adam@1: sed -e 's/#define XML_MAJOR_VERSION.//'` adam@1: adam@1: expat_minor=`cat $expat_include_dir/expat.h | \ adam@1: grep '^#define.*XML_MINOR_VERSION.*[0-9]$' | \ adam@1: sed -e 's/#define XML_MINOR_VERSION.//'` adam@1: adam@1: expat_revision=`cat $expat_include_dir/expat.h | \ adam@1: grep '^#define.*XML_MICRO_VERSION.*[0-9]$' | \ adam@1: sed -e 's/#define XML_MICRO_VERSION.//'` adam@1: adam@1: EXPAT_VERSION="$expat_major.$expat_minor.$expat_revision" adam@1: AC_SUBST([EXPAT_VERSION]) adam@1: adam@1: dnl Decompose required version string and calculate numerical representation adam@1: expat_version_req_major=`expr $expat_version_req : '\([[0-9]]*\)'` adam@1: expat_version_req_minor=`expr $expat_version_req : '[[0-9]]*\.\([[0-9]]*\)'` adam@1: expat_version_req_revision=`expr $expat_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` adam@1: if test "x$expat_version_req_revision" = "x"; then adam@1: expat_version_req_revision="0" adam@1: fi adam@1: adam@1: expat_version_req_number=`expr $expat_version_req_major \* 10000 \ adam@1: \+ $expat_version_req_minor \* 100 \ adam@1: \+ $expat_version_req_revision` adam@1: adam@1: dnl Calculate numerical representation of detected version adam@1: expat_version_number=`expr $expat_major \* 10000 \ adam@1: \+ $expat_minor \* 100 \ adam@1: \+ $expat_revision` adam@1: adam@1: expat_version_check=`expr $expat_version_number \>\= $expat_version_req_number` adam@1: if test "$expat_version_check" = "1"; then adam@1: AC_MSG_RESULT([yes]) adam@1: else adam@1: AC_MSG_RESULT([no]) adam@1: AC_MSG_WARN([Found Expat XML Parser $EXPAT_VERSION, which is older than required. Possible compilation failure.]) adam@1: fi adam@1: else adam@1: AC_MSG_RESULT([no]) adam@1: AC_MSG_WARN([Missing expat.h header. Unable to determine Expat version.]) adam@1: fi adam@1: fi adam@1: fi adam@1: adam@1: else adam@1: HAVE_EXPAT="no" adam@1: AC_MSG_RESULT([$HAVE_EXPAT]) adam@1: adam@1: if test "$expat_requested" = "yes"; then adam@1: 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: fi adam@1: fi adam@1: ])