Index: Documents/configure.in
===================================================================
--- Documents.orig/configure.in
+++ Documents/configure.in
@@ -990,6 +990,113 @@
 	esac],
 	[with_svg="yes"])
 
+#################### LibWWW and WebDAV Support ################################
+
+AC_ARG_ENABLE([system-libwww],
+	AC_HELP_STRING([--enable-system-libwww],[try the libWWW system library]),
+	[case "${enableval}" in
+	  yes) with_system_libwww="yes" ;;
+	  no)  with_system_libwww="no" ;;
+	  *) AC_MSG_ERROR([bad value ${enableval} for --enable-system-libwww]) ;;
+	esac],
+	[with_system_libwww="no"])
+
+if test "$with_system_libwww" = "yes" ; then
+    # check to see if we have a libWWW library
+    AC_PATH_PROG([LIBWWW_CONFIG],[libwww-config])
+
+    if test "$LIBWWW_CONFIG" = "" ; then
+		AC_MSG_WARN(Not using system-provided libWWW, falling back to the builtin version.)
+		with_system_libwww="no"
+    fi
+fi
+
+dnl
+dnl WebDAV support enabled by default
+dnl
+AC_ARG_WITH([dav],
+   AC_HELP_STRING([--with-dav],[enable WebDAV support (experimental)]),
+   [case "${withval}" in
+	  yes) with_dav="yes" ;;
+	  no)  with_dav="no" ;;
+	  *) AC_MSG_ERROR(bad value ${withval} for --with-dav) ;;
+	esac],
+	[with_dav="yes"])
+
+# If DAV is enabled, check if the source code is present
+if test ! -f $srcdir/davlib/Makefile.in ; then
+	if test "$with_dav" = "yes" ; then
+	    AC_MSG_WARN(WebDAV makefile not found, disabling WebDAV build)
+	    with_dav="no"
+	fi
+fi
+
+if test "$with_system_libwww" != "yes" ; then
+	if test ! -f $srcdir/../libwww/Makefile.in ; then
+		AC_MSG_ERROR([libWWW sources not found, stopping the build process])
+	fi
+fi
+
+if test "$enable_system_libwww" != "yes" ; then
+  if test "$with_dav" = "yes" ; then
+    WITH_DAV="--with-dav"
+  else
+    WITH_DAV="--without-dav"
+  fi
+  # configure libwww
+  CURRENT_PATH="`pwd`"
+  mkdir libwww
+  cd libwww && \
+    $CURRENT_PATH/../../libwww/configure \
+    --build=$build_alias --host=$host_alias --target=$target_alias \
+    --disable-shared \
+    $WITHDAV \
+    --with-zlib && \
+    echo "libwww is configured" ; \
+    echo "patching wwwconf.h because appkit.h do not compile on macos, and it seems that appkit.h is not used in amaya" ; \
+    cp wwwconf.h wwwconf.h.orig ; \
+    sed -e "s/\(\#define HAVE_APPKIT_APPKIT_H 1\)/\/* \1 *\//" \
+			wwwconf.h.orig > wwwconf.h ; \
+    echo "wwwconf.h patched !" ; \
+  cd ..
+  chmod +x libwww/libwww-config
+  BUILDLIBWWW="libWWW"
+  LIBWWW_CONFIG="libwww/libwww-config"
+  LIBWWW_LDFLAGS="-L$CURRENT_PATH/libwww/Library/src/.libs -L$CURRENT_PATH/libwww/modules/md5/.libs -L$CURRENT_PATH/libwww/modules/expat/.libs `$LIBWWW_CONFIG --libs`"
+  LIBWWW_CFLAGS="-I$CURRENT_PATH/../../libwww/Library/src -I$CURRENT_PATH/libwww"
+else
+  LIBWWW_CFLAGS="`$LIBWWW_CONFIG --cflags`"
+  LIBWWW_LDFLAGS="`$LIBWWW_CONFIG --libs`"
+
+  if test "$with_dav" = "yes" ; then
+    AC_CHECK_LIB([wwwdav],
+				 [toto],
+				 [LIBWWW_LDFLAGS="$LIBWWW_LDFLAGS -lwwwdav"],
+				 [AC_MSG_WARN([libwwwdav is not available, disabling WebDAV]); with_dav="no"])
+  fi
+fi
+
+LIBWWW_CXXFLAGS="$LIBWWW_CFLAGS"
+
+AC_SUBST(BUILDLIBWWW)
+AC_SUBST(LIBWWW_CFLAGS)
+AC_SUBST(LIBWWW_CXXFLAGS)
+AC_SUBST(LIBWWW_LDFLAGS)
+
+if test "$with_dav" = "yes" ; then
+	AMAYA_DAV_INCLUDES="-I$CURRENT_PATH/../davlib/h -I$CURRENT_PATH/../davlib/tree/h -I$CURRENT_PATH/../davlib/f"
+	AMAYA_DAV_LIBS="../davlib/davlib.a"
+	AMAYA_DAV_OPTIONS="-DDAV"
+	BUILDWEBDAV="WebDAV"
+fi
+
+AC_SUBST(AMAYA_DAV_OPTIONS)
+AC_SUBST(AMAYA_DAV_INCLUDES)
+AC_SUBST(AMAYA_DAV_LIBS)
+AC_SUBST(BUILDWEBDAV)
+
+############# end of LibWWW and WebDAV Support ################################
+
 ##########################Annotations Support####################
 dnl
 dnl annotations are enabled by default
@@ -1139,36 +1246,7 @@
  GENERIC_XML_OPTIONS=""
 fi
 
-dnl
-dnl WebDAV support enabled by default
-dnl
-AC_ARG_WITH(dav,            [  --with-dav              enable WebDAV support (default) ])
-if test "$with_dav" = "" ; then
-  with_dav="yes"
-fi
-if test "$with_dav" = "yes" ; then
-   DAV_OPTIONS=-DDAV
-   DAVDIR="davlib"
-   LIBDAV="libwwwdav"
-   WITHDAV="--with-dav" 
-   WWWDAV="-lwwwdav" 
-else
-   with_dav="no"
-   DAV_OPTIONS=""
-   DAVDIR=""
-   LIBDAV=""
-   WITHDAV="" 
-   WWWDAV="" 
-fi
-
-
 if test "$build_amaya" = "yes" ; then
-    if test ! -f $srcdir/../libwww/Makefile.in ; then
-	AC_MSG_WARN(libwww sources not found !!)
-	AC_MSG_WARN(Disabling Amaya build !)
-	build_amaya="no"
-    fi
-
     if test ! -f $srcdir/amaya/MathML.S ; then
 	if test "$with_math" = "yes" ; then
 	    AC_MSG_WARN(MathML sources not found !!)
@@ -1187,18 +1265,6 @@
 	fi
     fi
 
-    if test ! -f $srcdir/davlib/Makefile.in ; then
-	if test "$with_dav" = "yes" ; then
-	    AC_MSG_WARN(WebDAV makefile not found !!)
-	    AC_MSG_WARN(Disabling WebDAV build !)
-	    with_dav="no"
-            DAVDIR=""
-            LIBDAV=""
-            WITHDAV="" 
-            WWWDAV="" 
-	fi
-    fi
-   
 
 fi
 
@@ -1299,11 +1365,6 @@
 AC_SUBST(IMGLIBS)
 AC_SUBST(EXTRA_INCLUDES)
 
-AC_SUBST(DAVDIR)
-AC_SUBST(LIBDAV)
-AC_SUBST(WITHDAV)
-AC_SUBST(WWWDAV)
-
 AC_SUBST(MAKE_LIBWWW_RDF_PARSER)
 AC_SUBST(LIBWWW_RDF_PARSER)
 #AC_SUBST(ANNOTLIB_COMPILE_BM)
@@ -1316,9 +1377,6 @@
 dnl Include the option Makefile.xxx fragment according to the configure options
 dnl
 
-www_frag=$srcdir/amaya/Makefile.libwww
-AC_SUBST_FILE(www_frag)
-
 if test "$with_math" = "no" ; then
     math_frag=/dev/null
 else
@@ -1340,13 +1398,6 @@
 fi
 AC_SUBST_FILE(annot_frag)
 
-if test "$with_dav" = "yes" ; then
-    dav_frag=$srcdir/davlib/Makefile.dav
-else
-    dav_frag=/dev/null
-fi
-AC_SUBST_FILE(dav_frag)
-
 if test "$with_templates" = "yes" ; then
     templates_frag=$srcdir/amaya/Makefile.templates
 else
@@ -1372,8 +1423,11 @@
 
 if test "$build_amaya" = "yes" ; then
     make_output="$make_output amaya/Makefile"
-    EXTRA_MAKEFILE_IN="$srcdir/amaya/Makefile.in \
-    $srcdir/amaya/Makefile.libwww"
+    EXTRA_MAKEFILE_IN="$srcdir/amaya/Makefile.in"
+
+    if test "enable_system_libwww" != "yes" ; then
+       EXTRA_MAKEFILE_IN="$EXTRA_MAKEFILE_IN $srcdir/amaya/Makefile.libwww"
+    fi
 
     if test "$with_annot" = "yes" ; then
        make_output="$make_output annotlib/Makefile"
Index: Documents/Makefile.in
===================================================================
--- Documents.orig/Makefile.in
+++ Documents/Makefile.in
@@ -59,7 +59,7 @@
 	@(if test -d "$(GL_BUILDDIR)" ; then cd "$(GL_BUILDDIR)" ; \
 	  $(MAKE) linux-static ; fi)
 
-print_prog: rebuild force bin/str
+print_prog: rebuild force bin/str @BUILDLIBWWW@
 	@(if test -d thotlib ; then cd thotlib ; \
   $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" print ; fi)
 
@@ -129,130 +129,17 @@
 #
 # Rules to rebuild the libWWW package
 #
-
-# MKP: adding libwwwdav
-AMAYA_LIBWWW_STANDARD_LIBS = \
-	libwwwapp \
-	libwwwhttp \
-	libwwwhtml \
-	libwwwmime \
-	libwwwcache \
-	libwwwstream \
-	libwwwfile \
-	libwwwdir \
-	libwwwtrans \
-	libwwwcore \
-	libwwwutils \
-	libwwwftp \
-	@MAKE_LIBWWW_RDF_PARSER@ \
-	libwwwzip \
-        @LIBDAV@
-
-libwww_config :
-	@(if [ ! -d $(THOTDIR)/../$(LIBWWW) ] ; then \
-	      $(ECHO) "Error libwww dir not found at $(THOTDIR)/../$(LIBWWW)" ; \
-	  fi)
-	@(if [ ! -d $(LIBWWW) ] ; then \
-		$(MKDIR) $(LIBWWW) ; \
-          fi)
-#MKP: adding --with-dav
-	@(localdir=`pwd` ; libwwwdir="$$localdir/../../$(LIBWWW)" ; \
-	  cd $(LIBWWW) ; unset LANG; \
-	  if [ ! -f Makefile -o ! -f wwwconf.h ] ; then \
-	  	$$libwwwdir/configure \
-			--build=@build_alias@ --host=@host_alias@ --target=@target_alias@ \
-			--disable-shared \
-			@WITHDAV@ \
-			--with-zlib; \
-		$(ECHO) "libwww is configured" ; \
-		$(ECHO) "patching wwwconf.h because appkit.h do not compile on macos, and it seems that appkit.h is not used in amaya" ; \
-		$(CP) wwwconf.h wwwconf.h.orig ; \
-		$(SED) "s/\(\#define HAVE_APPKIT_APPKIT_H 1\)/\/* \1 *\//" \
-			wwwconf.h.orig > wwwconf.h ; \
-                $(ECHO) "wwwconf.h patched !" ; \
-	  fi)
-
-libwww_make_module_md5 \
-libmd5 : force
-		@(localdir=`pwd`; \
-		 cd $(LIBWWW)/modules/md5 ; \
-		 $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS) $(EXPAT_OPTIONS)" \
-		 CPPFLAGS="$(CPPFLAGS) $(THOTINCLUDES) $(EXTRA_INCLUDES)" \
-	        	    libmd5.la)
-
-libwww_install_module_md5 : force
-		@(if [ -e libmd5.a -a ! -L libmd5.a ] ; then \
-			$(RM) libmd5.a ; \
-		  fi ; \
-		  if [ ! -L libmd5.a ] ; then \
-			$(LN_S) $(LIBWWW)/modules/md5/.libs/libmd5.a ./libmd5.a ; \
-		  fi)
-
-libwww_make_module_expat \
-libexpat : force
-		@(localdir=`pwd`; \
-		  cd $(LIBWWW)/modules/expat/ ; \
-		  $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS) $(EXPAT_OPTIONS) -DXML_AMAYA" \
-		  CPPFLAGS="$(CPPFLAGS)" \
-	        	    )
-
-libwww_install_module_expat : force
-		@(if [ -e libexpat.a -a ! -L libexpat.a ] ; then \
-			$(RM) libexpat.a ; \
-		  fi ; \
-		  if [ ! -L libexpat.a ] ; then \
-			$(LN_S) $(LIBWWW)/modules/expat/.libs/libexpat.a ./libexpat.a ; \
-		  fi)
-
-#libwww_make_module_idn \
-#libidn : force
-#		@(localdir=`pwd`; \
-#		  cd $(LIBWWW)/modules/idn/ ; \
-#		  $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS) $(EXPAT_OPTIONS) -DLIBWWW_USEIDN" \
-#		  CPPFLAGS="$(CPPFLAGS)" \
-#	        	    )
-
-#libwww_install_module_idn : force
-#		@(if [ -e libidn.a -a ! -L libidn.a ] ; then \
-#			$(RM) libidn.a ; \
-#		  fi ; \
-#		  if [ ! -L libidn.a ] ; then \
-#			$(LN_S) $(LIBWWW)/modules/idn/.libs/libidn.a ./libidn.a ; \
-#		  fi)
-
-libwww_make_standard_libs \
-$(AMAYA_LIBWWW_STANDARD_LIBS) : force
-		@(localdir=`pwd`; \
-		  all_libs="" ; \
-		  for lib in $(AMAYA_LIBWWW_STANDARD_LIBS) ; do \
-		      all_libs="$$all_libs $$lib.la" ; \
-		   done ; \
-		  cd $(LIBWWW)/Library/src ; \
-		  $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS) $(EXPAT_OPTIONS)" \
-		  CPPFLAGS="$(CPPFLAGS) $(THOTINCLUDES) $(EXTRA_INCLUDES)" \
-			     $$all_libs)
-
-libwww_install_standard : force
-		@(for lib in $(AMAYA_LIBWWW_STANDARD_LIBS) ; do \
-		    if [ -e $$lib.a -a ! -L $$lib.a ] ; then \
-			$(RM) $$lib.a ;  \
-		    fi ; \
-		    if [ ! -L $$lib.a ] ; then \
-			$(LN_S) $(LIBWWW)/Library/src/.libs/$$lib.a ./$$lib.a ; \
-		    fi ; \
-		done)
-
-#libwww_make_module_libs : libwww_make_module_md5 libwww_make_module_expat libwww_make_module_idn
-libwww_make_module_libs : libwww_make_module_md5 libwww_make_module_expat
-libwww_make : libwww_make_module_libs libwww_make_standard_libs
-#libwww_install_modules : libwww_install_module_md5 libwww_install_module_expat libwww_install_module_idn
-libwww_install_modules : libwww_install_module_md5 libwww_install_module_expat
-libwww_install : libwww_install_modules libwww_install_standard 
-
-libwww : libwww_config libwww_make
+libwww: force
+	$(MAKE) -C libwww
 		@($(ECHO) "libwww is installed")
 
 #
+# Rules to rebuild the WebDAV module
+#
+WebDAV: @BUILDLIBWWW@ force
+	$(MAKE) -C davlib
+
+#
 # Rules to build the raptor RDF library
 #
 raptor: force
Index: Documents/Options.in
===================================================================
--- Documents.orig/Options.in
+++ Documents/Options.in
@@ -79,7 +79,5 @@
 GL_INCLUDES=@GL_INCLUDES@
 GL_LIBRARIES=@GL_LIBRARIES@
 
-LIBWWW=libwww
-
 
 
Index: Documents/amaya/Makefile.in
===================================================================
--- Documents.orig/amaya/Makefile.in
+++ Documents/amaya/Makefile.in
@@ -6,10 +6,16 @@
 
 @VPATHOPT@= @srcdir@
 THOTDIR = @top_srcdir@
-WWWDAV = @WWWDAV@
 LIBWWW_RDF_PARSER = @LIBWWW_RDF_PARSER@
 LIBZ = @LIBZ@
 
+AMAYA_LIBWWW_LIBS = @LIBWWW_LDFLAGS@
+AMAYA_LIBWWW_INCLUDES = @LIBWWW_CFLAGS@
+
+AMAYA_DAV_LIBS = @AMAYA_DAV_LIBS@
+AMAYA_DAV_OPTIONS = @AMAYA_DAV_OPTIONS@
+AMAYA_DAV_INCLUDES = @AMAYA_DAV_INCLUDES@
+
 OBJDIRS = wxdialog
 
 include ../Options
@@ -86,10 +92,6 @@
 ../tools/mkdep/mkdep : 
 	@(cd ../tools/mkdep ; $(MAKE) CC="$(CC)" CFLAGS="-O -x c")
 
-#../libraptor/.libs/libraptor.a \
-#amaya_comp_libraptor: @MAKERAPTOR@ force
-#	@(cd .. ; $(MAKE) libraptor CC="$(CC)" CFLAGS="-O2 -x c")
-
 ../redland/librdf/.libs/librdf.a \
 ../redland/raptor/.libs/libraptor.a \
 redland:
@@ -104,8 +106,13 @@
 #									#
 #########################################################################
 
-#include the fragment "amaya/Makefile.libwww" for libwww if configured in
-@www_frag@
+AMAYA_LIBWWW_OBJ= \
+	AHTBridge.o \
+	AHTFWrite.o \
+	answer.o \
+	query.o \
+	AHTMemConv.o \
+	AHTInit.o
 
 #include the fragment "amaya/Makefile.svg" for svg if configured in
 @svg_frag@
@@ -116,9 +123,6 @@
 #include the fragment "annotlib/Makefile.annot" for annotations if configured in
 @annot_frag@
 
-#include the fragment "davlib/Makefile.dav" for webdav if configured in
-@dav_frag@
-
 #include the fragment "amaya/Makefile.templates" for templates if configured in
 @templates_frag@
 
Index: Documents/annotlib/Makefile.in
===================================================================
--- Documents.orig/annotlib/Makefile.in
+++ Documents/annotlib/Makefile.in
@@ -14,9 +14,7 @@
 
 INCLUDES= -DHAVE_CONFIG_H -DANNOTATIONS \
 	  -I.. -I../amaya  -I@srcdir@/f -I@top_srcdir@/amaya \
-	  -I@top_srcdir@/amaya/f -I../libwww \
-	  -I@top_srcdir@/../libwww/Library/src \
-	  -I@top_srcdir@/../libwww/modules/expat/lib \
+	  -I@top_srcdir@/amaya/f @LIBWWW_CFLAGS@ \
 	   @AMAYA_RAPTOR_INCLUDES@ @THOTINCLUDES@ $(GUI_INCLUDES)
 
 
Index: Documents/davlib/Makefile.in
===================================================================
--- Documents.orig/davlib/Makefile.in
+++ Documents/davlib/Makefile.in
@@ -13,46 +13,21 @@
 
 INCLUDES =-DHAVE_CONFIG_H -I.. \
 	  -I../amaya -I@srcdir@/f -I@top_srcdir@/amaya \
-	  -I@top_srcdir@/amaya/f -I../libwww \
+	  -I@top_srcdir@/amaya/f \
 	  -I@top_srcdir@/thotlib/include \
-	  -I@top_srcdir@/../libwww/Library/src \
-	  -I@top_srcdir@/../libwww/modules/expat/lib \
+	  @LIBWWW_CFLAGS@ \
 	  -I$(DAVLIB)/tree/h -I$(DAVLIB)/h \
 	  $(GUI_INCLUDES)
 
 OPTIONS	= @AMAYA_OPTIONS@ $(AMAYA_DAV_OPTIONS)
 
-LIBWWW_LIBS= \
-		-L../$(LIBWWW)/Library/src/.libs \
-			-lwwwapp \
-			-lwwwhttp \
-			-lwwwxml \
-			-lwwwhtml \
-			-lwwwmime \
-			-lwwwcache \
-			-lwwwstream \
-			-lwwwfile \
-			-lwwwdir \
-			-lwwwtrans \
-			-lwwwcore \
-			-lwwwutils \
-			-lwwwzip \
-			-lwwwftp \
-			-lwwwdav \
-		-L../$(LIBWWW)/modules/md5/.libs \
-			-lmd5 \
-		-L../$(LIBWWW)/modules/expat/.libs \
-			-lexpat \
-		-ldl -L/usr/lib
-
-
 prefix = @prefix@
 exec_prefix = @exec_prefix@
 libdir = @libdir@
 
 ############################################
 
-all : tree awparser.o AHTLockBase.o HTHome dav_obj davlib.a
+all : tree awparser.o AHTLockBase.o dav_obj davlib.a
 
 dav_obj : $(AMAYA_DAV_OBJ)
 
@@ -108,8 +83,7 @@
 	awnode.o \
 	awstring.o \
 	awpair.o \
-	list.o \
-	../$(LIBWWW)/Library/src/HTHome.o
+	list.o
 
 #
 # dependencies
Index: Documents/amaya/Makefile.math
===================================================================
--- Documents.orig/amaya/Makefile.math
+++ Documents/amaya/Makefile.math
@@ -23,7 +23,7 @@
 
 MATH_SCHEMAS= $(AMAYA)/MathML.S $(AMAYA)/MathMLP.P $(AMAYA)/MathMLT.T
 
-math_schema= compMATH compMATHP compMATHT
+math_schema= compMATH compMATHP compMATHT MathML.h
 
 #
 # Structure schema compilation.
Index: Documents/amaya/Makefile.svg
===================================================================
--- Documents.orig/amaya/Makefile.svg
+++ Documents/amaya/Makefile.svg
@@ -31,7 +31,7 @@
 	$(AMAYA)/Timeline.S $(AMAYA)/TimelineP.P $(AMAYA)/TimelineT.T
 
 svg_schema= compSVG compSVGP compSVGT \
-	compTimeline compTimelineP compTimelineT
+	compTimeline compTimelineP compTimelineT SVG.h
 
 
 #
