+# README, INSTALL and NEWS files to be included in the source distribution
+# are generated on demand, as indirect side effects of a set of phoney goals
+# so that they are always regenerated for each distribution, from templates
+# in srcdist-doc so that we can make them version specific.
+#
+vpath %.in ${srcdir}/srcdist-doc
+srcdist-doc: README.dist NEWS.dist INSTALL.dist
+
+# We need to ensure that, when we invoke nroff, the generated output
+# will be suited to an ASCII class of typesetter; without the -Tascii
+# option, GNU nroff will substitute Unicode hyphens (u2010) in place
+# of ASCII hyphens (code 45).
+#
+NROFF = nroff -Tascii
+
+%.dist: %.in gendoc.simple.sed
+ sed -f gendoc.simple.sed $< | $(NROFF) > $*
+
+%.simple.sed: %.sed.in
+ sed -e s,'$${PACKAGE_DIRNAME}',"${PACKAGE_DISTROOT}", \
+ -e s,'$${PACKAGE_DISTNAME}',"${PACKAGE_DISTNAME}", $< > $@
+
+%.combined.sed: %.sed.in
+ sed -e s,'$${PACKAGE_DIRNAME}',"${PACKAGE_DISTROOT}", \
+ -e s,'$${PACKAGE_DISTNAME}',"${PACKAGE_DISTNAME}", \
+ -e s,'^# *cut:',, $< > $@
+
+# The following rules use sed and awk to match the RCS Id keyword;
+# we define and use the following macro, in the form "$(DOLLAR)Id:",
+# to avoid unwanted substitution on CVS checkout.
+#
+DOLLAR = $$
+
+# The following rule provides a mechanism for generating a composite from
+# README, INSTALL and NEWS, for use as an on-line package description.
+#
+readme.txt: gendoc.combined.sed readme.txt.tag readme.txt.in
+ sed s,'$(DOLLAR)Id:.*',"`cat $@.tag`", $@.in > $@
+ echo '$$Document: $@ $$: end of file' >> $@
+ rm -f gendoc.combined.sed $@.*
+
+# There should be a new generation of readme.txt for each package release;
+# since each release should also include an updated NEWS file; we adopt the
+# ID tag-line from NEWS.in, as most the appropriate template for generation
+# of a corresponding tag-line for readme.in
+#
+readme.txt.tag: NEWS.in
+ awk '/\$(DOLLAR)Id:/{ $$2 = "readme.txt\\,v"; print }' $^ > $@
+
+# The tag-line generated by the preceding rule may then be substituted, by
+# the primary readme.txt generation rule above, into the document template
+# generated by the following rule
+#
+readme.txt.in: README.in NEWS.in INSTALL.in
+ rm -f $@
+ for input in $^; do \
+ sed -f gendoc.combined.sed $$input | $(NROFF) >> $@; \
+ done
+