Blame libxml.m4

Packit 423ecb
# Configure paths for LIBXML2
Packit 423ecb
# Mike Hommey 2004-06-19
Packit 423ecb
# use CPPFLAGS instead of CFLAGS
Packit 423ecb
# Toshio Kuratomi 2001-04-21
Packit 423ecb
# Adapted from:
Packit 423ecb
# Configure paths for GLIB
Packit 423ecb
# Owen Taylor     97-11-3
Packit 423ecb
Packit 423ecb
dnl AM_PATH_XML2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
Packit 423ecb
dnl Test for XML, and define XML_CPPFLAGS and XML_LIBS
Packit 423ecb
dnl
Packit 423ecb
AC_DEFUN([AM_PATH_XML2],[ 
Packit 423ecb
AC_ARG_WITH(xml-prefix,
Packit 423ecb
            [  --with-xml-prefix=PFX   Prefix where libxml is installed (optional)],
Packit 423ecb
            xml_config_prefix="$withval", xml_config_prefix="")
Packit 423ecb
AC_ARG_WITH(xml-exec-prefix,
Packit 423ecb
            [  --with-xml-exec-prefix=PFX Exec prefix where libxml is installed (optional)],
Packit 423ecb
            xml_config_exec_prefix="$withval", xml_config_exec_prefix="")
Packit 423ecb
AC_ARG_ENABLE(xmltest,
Packit 423ecb
              [  --disable-xmltest       Do not try to compile and run a test LIBXML program],,
Packit 423ecb
              enable_xmltest=yes)
Packit 423ecb
Packit 423ecb
  if test x$xml_config_exec_prefix != x ; then
Packit 423ecb
     xml_config_args="$xml_config_args"
Packit 423ecb
     if test x${XML2_CONFIG+set} != xset ; then
Packit 423ecb
        XML2_CONFIG=$xml_config_exec_prefix/bin/xml2-config
Packit 423ecb
     fi
Packit 423ecb
  fi
Packit 423ecb
  if test x$xml_config_prefix != x ; then
Packit 423ecb
     xml_config_args="$xml_config_args --prefix=$xml_config_prefix"
Packit 423ecb
     if test x${XML2_CONFIG+set} != xset ; then
Packit 423ecb
        XML2_CONFIG=$xml_config_prefix/bin/xml2-config
Packit 423ecb
     fi
Packit 423ecb
  fi
Packit 423ecb
Packit 423ecb
  AC_PATH_PROG(XML2_CONFIG, xml2-config, no)
Packit 423ecb
  min_xml_version=ifelse([$1], ,2.0.0,[$1])
Packit 423ecb
  AC_MSG_CHECKING(for libxml - version >= $min_xml_version)
Packit 423ecb
  no_xml=""
Packit 423ecb
  if test "$XML2_CONFIG" = "no" ; then
Packit 423ecb
    no_xml=yes
Packit 423ecb
  else
Packit 423ecb
    XML_CPPFLAGS=`$XML2_CONFIG $xml_config_args --cflags`
Packit 423ecb
    XML_LIBS=`$XML2_CONFIG $xml_config_args --libs`
Packit 423ecb
    xml_config_major_version=`$XML2_CONFIG $xml_config_args --version | \
Packit 423ecb
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
Packit 423ecb
    xml_config_minor_version=`$XML2_CONFIG $xml_config_args --version | \
Packit 423ecb
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
Packit 423ecb
    xml_config_micro_version=`$XML2_CONFIG $xml_config_args --version | \
Packit 423ecb
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
Packit 423ecb
    if test "x$enable_xmltest" = "xyes" ; then
Packit 423ecb
      ac_save_CPPFLAGS="$CPPFLAGS"
Packit 423ecb
      ac_save_LIBS="$LIBS"
Packit 423ecb
      CPPFLAGS="$CPPFLAGS $XML_CPPFLAGS"
Packit 423ecb
      LIBS="$XML_LIBS $LIBS"
Packit 423ecb
dnl
Packit 423ecb
dnl Now check if the installed libxml is sufficiently new.
Packit 423ecb
dnl (Also sanity checks the results of xml2-config to some extent)
Packit 423ecb
dnl
Packit 423ecb
      rm -f conf.xmltest
Packit 423ecb
      AC_TRY_RUN([
Packit 423ecb
#include <stdlib.h>
Packit 423ecb
#include <stdio.h>
Packit 423ecb
#include <string.h>
Packit 423ecb
#include <libxml/xmlversion.h>
Packit 423ecb
Packit 423ecb
int 
Packit 423ecb
main()
Packit 423ecb
{
Packit 423ecb
  int xml_major_version, xml_minor_version, xml_micro_version;
Packit 423ecb
  int major, minor, micro;
Packit 423ecb
  char *tmp_version;
Packit 423ecb
Packit 423ecb
  system("touch conf.xmltest");
Packit 423ecb
Packit 423ecb
  /* Capture xml2-config output via autoconf/configure variables */
Packit 423ecb
  /* HP/UX 9 (%@#!) writes to sscanf strings */
Packit 423ecb
  tmp_version = (char *)strdup("$min_xml_version");
Packit 423ecb
  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
Packit 423ecb
     printf("%s, bad version string from xml2-config\n", "$min_xml_version");
Packit 423ecb
     exit(1);
Packit 423ecb
   }
Packit 423ecb
   free(tmp_version);
Packit 423ecb
Packit 423ecb
   /* Capture the version information from the header files */
Packit 423ecb
   tmp_version = (char *)strdup(LIBXML_DOTTED_VERSION);
Packit 423ecb
   if (sscanf(tmp_version, "%d.%d.%d", &xml_major_version, &xml_minor_version, &xml_micro_version) != 3) {
Packit 423ecb
     printf("%s, bad version string from libxml includes\n", "LIBXML_DOTTED_VERSION");
Packit 423ecb
     exit(1);
Packit 423ecb
   }
Packit 423ecb
   free(tmp_version);
Packit 423ecb
Packit 423ecb
 /* Compare xml2-config output to the libxml headers */
Packit 423ecb
  if ((xml_major_version != $xml_config_major_version) ||
Packit 423ecb
      (xml_minor_version != $xml_config_minor_version) ||
Packit 423ecb
      (xml_micro_version != $xml_config_micro_version))
Packit 423ecb
    {
Packit 423ecb
      printf("*** libxml header files (version %d.%d.%d) do not match\n",
Packit 423ecb
         xml_major_version, xml_minor_version, xml_micro_version);
Packit 423ecb
      printf("*** xml2-config (version %d.%d.%d)\n",
Packit 423ecb
         $xml_config_major_version, $xml_config_minor_version, $xml_config_micro_version);
Packit 423ecb
      return 1;
Packit 423ecb
    } 
Packit 423ecb
/* Compare the headers to the library to make sure we match */
Packit 423ecb
  /* Less than ideal -- doesn't provide us with return value feedback, 
Packit 423ecb
   * only exits if there's a serious mismatch between header and library.
Packit 423ecb
   */
Packit 423ecb
    LIBXML_TEST_VERSION;
Packit 423ecb
Packit 423ecb
    /* Test that the library is greater than our minimum version */
Packit 423ecb
    if ((xml_major_version > major) ||
Packit 423ecb
        ((xml_major_version == major) && (xml_minor_version > minor)) ||
Packit 423ecb
        ((xml_major_version == major) && (xml_minor_version == minor) &&
Packit 423ecb
        (xml_micro_version >= micro)))
Packit 423ecb
      {
Packit 423ecb
        return 0;
Packit 423ecb
       }
Packit 423ecb
     else
Packit 423ecb
      {
Packit 423ecb
        printf("\n*** An old version of libxml (%d.%d.%d) was found.\n",
Packit 423ecb
               xml_major_version, xml_minor_version, xml_micro_version);
Packit 423ecb
        printf("*** You need a version of libxml newer than %d.%d.%d. The latest version of\n",
Packit 423ecb
           major, minor, micro);
Packit 423ecb
        printf("*** libxml is always available from ftp://ftp.xmlsoft.org.\n");
Packit 423ecb
        printf("***\n");
Packit 423ecb
        printf("*** If you have already installed a sufficiently new version, this error\n");
Packit 423ecb
        printf("*** probably means that the wrong copy of the xml2-config shell script is\n");
Packit 423ecb
        printf("*** being found. The easiest way to fix this is to remove the old version\n");
Packit 423ecb
        printf("*** of LIBXML, but you can also set the XML2_CONFIG environment to point to the\n");
Packit 423ecb
        printf("*** correct copy of xml2-config. (In this case, you will have to\n");
Packit 423ecb
        printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
Packit 423ecb
        printf("*** so that the correct libraries are found at run-time))\n");
Packit 423ecb
    }
Packit 423ecb
  return 1;
Packit 423ecb
}
Packit 423ecb
],, no_xml=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
Packit 423ecb
       CPPFLAGS="$ac_save_CPPFLAGS"
Packit 423ecb
       LIBS="$ac_save_LIBS"
Packit 423ecb
     fi
Packit 423ecb
  fi
Packit 423ecb
Packit 423ecb
  if test "x$no_xml" = x ; then
Packit 423ecb
     AC_MSG_RESULT(yes (version $xml_config_major_version.$xml_config_minor_version.$xml_config_micro_version))
Packit 423ecb
     ifelse([$2], , :, [$2])     
Packit 423ecb
  else
Packit 423ecb
     AC_MSG_RESULT(no)
Packit 423ecb
     if test "$XML2_CONFIG" = "no" ; then
Packit 423ecb
       echo "*** The xml2-config script installed by LIBXML could not be found"
Packit 423ecb
       echo "*** If libxml was installed in PREFIX, make sure PREFIX/bin is in"
Packit 423ecb
       echo "*** your path, or set the XML2_CONFIG environment variable to the"
Packit 423ecb
       echo "*** full path to xml2-config."
Packit 423ecb
     else
Packit 423ecb
       if test -f conf.xmltest ; then
Packit 423ecb
        :
Packit 423ecb
       else
Packit 423ecb
          echo "*** Could not run libxml test program, checking why..."
Packit 423ecb
          CPPFLAGS="$CPPFLAGS $XML_CPPFLAGS"
Packit 423ecb
          LIBS="$LIBS $XML_LIBS"
Packit 423ecb
          AC_TRY_LINK([
Packit 423ecb
#include <libxml/xmlversion.h>
Packit 423ecb
#include <stdio.h>
Packit 423ecb
],      [ LIBXML_TEST_VERSION; return 0;],
Packit 423ecb
        [ echo "*** The test program compiled, but did not run. This usually means"
Packit 423ecb
          echo "*** that the run-time linker is not finding LIBXML or finding the wrong"
Packit 423ecb
          echo "*** version of LIBXML. If it is not finding LIBXML, you'll need to set your"
Packit 423ecb
          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
Packit 423ecb
          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
Packit 423ecb
          echo "*** is required on your system"
Packit 423ecb
          echo "***"
Packit 423ecb
          echo "*** If you have an old version installed, it is best to remove it, although"
Packit 423ecb
          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH" ],
Packit 423ecb
        [ echo "*** The test program failed to compile or link. See the file config.log for the"
Packit 423ecb
          echo "*** exact error that occurred. This usually means LIBXML was incorrectly installed"
Packit 423ecb
          echo "*** or that you have moved LIBXML since it was installed. In the latter case, you"
Packit 423ecb
          echo "*** may want to edit the xml2-config script: $XML2_CONFIG" ])
Packit 423ecb
          CPPFLAGS="$ac_save_CPPFLAGS"
Packit 423ecb
          LIBS="$ac_save_LIBS"
Packit 423ecb
       fi
Packit 423ecb
     fi
Packit 423ecb
Packit 423ecb
     XML_CPPFLAGS=""
Packit 423ecb
     XML_LIBS=""
Packit 423ecb
     ifelse([$3], , :, [$3])
Packit 423ecb
  fi
Packit 423ecb
  AC_SUBST(XML_CPPFLAGS)
Packit 423ecb
  AC_SUBST(XML_LIBS)
Packit 423ecb
  rm -f conf.xmltest
Packit 423ecb
])