neon-xml-parser.m4 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # Copyright (C) 1998-2005, 2007 Joe Orton <[email protected]> -*- autoconf -*-
  2. #
  3. # This file is free software; you may copy and/or distribute it with
  4. # or without modifications, as long as this notice is preserved.
  5. # This software is distributed in the hope that it will be useful, but
  6. # WITHOUT ANY WARRANTY, to the extent permitted by law; without even
  7. # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  8. # PURPOSE.
  9. # The above license applies to THIS FILE ONLY, the neon library code
  10. # itself may be copied and distributed under the terms of the GNU
  11. # LGPL, see COPYING.LIB for more details
  12. # This file is part of the neon HTTP/WebDAV client library.
  13. # See http://www.webdav.org/neon/ for the latest version.
  14. # Please send any feedback to <[email protected]>
  15. # Check for XML parser, supporting libxml 2.x and expat 1.95.x,
  16. # or a bundled copy of expat.
  17. # * Bundled expat if a directory name argument is passed
  18. # -> expat dir must contain minimal expat sources, i.e.
  19. # xmltok, xmlparse sub-directories. See sitecopy/cadaver for
  20. # examples of how to do this.
  21. #
  22. # Usage:
  23. # NEON_XML_PARSER()
  24. # or
  25. # NEON_XML_PARSER([expat-srcdir], [expat-builddir])
  26. dnl Find expat: run $1 if found, else $2
  27. AC_DEFUN([NE_XML_EXPAT], [
  28. AC_CHECK_HEADER(expat.h,
  29. [AC_CHECK_LIB(expat, XML_SetXmlDeclHandler, [
  30. AC_DEFINE(HAVE_EXPAT, 1, [Define if you have expat])
  31. neon_xml_parser_message="expat"
  32. NEON_LIBS="$NEON_LIBS -lexpat"
  33. neon_xml_parser=expat
  34. AC_CHECK_TYPE(XML_Size,
  35. [NEON_FORMAT(XML_Size, [#include <expat.h>])],
  36. [AC_DEFINE_UNQUOTED([NE_FMT_XML_SIZE], ["d"])],
  37. [#include <expat.h>])
  38. ], [$1])], [$1])
  39. ])
  40. dnl Find libxml2: run $1 if found, else $2
  41. AC_DEFUN([NE_XML_LIBXML2], [
  42. AC_CHECK_PROG(XML2_CONFIG, xml2-config, xml2-config)
  43. if test -n "$XML2_CONFIG"; then
  44. neon_xml_parser_message="libxml `$XML2_CONFIG --version`"
  45. AC_DEFINE(HAVE_LIBXML, 1, [Define if you have libxml])
  46. # xml2-config in some versions erroneously includes -I/include
  47. # in the --cflags output.
  48. CPPFLAGS="$CPPFLAGS `$XML2_CONFIG --cflags | sed 's| -I/include||g'`"
  49. NEON_LIBS="$NEON_LIBS `$XML2_CONFIG --libs | sed 's|-L/usr/lib ||g'`"
  50. AC_CHECK_HEADERS(libxml/xmlversion.h libxml/parser.h,,[
  51. AC_MSG_ERROR([could not find parser.h, libxml installation problem?])])
  52. neon_xml_parser=libxml2
  53. else
  54. $1
  55. fi
  56. ])
  57. dnl Configure for a bundled expat build.
  58. AC_DEFUN([NE_XML_BUNDLED_EXPAT], [
  59. AC_REQUIRE([AC_C_BIGENDIAN])
  60. # Define XML_BYTE_ORDER for expat sources.
  61. if test $ac_cv_c_bigendian = "yes"; then
  62. ne_xml_border=21
  63. else
  64. ne_xml_border=12
  65. fi
  66. # mini-expat doesn't pick up config.h
  67. CPPFLAGS="$CPPFLAGS -DXML_BYTE_ORDER=$ne_xml_border -DXML_DTD -I$1/xmlparse -I$1/xmltok"
  68. AC_DEFINE_UNQUOTED([NE_FMT_XML_SIZE], ["d"])
  69. # Use the bundled expat sources
  70. AC_LIBOBJ($2/xmltok/xmltok)
  71. AC_LIBOBJ($2/xmltok/xmlrole)
  72. AC_LIBOBJ($2/xmlparse/xmlparse)
  73. AC_LIBOBJ($2/xmlparse/hashtable)
  74. AC_DEFINE(HAVE_EXPAT)
  75. AC_DEFINE(HAVE_XMLPARSE_H, 1, [Define if using expat which includes xmlparse.h])
  76. ])
  77. AC_DEFUN([NEON_XML_PARSER], [
  78. dnl Switches to force choice of library
  79. AC_ARG_WITH([libxml2],
  80. AS_HELP_STRING([--with-libxml2], [force use of libxml 2.x]))
  81. AC_ARG_WITH([expat],
  82. AS_HELP_STRING([--with-expat], [force use of expat]))
  83. dnl Flag to force choice of included expat, if available.
  84. ifelse($#, 2, [
  85. AC_ARG_WITH([included-expat],
  86. AS_HELP_STRING([--with-included-expat], [use bundled expat sources]),,
  87. with_included_expat=no)],
  88. with_included_expat=no)
  89. if test "$NEON_NEED_XML_PARSER" = "yes"; then
  90. # Find an XML parser
  91. neon_xml_parser=none
  92. # Forced choice of expat:
  93. case $with_expat in
  94. yes) NE_XML_EXPAT([AC_MSG_ERROR([expat library not found, cannot proceed])]) ;;
  95. no) ;;
  96. */libexpat.la)
  97. # Special case for Subversion
  98. ne_expdir=`echo $with_expat | sed 's:/libexpat.la$::'`
  99. AC_DEFINE(HAVE_EXPAT)
  100. AC_DEFINE_UNQUOTED([NE_FMT_XML_SIZE], ["d"])
  101. CPPFLAGS="$CPPFLAGS -I$ne_expdir"
  102. if test "x${NEON_TARGET}" = "xlibneon.la"; then
  103. NEON_LTLIBS=$with_expat
  104. else
  105. # no dependency on libexpat => crippled libneon, so do partial install
  106. ALLOW_INSTALL=lib
  107. fi
  108. neon_xml_parser=expat
  109. neon_xml_parser_message="expat in $ne_expdir"
  110. ;;
  111. /*) AC_MSG_ERROR([--with-expat does not take a directory argument]) ;;
  112. esac
  113. # If expat wasn't specifically enabled and libxml was:
  114. if test "${neon_xml_parser}-${with_libxml2}-${with_included_expat}" = "none-yes-no"; then
  115. NE_XML_LIBXML2(
  116. [AC_MSG_ERROR([libxml2.x library not found, cannot proceed])])
  117. fi
  118. # Otherwise, by default search for expat then libxml2:
  119. if test "${neon_xml_parser}-${with_included_expat}" = "none-no"; then
  120. NE_XML_EXPAT([NE_XML_LIBXML2([:])])
  121. fi
  122. # If an XML parser still has not been found, fail or use the bundled expat
  123. if test "$neon_xml_parser" = "none"; then
  124. m4_if($1, [],
  125. [AC_MSG_ERROR([no XML parser was found: expat or libxml 2.x required])],
  126. [# Configure the bundled copy of expat
  127. NE_XML_BUNDLED_EXPAT($@)
  128. neon_xml_parser_message="bundled expat in $1"])
  129. fi
  130. AC_MSG_NOTICE([XML parser used: $neon_xml_parser_message])
  131. fi
  132. ])