Various "make distcheck" and portability fixups

Makefile.am:

* Don't use @VAR@, use $(VAR). Autoconf's AC_SUBST provides us the Make
   variable, it allows overriding the value at the command line, and
   (notably) it avoids a Make parse error in the libxml2_la_LDFLAGS
   assignment when @MODULE_PLATFORM_LIBS@ is empty

* Changed how the THREADS_W32 mechanism switches the build between
   testThreads.c and testThreadsWin32.c as appropriate; using AM_CONDITIONAL
   allows this to work cleanly and plays well with dependencies

* testapi.c should be specified as BUILT_SOURCES

* Create symlinks to the test/ and result/ subdirs so that the runtests
   target is usable in out-of-source-tree builds

* Don't do MAKEFLAGS+=--silent as this is not portable to non-GNU Makes

* Fixed incorrect find(1) syntax in the "cleanup" rule, and doing "rm -f"
   instead of just "rm" is good form

* (DIST)CLEANFILES needed a bit more coverage to allow "make distcheck" to
   pass

configure.in:

* Need AC_PROG_LN_S to create test/ and result/ symlinks in Makefile.am

* AC_LIBTOOL_WIN32_DLL and AM_PROG_LIBTOOL are obsolete; these have been
   superceded by LT_INIT

* Don't rebuild docs by default, as this requires GNU Make (as
   implemented)

* Check for uint32_t as some platforms don't provide it

* Check for some more functions, and undefine HAVE_MMAP if we don't also
   HAVE_MUNMAP (one system I tested on actually needed this)

* Changed THREADS_W32 from a filename insert into an Automake conditional

* The "Copyright" file will not be in the current directory if builddir !=
   srcdir

doc/Makefile.am:

* EXTRA_DIST cannot use wildcards when they refer to generated files; this
   breaks dependencies. What I did was define EXTRA_DIST_wc, which uses GNU
   Make $(wildcard) directives to build up a list of files, and EXTRA_DIST,
   as a literal expansion of EXTRA_DIST_wc. I also added a new rule,
   "check-extra-dist", to simplify checking that the two variables are
   equivalent. (Note that this works only when builddir == srcdir)

   (I can implement this differently if desired; this is just one way of
   doing it)

* Don't define an "all" target; this steps on Automake's toes

* Fixed up the "libxml2-api.xml ..." rule by using $(wildcard) for
   dependencies (as Make doesn't process the wildcards otherwise) and
   qualifying appropriate files with $(srcdir)

   (Note that $(srcdir) is not needed in the dependencies, thanks to VPATH,
   which we can count on as this is GNU-Make-only code anyway)

doc/devhelp/Makefile.am:

* Qualified appropriate files with $(srcdir)

* Added an "uninstall-local" rule so that "make distcheck" passes

doc/examples/Makefile.am:

* Rather than use a wildcard that doesn't work, use a substitution that
   most Make programs can handle

doc/examples/index.py:

* Do the same here

include/libxml/nanoftp.h:

* Some platforms (e.g. MSVC 6) already #define INVALID_SOCKET:

     user@host:/cygdrive/c/Program Files/Microsoft Visual Studio/VC98/\
     Include$ grep -R INVALID_SOCKET .
     ./WINSOCK.H:#define INVALID_SOCKET  (SOCKET)(~0)
     ./WINSOCK2.H:#define INVALID_SOCKET  (SOCKET)(~0)

include/libxml/xmlversion.h.in:

* Support ancient GCCs (I was actually able to build the library with 2.5
   but for this bit)

python/Makefile.am:

* Expanded CLEANFILES to allow "make distcheck" to pass

python/tests/Makefile.am:

* Define CLEANFILES instead of a "clean" rule, and added tmp.xml to allow
   "make distcheck" to pass

testRelax.c:

* Use HAVE_MMAP instead of the less explicit HAVE_SYS_MMAN_H (as some
   systems have the header but not the function)

testSchemas.c:

* Use HAVE_MMAP instead of the less explicit HAVE_SYS_MMAN_H

testapi.c:

* Don't use putenv() if it's not available

threads.c:

* This fixes the following build error on Solaris 8:

     libtool: compile:  cc -DHAVE_CONFIG_H -I. -I./include -I./include \
     -D_REENTRANT -D__EXTENSIONS__ -D_REENTRANT -Dsparc -Xa -mt -v \
     -xarch=v9 -xcrossfile -xO5 -c threads.c  -KPIC -DPIC -o threads.o
     "threads.c", line 442: controlling expressions must have scalar type
     "threads.c", line 512: controlling expressions must have scalar type
     cc: acomp failed for threads.c
     *** Error code 1

trio.c:

* Define isascii() if the system doesn't provide it

trio.h:

* The trio library's HAVE_CONFIG_H header is not the same as LibXML2's
   HAVE_CONFIG_H header; this change is needed to avoid a double-inclusion

win32/configure.js:

* Added support for the LZMA compression option

win32/Makefile.{bcb,mingw,msvc}:

* Added appropriate bits to support WITH_LZMA=1

* Install the header files under $(INCPREFIX)\libxml2\libxml instead of
   $(INCPREFIX)\libxml, to mirror the install location on Unix+Autotools

xml2-config.in:

* @MODULE_PLATFORM_LIBS@ (usually "-ldl") needs to be in there in order for
   `xml2-config --libs` to provide a complete set of dependencies

xmllint.c:

* Use HAVE_MMAP instead of the less-explicit HAVE_SYS_MMAN_H
diff --git a/doc/Makefile.am b/doc/Makefile.am
index dd39f69..b9ab1ad 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -16,21 +16,229 @@
     tree.html xmldtd.html XMLinfo.html XSLT.html
 APIPAGES=APIconstructors.html APIfiles.html APIfunctions.html \
     APIsymbols.html APIchunk0.html
-EXTRA_DIST=xmlcatalog_man.xml tutorial/*.html tutorial/*.c tutorial/*.pdf \
-           tutorial/images/*.png tutorial/images/callouts/*.png \
-	   API*.html *.1 *.xsl *.html *.gif w3c.png html/*.html \
-	   html/*.png libxml2-api.xml index.py search.php \
-	   apibuild.py libxml2.xsa xmllint.xml xmlcatalog_man.xml \
-	   README.docs symbols.xml
 
+if REBUILD_DOCS
+EXTRA_DIST_wc = xmlcatalog_man.xml $(wildcard tutorial/*.html) \
+    $(wildcard tutorial/*.c) $(wildcard tutorial/*.pdf) \
+    $(wildcard tutorial/images/*.png) \
+    $(wildcard tutorial/images/callouts/*.png) $(wildcard API*.html) \
+    $(wildcard *.1) $(wildcard *.xsl) $(wildcard *.html) \
+    $(wildcard *.gif) w3c.png $(wildcard html/*.html) \
+    $(wildcard html/*.png) libxml2-api.xml index.py search.php \
+    apibuild.py libxml2.xsa xmllint.xml xmlcatalog_man.xml \
+    README.docs symbols.xml
+endif
+
+# Expanded form of EXTRA_DIST_wc
+#
+EXTRA_DIST = \
+	APIchunk0.html \
+	APIchunk1.html \
+	APIchunk2.html \
+	APIchunk3.html \
+	APIchunk4.html \
+	APIchunk5.html \
+	APIchunk6.html \
+	APIchunk7.html \
+	APIchunk8.html \
+	APIchunk9.html \
+	APIchunk10.html \
+	APIchunk11.html \
+	APIchunk12.html \
+	APIchunk13.html \
+	APIchunk14.html \
+	APIchunk15.html \
+	APIchunk16.html \
+	APIchunk17.html \
+	APIchunk18.html \
+	APIchunk19.html \
+	APIchunk20.html \
+	APIchunk21.html \
+	APIchunk22.html \
+	APIchunk23.html \
+	APIchunk24.html \
+	APIchunk25.html \
+	APIchunk26.html \
+	APIchunk27.html \
+	APIchunk28.html \
+	APIchunk29.html \
+	APIconstructors.html \
+	APIfiles.html \
+	APIfunctions.html \
+	APIsymbols.html \
+	ChangeLog.xsl \
+	DOM.gif \
+	DOM.html \
+	FAQ.html \
+	Libxml2-Logo-180x168.gif \
+	Libxml2-Logo-90x34.gif \
+	README.docs \
+	XMLinfo.html \
+	XSLT.html \
+	api.xsl \
+	apibuild.py \
+	architecture.html \
+	bugs.html \
+	catalog.gif \
+	catalog.html \
+	checkapisym.xsl \
+	contribs.html \
+	docs.html \
+	downloads.html \
+	elfgcchack.xsl \
+	encoding.html \
+	entities.html \
+	example.html \
+	guidelines.html \
+	help.html \
+	html/book1.html \
+	html/home.png \
+	html/index.html \
+	html/left.png \
+	html/libxml-DOCBparser.html \
+	html/libxml-HTMLparser.html \
+	html/libxml-HTMLtree.html \
+	html/libxml-SAX.html \
+	html/libxml-SAX2.html \
+	html/libxml-c14n.html \
+	html/libxml-catalog.html \
+	html/libxml-chvalid.html \
+	html/libxml-debugXML.html \
+	html/libxml-dict.html \
+	html/libxml-encoding.html \
+	html/libxml-entities.html \
+	html/libxml-globals.html \
+	html/libxml-hash.html \
+	html/libxml-lib.html \
+	html/libxml-list.html \
+	html/libxml-nanoftp.html \
+	html/libxml-nanohttp.html \
+	html/libxml-parser.html \
+	html/libxml-parserInternals.html \
+	html/libxml-pattern.html \
+	html/libxml-relaxng.html \
+	html/libxml-schemasInternals.html \
+	html/libxml-schematron.html \
+	html/libxml-threads.html \
+	html/libxml-tree.html \
+	html/libxml-uri.html \
+	html/libxml-valid.html \
+	html/libxml-xinclude.html \
+	html/libxml-xlink.html \
+	html/libxml-xmlIO.html \
+	html/libxml-xmlautomata.html \
+	html/libxml-xmlerror.html \
+	html/libxml-xmlexports.html \
+	html/libxml-xmlmemory.html \
+	html/libxml-xmlmodule.html \
+	html/libxml-xmlreader.html \
+	html/libxml-xmlregexp.html \
+	html/libxml-xmlsave.html \
+	html/libxml-xmlschemas.html \
+	html/libxml-xmlschemastypes.html \
+	html/libxml-xmlstring.html \
+	html/libxml-xmlunicode.html \
+	html/libxml-xmlversion.html \
+	html/libxml-xmlwriter.html \
+	html/libxml-xpath.html \
+	html/libxml-xpathInternals.html \
+	html/libxml-xpointer.html \
+	html/right.png \
+	html/up.png \
+	index.html \
+	index.py \
+	interface.html \
+	intro.html \
+	library.html \
+	libxml.gif \
+	libxml2-api.xml \
+	libxml2.xsa \
+	namespaces.html \
+	newapi.xsl \
+	news.html \
+	news.xsl \
+	python.html \
+	redhat.gif \
+	search.php \
+	searches.html \
+	searches.xsl \
+	site.xsl \
+	smallfootonly.gif \
+	structure.gif \
+	symbols.xml \
+	syms.xsl \
+	threads.html \
+	tree.html \
+	tutorial/apa.html \
+	tutorial/apb.html \
+	tutorial/apc.html \
+	tutorial/apd.html \
+	tutorial/ape.html \
+	tutorial/apf.html \
+	tutorial/apg.html \
+	tutorial/aph.html \
+	tutorial/api.html \
+	tutorial/ar01s02.html \
+	tutorial/ar01s03.html \
+	tutorial/ar01s04.html \
+	tutorial/ar01s05.html \
+	tutorial/ar01s06.html \
+	tutorial/ar01s07.html \
+	tutorial/ar01s08.html \
+	tutorial/ar01s09.html \
+	tutorial/images/blank.png \
+	tutorial/images/callouts/1.png \
+	tutorial/images/callouts/10.png \
+	tutorial/images/callouts/2.png \
+	tutorial/images/callouts/3.png \
+	tutorial/images/callouts/4.png \
+	tutorial/images/callouts/5.png \
+	tutorial/images/callouts/6.png \
+	tutorial/images/callouts/7.png \
+	tutorial/images/callouts/8.png \
+	tutorial/images/callouts/9.png \
+	tutorial/images/caution.png \
+	tutorial/images/draft.png \
+	tutorial/images/home.png \
+	tutorial/images/important.png \
+	tutorial/images/next.png \
+	tutorial/images/note.png \
+	tutorial/images/prev.png \
+	tutorial/images/tip.png \
+	tutorial/images/toc-blank.png \
+	tutorial/images/toc-minus.png \
+	tutorial/images/toc-plus.png \
+	tutorial/images/up.png \
+	tutorial/images/warning.png \
+	tutorial/includeaddattribute.c \
+	tutorial/includeaddkeyword.c \
+	tutorial/includeconvert.c \
+	tutorial/includegetattribute.c \
+	tutorial/includekeyword.c \
+	tutorial/includexpath.c \
+	tutorial/index.html \
+	tutorial/ix01.html \
+	tutorial/xmltutorial.pdf \
+	upgrade.html \
+	w3c.png \
+	wiki.xsl \
+	xml.html \
+	xmlcatalog.1 \
+	xmlcatalog_man.html \
+	xmlcatalog_man.xml \
+	xmldtd.html \
+	xmlio.html \
+	xmllint.1 \
+	xmllint.html \
+	xmllint.xml \
+	xmlmem.html \
+	xmlreader.html \
+	xsa.xsl
 
 man_MANS = xmllint.1 xmlcatalog.1
 
 if REBUILD_DOCS
-all: web $(top_builddir)/NEWS libxml2.xsa $(man_MANS)
-else
-all:
-endif
+docs: web $(top_builddir)/NEWS libxml2.xsa $(man_MANS)
 
 api: libxml2-api.xml libxml2-refs.xml $(APIPAGES) $(srcdir)/html/index.html $(WIN32_DIR)/libxml2.def.src ../elfgcchack.h $(srcdir)/site.xsl
 
@@ -89,10 +297,10 @@
 	  $(XSLTPROC) -o $(WIN32_DIR)/libxml2.def.src \
 	  --nonet $(WIN32_DIR)/defgen.xsl libxml2-api.xml ; fi )
 
-libxml2-api.xml libxml2-refs.xml ../libxml2.syms: apibuild.py symbols.xml syms.xsl checkapisym.xsl ../include/libxml/*.h ../*.c
-	-(./apibuild.py)
-	($(XSLTPROC) checkapisym.xsl libxml2-api.xml)
-	($(XSLTPROC) -o ../libxml2.syms syms.xsl symbols.xml)
+libxml2-api.xml libxml2-refs.xml ../libxml2.syms: apibuild.py symbols.xml syms.xsl checkapisym.xsl $(wildcard $(top_srcdir)/include/libxml/*.h) $(wildcard $(top_srcdir)/*.c)
+	-($(srcdir)/apibuild.py)
+	($(XSLTPROC) $(srcdir)/checkapisym.xsl $(srcdir)/libxml2-api.xml)
+	($(XSLTPROC) -o ../libxml2.syms $(srcdir)/syms.xsl $(srcdir)/symbols.xml)
 	-@(cd .. ; $(MAKE) rebuild_testapi)
 
 
@@ -102,28 +310,35 @@
 xmlcatalog.1: xmlcatalog_man.xml
 	-@($(XSLTPROC) --nonet xmlcatalog_man.xml)
 
+check-extra-dist:
+	for f in $(EXTRA_DIST_wc) ; do echo $$f; done | sort -u >tmp.EXTRA_DIST_wc
+	for f in $(EXTRA_DIST) ;    do echo $$f; done | sort    >tmp.EXTRA_DIST
+	diff -u tmp.EXTRA_DIST_wc tmp.EXTRA_DIST
+	rm -f tmp.EXTRA_DIST_wc tmp.EXTRA_DIST
+endif
+
 clean-local:
 	rm -f *~ *.bak *.hierarchy *.signals *-unused.txt
 
 maintainer-clean-local: clean-local
 	rm -rf libxml-decl-list.txt libxml-decl.txt 
 
-rebuild: api all
+rebuild: api docs
 
 install-data-local: 
-	@MKDIR_P@ $(DESTDIR)$(HTML_DIR)
-	-@INSTALL@ -m 0644 $(srcdir)/xml.html $(srcdir)/encoding.html $(srcdir)/FAQ.html $(srcdir)/structure.gif $(srcdir)/DOM.gif $(srcdir)/smallfootonly.gif $(srcdir)/redhat.gif $(srcdir)/libxml.gif $(srcdir)/w3c.png $(srcdir)/Libxml2-Logo-180x168.gif $(srcdir)/Libxml2-Logo-90x34.gif $(DESTDIR)$(HTML_DIR)
-	@MKDIR_P@ $(DESTDIR)$(HTML_DIR)/html
-	-@INSTALL@ -m 0644 $(srcdir)/html/*.html $(DESTDIR)$(HTML_DIR)/html
-	-@INSTALL@ -m 0644 $(srcdir)/html/*.png $(DESTDIR)$(HTML_DIR)/html
-	@MKDIR_P@ $(DESTDIR)$(HTML_DIR)/tutorial
-	-@INSTALL@ -m 0644 $(srcdir)/tutorial/*.* \
+	$(MKDIR_P) $(DESTDIR)$(HTML_DIR)
+	-$(INSTALL) -m 0644 $(srcdir)/xml.html $(srcdir)/encoding.html $(srcdir)/FAQ.html $(srcdir)/structure.gif $(srcdir)/DOM.gif $(srcdir)/smallfootonly.gif $(srcdir)/redhat.gif $(srcdir)/libxml.gif $(srcdir)/w3c.png $(srcdir)/Libxml2-Logo-180x168.gif $(srcdir)/Libxml2-Logo-90x34.gif $(DESTDIR)$(HTML_DIR)
+	$(MKDIR_P) $(DESTDIR)$(HTML_DIR)/html
+	-$(INSTALL) -m 0644 $(srcdir)/html/*.html $(DESTDIR)$(HTML_DIR)/html
+	-$(INSTALL) -m 0644 $(srcdir)/html/*.png $(DESTDIR)$(HTML_DIR)/html
+	$(MKDIR_P) $(DESTDIR)$(HTML_DIR)/tutorial
+	-$(INSTALL) -m 0644 $(srcdir)/tutorial/*.* \
 		$(DESTDIR)$(HTML_DIR)/tutorial
-	@MKDIR_P@ $(DESTDIR)$(HTML_DIR)/tutorial/images
-	-@INSTALL@ -m 0644 $(srcdir)/tutorial/images/*.* \
+	$(MKDIR_P) $(DESTDIR)$(HTML_DIR)/tutorial/images
+	-$(INSTALL) -m 0644 $(srcdir)/tutorial/images/*.* \
 		$(DESTDIR)$(HTML_DIR)/tutorial/images
-	@MKDIR_P@ $(DESTDIR)$(HTML_DIR)/tutorial/images/callouts
-	-@INSTALL@ -m 0644 $(srcdir)/tutorial/images/callouts/*.* \
+	$(MKDIR_P) $(DESTDIR)$(HTML_DIR)/tutorial/images/callouts
+	-$(INSTALL) -m 0644 $(srcdir)/tutorial/images/callouts/*.* \
 		$(DESTDIR)$(HTML_DIR)/tutorial/images/callouts
 
 .PHONY : html xml templates scan