Index: configure
===================================================================
diff -u -r78e6c23b4195221aba2a75be9e813382d74f20fb -ra16cfab111738c0792b602340bb9f86263206a74
--- configure	(.../configure)	(revision 78e6c23b4195221aba2a75be9e813382d74f20fb)
+++ configure	(.../configure)	(revision a16cfab111738c0792b602340bb9f86263206a74)
@@ -1365,6 +1365,9 @@
   --with-all=yes|no,
 	   --without-all disables built of all
   --with-tclinclude       directory containing the public Tcl  header files.
+  --with-expat=sys assumes a system-wide expat installation,
+           --with-expat=<INC_DIR,LIB_DIR> point to a custom expat installation,
+           --without-expat falls back to the bundled expat installation
   --with-tcl              directory containing tcl configuration
                           (tclConfig.sh)
   --with-tk               directory containing tk configuration (tkConfig.sh)
@@ -2016,6 +2019,14 @@
 fi
 
 
+# Check whether --with-expat was given.
+if test "${with_expat+set}" = set; then
+  withval=$with_expat; with_expat=$withval
+else
+  with_expat=bundle
+fi
+
+
 subdirs=""
 
 if test "$with_all" = yes; then
@@ -2038,6 +2049,11 @@
    test_actiweb=""
    libdirs_actiweb=""
    apps_actiweb=""
+   if ! test "${with_expat}" = bundle ; then
+      { echo "$as_me:$LINENO: result: WARNING: expat configuration ${with_expat} ignored" >&5
+echo "${ECHO_T}WARNING: expat configuration ${with_expat} ignored" >&6; }
+      with_expat="bundle"
+   fi
 fi
 
 
Index: configure.in
===================================================================
diff -u -r78e6c23b4195221aba2a75be9e813382d74f20fb -ra16cfab111738c0792b602340bb9f86263206a74
--- configure.in	(.../configure.in)	(revision 78e6c23b4195221aba2a75be9e813382d74f20fb)
+++ configure.in	(.../configure.in)	(revision a16cfab111738c0792b602340bb9f86263206a74)
@@ -54,6 +54,11 @@
 AC_ARG_WITH(tclinclude, 
         [  --with-tclinclude       directory containing the public Tcl  header files.], 
          with_tclinclude=${withval})
+AC_ARG_WITH(expat,
+        [  --with-expat=sys assumes a system-wide expat installation, 
+           --with-expat=<INC_DIR,LIB_DIR> point to a custom expat installation,
+           --without-expat falls back to the bundled expat installation],
+        [with_expat=$withval],[with_expat=bundle])
 
 subdirs=""
 
@@ -77,6 +82,10 @@
    test_actiweb=""
    libdirs_actiweb=""
    apps_actiweb=""
+   if ! test "${with_expat}" = bundle ; then
+      AC_MSG_RESULT([WARNING: expat configuration ${with_expat} ignored])
+      with_expat="bundle"
+   fi
 fi
 
 AC_SUBST(subdirs)
Index: library/xml/TclExpat-1.1/configure
===================================================================
diff -u -r78e6c23b4195221aba2a75be9e813382d74f20fb -ra16cfab111738c0792b602340bb9f86263206a74
--- library/xml/TclExpat-1.1/configure	(.../configure)	(revision 78e6c23b4195221aba2a75be9e813382d74f20fb)
+++ library/xml/TclExpat-1.1/configure	(.../configure)	(revision a16cfab111738c0792b602340bb9f86263206a74)
@@ -1313,6 +1313,9 @@
   --with-xotcl=DIR_CONTAINING_XOTCLCONFIG_SH
             absolute path to xotclConfig.sh,
            --without-xotcl disables, but this is pointless
+  --with-expat=sys assumes a system-wide expat installation,
+           --with-expat=<INC_DIR,LIB_DIR> point to a custom expat installation,
+           --without-expat falls back to the bundled expat installation
   --with-tcl              directory containing tcl configuration
                           (tclConfig.sh)
   --with-tclinclude       directory containing the public Tcl header files
@@ -1921,6 +1924,46 @@
 fi
 
 
+
+# Check whether --with-expat was given.
+if test "${with_expat+set}" = set; then
+  withval=$with_expat; with_expat=$withval
+else
+  with_expat=bundle
+fi
+
+
+case $with_expat in
+    bundle) ;;
+    sys)
+        { echo "$as_me:$LINENO: result: search for expat in ${prefix} /usr/local /usr" >&5
+echo "${ECHO_T}search for expat in ${prefix} /usr/local /usr" >&6; }
+        for f in $prefix /usr/local /usr; do
+            if test -f "$f/include/expat.h" ; then
+		expat_dir=$f
+                EXPAT_INC_SPEC="-I`(cd $inc_dir; pwd)`"
+                break
+            fi
+        done
+        ;;
+    *)
+	inc_dir="`echo $with_expat |cut -f1 -d,`"
+        lib_dir="`echo $with_expat |cut -f2 -d, -s`"
+        if test -f "$inc_dir/expat.h"; then
+            EXPAT_INC_SPEC="-I`(cd $inc_dir; pwd)`"
+        else
+            { { echo "$as_me:$LINENO: error: ${inc_dir} directory does not contain expat.h" >&5
+echo "$as_me: error: ${inc_dir} directory does not contain expat.h" >&2;}
+   { (exit 1); exit 1; }; }
+        fi
+	expat_dir="`(cd $inc_dir/..; pwd)`"
+	if test -z "${lib_dir}"; then
+            EXPAT_LIB_SPEC=""
+	else
+            EXPAT_LIB_SPEC="-L`(cd $lib_dir; pwd)`"
+	fi
+esac
+
 #--------------------------------------------------------------------
 # Load the tclConfig.sh file
 #--------------------------------------------------------------------
@@ -6659,8 +6702,17 @@
 #-----------------------------------------------------------------------
 
 if test "${TEA_PLATFORM}" = "windows" ; then
+    filemap="win32filemap.c"
+else
+    filemap="unixfilemap.c"
+fi
 
-    vars="xmltok.c win32filemap.c xmlrole.c xmlwf.c codepage.c xmlparse.c hashtable.c tclexpat.c"
+if test "${with_expat}" = bundle ; then
+    # 1) the bundled case
+    { echo "$as_me:$LINENO: result: using bundled expat distribution" >&5
+echo "${ECHO_T}using bundled expat distribution" >&6; }
+
+    vars="xmltok.c ${filemap} xmlrole.c xmlwf.c codepage.c xmlparse.c hashtable.c tclexpat.c"
     for i in $vars; do
 	case $i in
 	    \$*)
@@ -6696,8 +6748,11 @@
 
 
 else
+    # 2) the shared case
+    { echo "$as_me:$LINENO: result: using shared expat found in ${expat_dir}" >&5
+echo "${ECHO_T}using shared expat found in ${expat_dir}" >&6; }
 
-    vars="xmltok.c unixfilemap.c xmlrole.c xmlwf.c codepage.c xmlparse.c hashtable.c tclexpat.c"
+    vars="tclexpat.c"
     for i in $vars; do
 	case $i in
 	    \$*)
@@ -6732,6 +6787,24 @@
 
 
 
+
+    vars="${EXPAT_INC_SPEC}"
+    for i in $vars; do
+	PKG_INCLUDES="$PKG_INCLUDES $i"
+    done
+
+
+
+    vars="${EXPAT_LIB_SPEC} -lexpat"
+    for i in $vars; do
+	if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then
+	    # Convert foo.lib to -lfoo for GCC.  No-op if not *.lib
+	    i=`echo "$i" | sed -e 's/^\([^-].*\)\.lib$/-l\1/i'`
+	fi
+	PKG_LIBS="$PKG_LIBS $i"
+    done
+
+
 fi
 
 
Index: library/xml/TclExpat-1.1/configure.in
===================================================================
diff -u -r78e6c23b4195221aba2a75be9e813382d74f20fb -ra16cfab111738c0792b602340bb9f86263206a74
--- library/xml/TclExpat-1.1/configure.in	(.../configure.in)	(revision 78e6c23b4195221aba2a75be9e813382d74f20fb)
+++ library/xml/TclExpat-1.1/configure.in	(.../configure.in)	(revision a16cfab111738c0792b602340bb9f86263206a74)
@@ -42,6 +42,40 @@
            --without-xotcl disables, but this is pointless],
         [with_xotcl=$withval], [AC_MSG_ERROR([--with-xotcl is required])])
 
+AC_ARG_WITH(expat,
+        [  --with-expat=sys assumes a system-wide expat installation, 
+           --with-expat=<INC_DIR,LIB_DIR> point to a custom expat installation,
+           --without-expat falls back to the bundled expat installation],
+        [with_expat=$withval],[with_expat=bundle])
+
+case $with_expat in
+    bundle) ;;
+    sys)
+        AC_MSG_RESULT([search for expat in ${prefix} /usr/local /usr])
+        for f in $prefix /usr/local /usr; do
+            if test -f "$f/include/expat.h" ; then
+		expat_dir=$f
+                EXPAT_INC_SPEC="-I`(cd $inc_dir; pwd)`"
+                break
+            fi
+        done
+        ;;
+    *)
+	inc_dir="`echo $with_expat |cut -f1 -d,`"
+        lib_dir="`echo $with_expat |cut -f2 -d, -s`"
+        if test -f "$inc_dir/expat.h"; then
+            EXPAT_INC_SPEC="-I`(cd $inc_dir; pwd)`"
+        else
+            AC_MSG_ERROR([${inc_dir} directory does not contain expat.h])
+        fi
+	expat_dir="`(cd $inc_dir/..; pwd)`"
+	if test -z "${lib_dir}"; then
+            EXPAT_LIB_SPEC=""
+	else
+            EXPAT_LIB_SPEC="-L`(cd $lib_dir; pwd)`"
+	fi
+esac
+
 #--------------------------------------------------------------------
 # Load the tclConfig.sh file
 #--------------------------------------------------------------------
@@ -90,10 +124,22 @@
 #-----------------------------------------------------------------------
 
 if test "${TEA_PLATFORM}" = "windows" ; then
-    TEA_ADD_SOURCES([xmltok.c win32filemap.c xmlrole.c xmlwf.c codepage.c xmlparse.c hashtable.c tclexpat.c])
+    filemap="win32filemap.c"
 else
-    TEA_ADD_SOURCES([xmltok.c unixfilemap.c xmlrole.c xmlwf.c codepage.c xmlparse.c hashtable.c tclexpat.c])
+    filemap="unixfilemap.c"
 fi
+ 
+if test "${with_expat}" = bundle ; then
+    # 1) the bundled case
+    AC_MSG_RESULT([using bundled expat distribution])
+    TEA_ADD_SOURCES([xmltok.c ${filemap} xmlrole.c xmlwf.c codepage.c xmlparse.c hashtable.c tclexpat.c])
+else
+    # 2) the shared case
+    AC_MSG_RESULT([using shared expat found in ${expat_dir}])
+    TEA_ADD_SOURCES([tclexpat.c])
+    TEA_ADD_INCLUDES([${EXPAT_INC_SPEC}])
+    TEA_ADD_LIBS([${EXPAT_LIB_SPEC} -lexpat])
+fi
 
 TEA_ADD_HEADERS([])
 TEA_ADD_INCLUDES([-I${with_xotcl}/generic ${XOTCL_BUILD_INCLUDE_SPEC}])