Attempts to fix 'make distcheck' work. Things are progressing pretty well,
    but there are still failures long into the process dealing with docs
    (as always).
The big changes here are mostly to make $(srcdir) != "." work correctly,
    fixing the docbook related sections and fc-lang were particularily
    tricky. Docbook refuses to load system entities from anywhere other
    than where the original .sgml file was located, so no luck looking in
    "." for the configure-generated version.sgml and confdir.sgml files.
fc-lang needed help finding .orth files; added a -d option to set the
    directory as the least evil of many options.
Now to go use a faster machine and try and wring out the last issues.
diff --git a/ChangeLog b/ChangeLog
index 2a0d902..5b0b246 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,32 @@
 2003-10-26  Keith Packard  <keithp@keithp.com>
 
+	* configure.in:
+	* doc/Makefile.am:
+	* fc-cache/Makefile.am:
+	* fc-glyphname/Makefile.am:
+	* fc-lang/Makefile.am:
+	* fc-lang/fc-lang.c: (scanopen), (scan), (main):
+	* fc-list/Makefile.am:
+	* fc-match/Makefile.am:
+	Attempts to fix 'make distcheck' work.  Things are
+	progressing pretty well, but there are still failures
+	long into the process dealing with docs (as always).
+	
+	The big changes here are mostly to make $(srcdir) != "."
+	work correctly, fixing the docbook related sections and
+	fc-lang were particularily tricky.  Docbook refuses to load
+	system entities from anywhere other than where the original .sgml
+	file was located, so no luck looking in "." for the
+	configure-generated version.sgml and confdir.sgml files.
+
+	fc-lang needed help finding .orth files; added a -d option
+	to set the directory as the least evil of many options.
+
+	Now to go use a faster machine and try and wring out the last
+	issues.
+
+2003-10-26  Keith Packard  <keithp@keithp.com>
+
 	Tag version 2.2.91
 
 2003-10-26  Keith Packard  <keithp@keithp.com>
diff --git a/configure.in b/configure.in
index be2e3cb..f87a7a5 100644
--- a/configure.in
+++ b/configure.in
@@ -330,7 +330,7 @@
 # Find out what language orthographies are included
 #
 
-ORTH_FILES=`cd fc-lang && echo *.orth`
+ORTH_FILES=`cd ${srcdir}/fc-lang && echo *.orth`
 AC_SUBST(ORTH_FILES)
 
 #
diff --git a/doc/Makefile.am b/doc/Makefile.am
index b4bd051..6c83d7e 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,3 +1,28 @@
+#
+# $Id$
+#
+# Copyright © 2003 Keith Packard
+#
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that
+# copyright notice and this permission notice appear in supporting
+# documentation, and that the name of Keith Packard not be used in
+# advertising or publicity pertaining to distribution of the software without
+# specific, written prior permission.  Keith Packard makes no
+# representations about the suitability of this software for any purpose.  It
+# is provided "as is" without express or implied warranty.
+#
+# KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+# EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+DOC_SRC = ${top_srcdir}/doc
+DOC_BLD = ${top_builddir}/doc
 DOC_MODULE = fontconfig
 DOC2HTML = docbook2html
 DOC2TXT = docbook2txt
@@ -6,8 +31,8 @@
 TXT = fontconfig-user.txt fontconfig-devel.txt
 HTML_FILES = fontconfig-user.html
 HTML_DIRS = fontconfig-devel
-SGML = fontconfig-user.sgml fontconfig-devel.sgml
-FNCS_TMPL = func.sgml
+SGML = ${DOC_SRC}/fontconfig-user.sgml ${DOC_SRC}/fontconfig-devel.sgml
+FNCS_TMPL = ${DOC_SRC}/func.sgml
 
 DOC_FUNCS_FNCS=\
 	fcatomic.fncs \
@@ -97,11 +122,12 @@
 
 .fncs.sgml:
 	$(RM) $@
-	./edit-sgml $(FNCS_TMPL) < $*.fncs > $*.sgml
+	./edit-sgml $(FNCS_TMPL) < `test -f '$<' || echo '$(srcdir)/'`$< > $*.sgml
 
 .sgml.txt:
 	$(RM) $@
-	$(DOC2TXT) $*.sgml
+	test -f '$<' || ln -s '$(srcdir)/'$< $<
+	$(DOC2TXT) $<
 
 $(man_MANS): func.refs
 
@@ -124,20 +150,31 @@
 	$(RM) $(man_MANS) $(DOC_FILES) $(DOC_FUNCS_SGML) func.refs
 	$(RM) -r $(DOC_DIRS)
 
-fontconfig-devel: fontconfig-devel.sgml $(DOCS_FUNCS_SGML) version.sgml confdir.sgml
+fontconfig-devel: ./fontconfig-devel.sgml $(DOCS_FUNCS_SGML) version.sgml confdir.sgml
 	$(RM) -r fontconfig-devel
 	$(DOC2HTML) -o fontconfig-devel fontconfig-devel.sgml
 
-fontconfig-devel.txt: fontconfig-devel.sgml version.sgml confdir.sgml
+fontconfig-devel.txt: ./fontconfig-devel.sgml version.sgml confdir.sgml
 
-fontconfig-user.html: fontconfig-user.sgml version.sgml confdir.sgml
+fontconfig-user.html: ./fontconfig-user.sgml version.sgml confdir.sgml
 	$(DOC2HTML) -u fontconfig-user.sgml
 
-fontconfig-user.txt:  fontconfig-user.sgml version.sgml confdir.sgml
+fontconfig-user.txt:  ./fontconfig-user.sgml version.sgml confdir.sgml
+
+./fontconfig-user.sgml: ALWAYS
+	test -f fontconfig-user.sgml || $(LN_S) ${srcdir}/fontconfig-user.sgml fontconfig-user.sgml
+
+./fontconfig-devel.sgml: ALWAYS
+	test -f fontconfig-devel.sgml || $(LN_S) ${srcdir}/fontconfig-devel.sgml fontconfig-devel.sgml
+
+ALWAYS:
 
 STRIPNL=awk '{ if (NR > 1) printf ("\n"); printf ("%s", $$0); }'
-confdir.sgml: confdir.sgml.in
-	sed "s,@CONFDIR\@,${CONFDIR}," < confdir.sgml.in | $(STRIPNL) > confdir.sgml
+confdir.sgml: ${DOC_SRC}/confdir.sgml.in
+	sed "s,@CONFDIR\@,${CONFDIR}," < ${DOC_SRC}/confdir.sgml.in | $(STRIPNL) > confdir.sgml
+
+clean::
+	$(RM) confdir.sgml
 
 else
 all-local:
@@ -157,3 +194,14 @@
 	    $(INSTALL_DATA) $$f $(DESTDIR)$(DOCDIR)/$$f; \
 	  done \
 	done
+
+uninstall-local:
+	for i in $(DOC_FILES); do \
+	  echo '-- Uninstalling '$$i ; \
+	  $(RM) $(DESTDIR)$(DOCDIR)/$$i ; \
+	done
+	for i in $(DOC_DIRS); do \
+	  echo '-- Uninstalling '$$i ; \
+	  rm -rf $(DESTDIR)$(DOCDIR)/$$i ; \
+	done
+	rmdir $(DESTDIR)$(DOCDIR)
diff --git a/fc-cache/Makefile.am b/fc-cache/Makefile.am
index eede777..3d584bc 100644
--- a/fc-cache/Makefile.am
+++ b/fc-cache/Makefile.am
@@ -22,8 +22,10 @@
 #  PERFORMANCE OF THIS SOFTWARE.
 
 DOC2MAN = docbook2man
- 
-SGML = fc-cache.sgml
+
+FC_CACHE_SRC=${top_srcdir}/fc-cache
+
+SGML = ${FC_CACHE_SRC}/fc-cache.sgml
 
 INCLUDES=$(FREETYPE_CFLAGS)
 
@@ -33,14 +35,13 @@
 
 EXTRA_DIST=$(SGML)
 
-fc_cache_LDADD = ../src/libfontconfig.la
-
+fc_cache_LDADD = ${top_builddir}/src/libfontconfig.la
 
 if USEDOCBOOK
                                                                                 
-.sgml.1:
+${man_MANS}: ${SGML}										
 	$(RM) $@
-	$(DOC2MAN) $*.sgml
+	$(DOC2MAN) ${SGML}
 	$(RM) manpage.refs manpage.links
                                                                                 
 all-local: $(man_MANS)
diff --git a/fc-glyphname/Makefile.am b/fc-glyphname/Makefile.am
index 8063a38..b379e38 100644
--- a/fc-glyphname/Makefile.am
+++ b/fc-glyphname/Makefile.am
@@ -22,9 +22,10 @@
 # PERFORMANCE OF THIS SOFTWARE.
 #
 
-INCLUDES=-I../src $(FREETYPE_CFLAGS)
+INCLUDES=-I${top_srcdir}/src $(FREETYPE_CFLAGS)
 
 TMPL=fcglyphname.tmpl.h
+STMPL=${top_srcdir}/fc-glyphname/${TMPL}
 TARG=fcglyphname.h
 
 noinst_PROGRAMS=fc-glyphname
@@ -34,9 +35,13 @@
 noinst_MANS=fc-glyphname.man
 
 GLYPHNAME=zapfdingbats.txt
+SGLYPHNAME=${top_srcdir}/fc-glyphname/zapfdingbats.txt
 
 EXTRA_DIST=$(TMPL) $(GLYPHNAME)
 
-$(TARG): $(TMPL) fc-glyphname $(GLYPHNAME)
+$(TARG): $(STMPL) fc-glyphname $(SGLYPHNAME)
 	rm -f $(TARG)
-	./fc-glyphname $(GLYPHNAME) < $(TMPL) > $(TARG)
+	./fc-glyphname $(SGLYPHNAME) < $(STMPL) > $(TARG)
+
+clean::
+	$(RM) $(TARG)
diff --git a/fc-lang/Makefile.am b/fc-lang/Makefile.am
index fd4ba0e..4fd0b3e 100644
--- a/fc-lang/Makefile.am
+++ b/fc-lang/Makefile.am
@@ -22,9 +22,10 @@
 # PERFORMANCE OF THIS SOFTWARE.
 #
 
-INCLUDES=-I../src $(FREETYPE_CFLAGS)
+INCLUDES=-I${top_srcdir}/src $(FREETYPE_CFLAGS)
 
 TMPL=fclang.tmpl.h
+STMPL=${top_srcdir}/fc-lang/fclang.tmpl.h
 TARG=fclang.h
 
 noinst_PROGRAMS=fc-lang
@@ -37,6 +38,9 @@
 
 EXTRA_DIST=$(TMPL) $(ORTH)
 
-$(TARG): $(TMPL) fc-lang $(ORTH)
+$(TARG):$(ORTH) fc-lang $(STMPL)
 	rm -f $(TARG)
-	./fc-lang $(ORTH) < $(TMPL) > $(TARG)
+	./fc-lang -d ${srcdir} $(ORTH) < $(STMPL) > $(TARG)
+
+clean::
+	$(RM) $(TARG)
diff --git a/fc-lang/fc-lang.c b/fc-lang/fc-lang.c
index ef259bc..edfad3b 100644
--- a/fc-lang/fc-lang.c
+++ b/fc-lang/fc-lang.c
@@ -75,6 +75,26 @@
     return line;
 }
 
+char	*dir = 0;
+
+FILE *
+scanopen (char *file)
+{
+    FILE    *f;
+
+    f = fopen (file, "r");
+    if (!f && dir)
+    {
+	char	path[1024];
+	
+	strcpy (path, dir);
+	strcat (path, "/");
+	strcat (path, file);
+	f = fopen (path, "r");
+    }
+    return f;
+}
+
 /*
  * build a single charset from a source file
  *
@@ -103,7 +123,7 @@
 	    end = strlen (file);
 	    if (file[end-1] == '\n')
 		file[end-1] = '\0';
-	    f = fopen (file, "r");
+	    f = scanopen (file);
 	    if (!f)
 		fatal (file, 0, "can't open");
 	    c = scan (f, file);
@@ -213,6 +233,11 @@
     
     while (*++argv)
     {
+	if (!strcmp (*argv, "-d"))
+	{
+	    dir = *++argv;
+	    continue;
+	}
 	if (i == MAX_LANG)
 	    fatal (*argv, 0, "Too many languages");
 	files[i++] = *argv;
@@ -222,7 +247,7 @@
     i = 0;
     while (files[i])
     {
-	f = fopen (files[i], "r");
+	f = scanopen (files[i]);
 	if (!f)
 	    fatal (files[i], 0, strerror (errno));
 	sets[i] = scan (f, files[i]);
diff --git a/fc-list/Makefile.am b/fc-list/Makefile.am
index 6975361..356c9f1 100644
--- a/fc-list/Makefile.am
+++ b/fc-list/Makefile.am
@@ -23,7 +23,9 @@
 
 DOC2MAN = docbook2man
 
-SGML = fc-list.sgml
+FC_LIST_SRC=${top_srcdir}/fc-list
+
+SGML = ${FC_LIST_SRC}/fc-list.sgml
 
 bin_PROGRAMS=fc-list
 
@@ -33,14 +35,14 @@
 
 EXTRA_DIST=$(SGML)
 
-fc_list_LDADD = ../src/libfontconfig.la
+fc_list_LDADD = ${top_builddir}/src/libfontconfig.la
 
 
 if USEDOCBOOK
 
-.sgml.1:
+${man_MANS}: ${SGML}
 	$(RM) $@
-	$(DOC2MAN) $*.sgml
+	$(DOC2MAN) ${SGML}
 	$(RM) manpage.refs manpage.links
 
 all-local: $(man_MANS)
diff --git a/fc-match/Makefile.am b/fc-match/Makefile.am
index 8c8b119..229ac60 100644
--- a/fc-match/Makefile.am
+++ b/fc-match/Makefile.am
@@ -29,4 +29,4 @@
 
 EXTRA_DIST=$(man_MANS)
 
-fc_match_LDADD = ../src/libfontconfig.la
+fc_match_LDADD = ${top_builddir}/src/libfontconfig.la