neon-xml-parser.m4 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # Copyright (C) 1998-2022 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 https://notroj.github.io/neon/ for the latest version.
  14. # Please report feedback via <https://github.com/notroj/neon/>
  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. NE_PKG_CONFIG(NE_LX2, libxml-2.0,
  43. [],
  44. [AC_CHECK_TOOL(XML2_CONFIG, xml2-config)
  45. if test "x$XML2_CONFIG" != "xno"; then
  46. # xml2-config in some versions erroneously includes -I/include
  47. # in the --cflags output.
  48. NE_LX2_VERSION="`$XML2_CONFIG --version`"
  49. NE_LX2_CFLAGS="`$XML2_CONFIG --cflags | sed 's| -I/include||g'`"
  50. NE_LX2_LIBS="`$XML2_CONFIG --libs | sed 's|-L/usr/lib ||g'`"
  51. fi])
  52. if test -n "${NE_LX2_VERSION+set}"; then
  53. neon_xml_parser_message="libxml $NE_LX2_VERSION"
  54. AC_DEFINE(HAVE_LIBXML, 1, [Define if you have libxml])
  55. CPPFLAGS="$CPPFLAGS $NE_LX2_CFLAGS"
  56. NEON_LIBS="$NEON_LIBS $NE_LX2_LIBS"
  57. AC_CHECK_HEADERS(libxml/xmlversion.h libxml/parser.h,,[
  58. AC_MSG_ERROR([could not find parser.h, libxml installation problem?])])
  59. neon_xml_parser=libxml2
  60. else
  61. $1
  62. fi
  63. ])
  64. dnl Configure for a bundled expat build.
  65. AC_DEFUN([NE_XML_BUNDLED_EXPAT], [
  66. AC_REQUIRE([AC_C_BIGENDIAN])
  67. # Define XML_BYTE_ORDER for expat sources.
  68. if test $ac_cv_c_bigendian = "yes"; then
  69. ne_xml_border=21
  70. else
  71. ne_xml_border=12
  72. fi
  73. # mini-expat doesn't pick up config.h
  74. CPPFLAGS="$CPPFLAGS -DXML_BYTE_ORDER=$ne_xml_border -DXML_DTD -I$1/xmlparse -I$1/xmltok"
  75. AC_DEFINE_UNQUOTED([NE_FMT_XML_SIZE], ["d"])
  76. # Use the bundled expat sources
  77. AC_LIBOBJ($2/xmltok/xmltok)
  78. AC_LIBOBJ($2/xmltok/xmlrole)
  79. AC_LIBOBJ($2/xmlparse/xmlparse)
  80. AC_LIBOBJ($2/xmlparse/hashtable)
  81. AC_DEFINE(HAVE_EXPAT)
  82. AC_DEFINE(HAVE_XMLPARSE_H, 1, [Define if using expat which includes xmlparse.h])
  83. ])
  84. AC_DEFUN([NEON_XML_PARSER], [
  85. dnl Switches to force choice of library
  86. AC_ARG_WITH([libxml2],
  87. AS_HELP_STRING([--with-libxml2], [force use of libxml 2.x]))
  88. AC_ARG_WITH([expat],
  89. AS_HELP_STRING([--with-expat], [force use of expat]))
  90. dnl Flag to force choice of included expat, if available.
  91. ifelse($#, 2, [
  92. AC_ARG_WITH([included-expat],
  93. AS_HELP_STRING([--with-included-expat], [use bundled expat sources]),,
  94. with_included_expat=no)],
  95. with_included_expat=no)
  96. if test "$NEON_NEED_XML_PARSER" = "yes"; then
  97. # Find an XML parser
  98. neon_xml_parser=none
  99. # Forced choice of expat:
  100. case $with_expat in
  101. yes) NE_XML_EXPAT([AC_MSG_ERROR([expat library not found, cannot proceed])]) ;;
  102. no) ;;
  103. */libexpat.la)
  104. # Special case for Subversion
  105. ne_expdir=`echo $with_expat | sed 's:/libexpat.la$::'`
  106. AC_DEFINE(HAVE_EXPAT)
  107. AC_DEFINE_UNQUOTED([NE_FMT_XML_SIZE], ["d"])
  108. CPPFLAGS="$CPPFLAGS -I$ne_expdir"
  109. if test "x${NEON_TARGET}" = "xlibneon.la"; then
  110. NEON_LTLIBS=$with_expat
  111. else
  112. # no dependency on libexpat => crippled libneon, so do partial install
  113. ALLOW_INSTALL=lib
  114. fi
  115. neon_xml_parser=expat
  116. neon_xml_parser_message="expat in $ne_expdir"
  117. ;;
  118. /*) AC_MSG_ERROR([--with-expat does not take a directory argument]) ;;
  119. esac
  120. # If expat wasn't specifically enabled and libxml was:
  121. if test "${neon_xml_parser}-${with_libxml2}-${with_included_expat}" = "none-yes-no"; then
  122. NE_XML_LIBXML2(
  123. [AC_MSG_ERROR([libxml2.x library not found, cannot proceed])])
  124. fi
  125. # Otherwise, by default search for expat then libxml2:
  126. if test "${neon_xml_parser}-${with_included_expat}" = "none-no"; then
  127. NE_XML_EXPAT([NE_XML_LIBXML2([:])])
  128. fi
  129. # If an XML parser still has not been found, fail or use the bundled expat
  130. if test "$neon_xml_parser" = "none"; then
  131. m4_if($1, [],
  132. [AC_MSG_ERROR([no XML parser was found: expat or libxml 2.x required])],
  133. [# Configure the bundled copy of expat
  134. NE_XML_BUNDLED_EXPAT($@)
  135. neon_xml_parser_message="bundled expat in $1"])
  136. fi
  137. AC_MSG_NOTICE([XML parser used: $neon_xml_parser_message])
  138. fi
  139. ])