Shift XML handling code from Apache down into APRUTIL

- teach APRUTIL how to find Expat and respond to --with-expat
- Apache's configure points APRUTIL's configure at its srclib/expat-lite
  (this will go away; aprutil can work against installed expats or fallback
   to an expat bundled within aprutil)
- shift some of the timing of INCLUDES and top_builddir processing in the
  APRUTIL configure.in script
- expose the new apr_xml functions in apr_xml.h, apr_xml.c (by building it),
  and apu_compat.h
- rewrite util_xml.[ch] in terms of apr_xml


git-svn-id: https://svn.apache.org/repos/asf/apr/apr-util/trunk@58127 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/build/apu-conf.m4 b/build/apu-conf.m4
index 84f63d9..6d96612 100644
--- a/build/apu-conf.m4
+++ b/build/apu-conf.m4
@@ -236,7 +236,104 @@
 if test $apu_use_db = 1; then
   dnl ### use AC_CHECK_LIB?
   LIBS="$LIBS -l$db_lib"
-  APRUTIL_EXPORT_LIBS="$APRUTIL_EXPORT_LIBS $LIBS"
+  APRUTIL_EXPORT_LIBS="$APRUTIL_EXPORT_LIBS -l$db_lib"
 fi
 
 ])
+
+dnl
+dnl APU_TEST_EXPAT(directory): test if Expat is located in the specified dir
+dnl
+dnl if present: sets expat_include_dir, expat_libs, possibly expat_old
+dnl
+AC_DEFUN(APU_TEST_EXPAT,[
+  AC_MSG_CHECKING(for Expat in ifelse($2,,$1,$2))
+
+  if test -r "$1/lib/expat.h"; then
+    dnl Expat 1.95.* distribution
+    expat_include_dir="$1/lib"
+    expat_libs="$1/lib/libexpat.la"
+  elif test -r "$1/xmlparse.h"; then
+    dnl maybe an expat-lite. use this dir for both includes and libs
+    expat_include_dir="$1"
+    expat_libs="$1/libexpat.la"
+    expat_old=yes
+  elif test -r "$1/include/xmlparse.h"; then
+    dnl ### who is this?
+    expat_include_dir="$1/include"
+    expat_libs="-L$1/lib -lexpat"
+    expat_old=yes
+  elif test -r "$1/include/xml/xmlparse.h"; then
+    dnl ### who is this?
+    expat_include_dir="$1/include/xml"
+    expat_libs="-L$1/lib -lexpat"
+    expat_old=yes
+  elif test -r "$1/include/xmltok/xmlparse.h"; then
+    dnl Debian distribution
+    expat_include_dir="$1/include/xmltok"
+    expat_libs="-L$1/lib -lxmlparse -lxmltok"
+    expat_old=yes
+  elif test -r "$1/xmlparse/xmlparse.h"; then
+    dnl Expat 1.0 or 1.1 source directory
+    expat_include_dir="$1/xmlparse"
+    expat_libs="-L$1 -lexpat"
+    expat_old=yes
+  fi
+  dnl ### test for installed Expat 1.95.* distros
+
+  if test -n "$expat_include_dir"; then
+    dnl ### more info about what we found there? version? using .la?
+    AC_MSG_RESULT(yes)
+  else
+    AC_MSG_RESULT(no)
+  fi
+])
+
+
+dnl
+dnl APU_FIND_EXPAT: figure out where EXPAT is located (or use bundled)
+dnl
+AC_DEFUN(APU_FIND_EXPAT,[
+
+AC_ARG_WITH([expat],
+[ --with-expat=DIR        specify Expat location], [
+  if test "$withval" = "yes"; then
+    AC_MSG_ERROR([a directory must be specified for --with-expat])
+  elif test "$withval" = "no"; then
+    AC_MSG_ERROR([Expat cannot be disabled (at this time)])
+  else
+    abs_expatdir="`cd $withval && pwd`"
+    APU_TEST_EXPAT($abs_expatdir, $withval)
+    if test -z "$expat_include_dir"; then
+      AC_MSG_ERROR([Expat was not found (or recognized) in \"$withval\"])
+    fi
+  fi
+])
+
+if test -z "$expat_include_dir"; then
+  for d in /usr /usr/local xml/expat ; do
+    APU_TEST_EXPAT($d)
+    if test -n "$expat_include_dir"; then
+      break
+    fi
+  done
+fi
+if test -z "$expat_include_dir"; then
+  AC_MSG_ERROR([could not locate Expat. use --with-expat])
+fi
+
+if test -n "$expat_old"; then
+  AC_DEFINE(APR_HAVE_OLD_EXPAT, 1, [define if Expat 1.0 or 1.1 was found])
+fi
+
+dnl special-case the bundled distribution (use absolute dirs)
+if test "$expat_include_dir" = "xml/expat/lib"; then
+  expat_include_dir=$srcdir/xml/expat/lib
+  expat_libs=$top_builddir/xml/expat/lib/libexpat.la
+fi
+
+INCLUDES="$INCLUDES -I$expat_include_dir"
+LIBS="$LIBS $expat_libs"
+APRUTIL_EXPORT_LIBS="$APRUTIL_EXPORT_LIBS $expat_libs"
+dnl ### export the Expat includes?
+])
diff --git a/configure.in b/configure.in
index 5d2102d..c3a0e77 100644
--- a/configure.in
+++ b/configure.in
@@ -13,31 +13,35 @@
 AC_CHECK_PROG(RM, rm, rm)
 
 dnl
-dnl 1. Find the APR includes directory and (possibly) the source (base) dir.
-dnl 2. Determine what DBM backend type to use.
-dnl
-APU_FIND_APR
-APU_CHECK_DBM
-
-dnl
 dnl compute the top directory of the build
-dnl note: this substitution is needed for LIBTOOL
+dnl note: this is needed for LIBTOOL and exporting the bundled Expat
 dnl
 top_builddir="`cd $srcdir ; pwd`"
 AC_SUBST(top_builddir)
 
 dnl
+dnl set up the compilation flags and stuff
+dnl
+INCLUDES="$INCLUDES -I\$(top_builddir)/include/private -I\$(top_builddir)/include"
+
+dnl
+dnl 1. Find the APR includes directory and (possibly) the source (base) dir.
+dnl 2. Determine what DBM backend type to use.
+dnl 3. Find Expat
+dnl
+APU_FIND_APR
+APU_CHECK_DBM
+APU_FIND_EXPAT
+
+INCLUDES="$INCLUDES -I$APR_INCLUDES"
+
+dnl
 dnl prep libtool
 dnl
 echo "performing libtool configuration..."
 AC_PROG_LIBTOOL
 
 dnl
-dnl set up the compilation flags and stuff
-dnl
-INCLUDES="-I\$(top_builddir)/include/private -I\$(top_builddir)/include -I$APR_INCLUDES"
-
-dnl
 dnl grab flags from APR.
 dnl ### APR doesn't have "nice" names for its exports (yet), but it isn't
 dnl ### a problem to deal with them right here
diff --git a/include/apr_xml.h b/include/apr_xml.h
index dafb1f7..439978f 100644
--- a/include/apr_xml.h
+++ b/include/apr_xml.h
@@ -52,8 +52,6 @@
  * <http://www.apache.org/>.
  */
 
-#if 0
-
 #ifndef APR_XML_H
 #define APR_XML_H
 
@@ -66,8 +64,6 @@
 extern "C" {
 #endif
 
-#ifdef APR_NOT_AVAILABLE_YET
-
 /**
  * @package Apache XML library
  */
@@ -354,12 +350,8 @@
                                     const char *uri);
 #define APR_XML_GET_URI_ITEM(ary, i) (((const char * const *)(ary)->elts)[i])
 
-#endif /* APR_NOT_AVAILABLE_YET */
-
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* APR_XML_H */
-
-#endif /* 0 */
diff --git a/include/apu_compat.h b/include/apu_compat.h
index 0b98f3d..d99357f 100644
--- a/include/apu_compat.h
+++ b/include/apu_compat.h
@@ -76,7 +76,6 @@
 /* --------------------------------------------------------------------
  * the following symbols were moved from httpd-2.0/.../util_xml.[ch]
  */
-#if 0
 #define ap_text apr_text
 #define ap_text_header apr_text_header
 #define ap_text_append apr_text_append
@@ -102,6 +101,5 @@
 #define ap_xml_quote_elem apr_xml_quote_elem
 #define ap_xml_insert_uri apr_xml_insert_uri
 #define AP_XML_GET_URI_ITEM(a,i) APR_XML_GET_URI_ITEM(a,i)
-#endif /* 0 */
 
 #endif /* APU_COMPAT_H */
diff --git a/xml/Makefile.in b/xml/Makefile.in
index 9ac9a44..f9d62bc 100644
--- a/xml/Makefile.in
+++ b/xml/Makefile.in
@@ -1,2 +1,5 @@
+
+TARGETS = apr_xml.lo
+
 # bring in rules.mk for standard functionality
 @INCLUDE_RULES@