From 84181ecf089551f211ee62a9a1115eeefd1cd05f Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@debian.org>
Date: Mon, 9 Jan 2017 05:22:59 +0100
Subject: [PATCH 7/8] Update build system for DocBook conversion

Switch to use xsltproc and dblatex for the converted sources. Stop
using tidy(1) because it produces bigger files, and the output
generated by xsltproc is pretty clean and compliant already. Remove
all build dependencies not used at all or not used directly by our
build system, even if they end up being pulled anyway by our direct
dependencies.
---
 .gitignore      |  2 +-
 Makefile        | 45 ++++++++++++++++++++++++++++-----------------
 README.md       | 10 +++++-----
 debian/control  |  7 +------
 debian/rules    | 38 +++++++++++++++++---------------------
 xsl/dblatex.xsl |  9 +++++++++
 6 files changed, 61 insertions(+), 50 deletions(-)
 create mode 100644 xsl/dblatex.xsl

diff --git a/.gitignore b/.gitignore
index 66b5940..66c32a5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,7 +17,7 @@
 /stamp-build
 /stamp-binary
 /upgrading-checklist.html/
-/version.ent
+/version.xml
 *-1.html
 *.html.tar.gz
 *.pdf
diff --git a/Makefile b/Makefile
index 288c4ae..2df0ac0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,13 @@
 include debian/rules
 
-policy.sgml: version.ent
-menu-policy.sgml: version.ent
-perl-policy.sgml: version.ent
+policy.xml: version.xml
+menu-policy.xml: version.xml
+perl-policy.xml: version.xml
+upgrading-checklist.xml: version.xml
+
+XSLTPROC = xsltproc --nonet --xinclude
+XMLLINT  = xmllint --nonet --noout --postvalid --xinclude
+DBLATEX  = dblatex -p xsl/dblatex.xsl
 
 $(MDWN_FILES:=.txt): %.txt: %.md
 	cat $^ > $@
@@ -11,34 +16,40 @@ $(MDWN_FILES:=.txt): %.txt: %.md
 $(MDWN_FILES:=.html): %.html: %.md
 	$(MDWN) $< > $@
 
+upgrading-checklist-1.html \
+upgrading-checklist.html/index.html: XSLPARAMS = --stringparam generate.toc ''
+
 %.validate: %
-	onsgmls -wall -gues $<
+	$(XMLLINT) $<
 
-%.html/index.html: %.sgml
-	LANG=C debiandoc2html $<
+%.html/index.html: %.xml xsl/html-chunk.xsl
+	mkdir -p $(@D)
+	$(XSLTPROC) $(XSLPARAMS) \
+	  --stringparam base.dir $(@D)/ \
+	  xsl/html-chunk.xsl $<
 
-%-1.html: %.sgml
-	LANG=C debiandoc2html -1 -b $*-1d $< && \
-        mv $*-1d.html/index.html $*-1.html && \
-        rmdir $*-1d.html
+%-1.html: %.xml xsl/html-single.xsl
+	$(XSLTPROC) $(XSLPARAMS) xsl/html-single.xsl $< > $@
 
 %.html.tar.gz: %.html/index.html
 	GZIP=-n9 tar -czf $(<:/index.html=.tar.gz) $(<:/index.html=)
 
-$(SGML_FILES:=.txt): %.txt: %.sgml
-	LANG=C debiandoc2text $<
+$(XML_FILES:=.txt): %.txt: %.xml
+	$(XSLTPROC) $(XSLPARAMS) xsl/text.xsl $< > $@.html
+	links -dump $@.html | perl -pe 's/[\r\0]//g' > $@
+	rm -f $@.html
 
 %.txt.gz: %.txt
 	gzip -ncf9 $< > $@
 
-%.ps: %.sgml
-	LANG=C debiandoc2latexps $<
+%.ps: %.xml
+	$(DBLATEX) --ps $<
 
 %.ps.gz: %.ps
 	gzip -ncf9 $< > $@
 
-%.pdf: %.sgml
-	LANG=C debiandoc2latexpdf $<
+%.pdf: %.xml
+	$(DBLATEX) --pdf $<
 
 %.pdf.gz: %.pdf
 	gzip -ncf9 $< > $@
@@ -70,7 +81,7 @@ distclean:
 	rm -f $(filter-out $(leavealone),$(wildcard *.txt *.txt.gz *.html.tar.gz *.pdf *.ps))
 	rm -f *.lout* lout.li *.sasp* *.tex *.aux *.toc *.idx *.log *.out *.dvi *.tpt
 	rm -f `find . -name "*~" -o -name "*.bak" -o -name ".#*" -o -name core`
-	rm -f version.ent
+	rm -f version.xml
 	rm -f *.rej *.orig
 
 # if a rule bombs out, delete the target
diff --git a/README.md b/README.md
index 76a236b..68085e7 100644
--- a/README.md
+++ b/README.md
@@ -192,14 +192,14 @@ proposed wording, is:
   &lt;number&gt; is the bug number in the BTS and &lt;user&gt;is a
   designator of the Policy team member who is shepherding the bug.
 + Commit wording changes in that branch until consensus is
-  achieved. Do not modify debian/changelog or upgrading-checklist.html
+  achieved. Do not modify debian/changelog or upgrading-checklist.xml
   during this phase. Use the BTS to track who proposed the wording and
   who seconded it.
 + git pull master to make sure you have the latest version.
 + Once the change has been approved by enough people, git merge the
   branch into master immediately after making the final commit adding
   the changelog entry to minimize conflicts.
-+ add the debian/changelog and upgrading-checklist.html changes, and
++ add the debian/changelog and upgrading-checklist.xml changes, and
   commit to master.
 + Push master out so other people may merge in their own bug branches
   without conflicts.
@@ -233,8 +233,8 @@ The Git commands used for this workflow are:
 
     git checkout master
     git merge bug12345-rra
-    # edit debian/changelog and upgrading-checklist.html
-    git add debian/changelog upgrading-checklist.html
+    # edit debian/changelog and upgrading-checklist.xml
+    git add debian/changelog upgrading-checklist.xml
     git commit
     git push origin master
     git branch -d bug12345-rra
@@ -278,7 +278,7 @@ assuming that you haven't packed the refs in your repository.
 For a final Policy release, change UNRELEASED to unstable in
 debian/changelog and update the timestamp to match the final release
 time (dch -r may be helpful for this), update the release date in
-upgrading-checklist.html, update Standards-Version in debian/control,
+upgrading-checklist.xml, update Standards-Version in debian/control,
 and commit that change. Then do the final release build and make sure
 that it builds and installs.
 
diff --git a/debian/control b/debian/control
index 0f59405..87259d0 100644
--- a/debian/control
+++ b/debian/control
@@ -8,17 +8,12 @@ Uploaders:
 Section: doc
 Priority: optional
 Build-Depends:
- debiandoc-sgml (>= 1.1.47),
+ dblatex,
  docbook-xml,
  docbook-xsl,
- ghostscript,
  libtext-multimarkdown-perl,
  libxml2-utils,
  links | elinks,
- opensp,
- texlive,
- texlive-latex-extra,
- tidy,
  xsltproc,
 Standards-Version: 3.9.9
 Vcs-Browser: https://anonscm.debian.org/git/dbnpolicy/policy.git
diff --git a/debian/rules b/debian/rules
index d21ef57..33c06ab 100755
--- a/debian/rules
+++ b/debian/rules
@@ -16,11 +16,12 @@ TMPTOP	:= $(SRCTOP)/debian/tmp
 DOCDIR	:= $(TMPTOP)/usr/share/doc/$(package)
 LIBDIR	:= $(TMPTOP)/usr/share/doc-base
 
-# SGML source files in the top-level directory.  We do some common actions
-# with each of these: validate, build text, HTML, and one-page HTML output.
-SGML_FILES  := policy menu-policy perl-policy upgrading-checklist
+# DocBook source files in the top-level directory.  We do some common actions
+# with each of these: build text, HTML, and one-page HTML output.
+XML_FILES   := policy menu-policy perl-policy upgrading-checklist
 
-XML_VERSION := copyright-format/version.xml debconf_spec/include/version.xml
+XML_VERSION := copyright-format/version.xml debconf_spec/include/version.xml \
+	       version.xml
 
 # Markdown source files in the top-level directory.  We generate text and
 # HTML versions from these.
@@ -38,8 +39,8 @@ FHS_FILES   := fhs-2.3.html fhs-2.3.ps.gz fhs-2.3.txt.gz fhs-2.3.pdf.gz
 # A list of the simple Policy files that we include in the documentation
 # directory of the generated package.  The directories of HTML output are
 # handled separately.
-POLICY_FILES := $(SGML_FILES:=.txt.gz)					\
-		$(SGML_FILES:=-1.html)					\
+POLICY_FILES := $(XML_FILES:=.txt.gz)					\
+		$(XML_FILES:=-1.html)					\
 		virtual-package-names-list.txt	                        \
 		copyright-format/copyright-format-1.0.html		\
 		copyright-format/copyright-format-1.0.txt.gz		\
@@ -56,9 +57,9 @@ POLICY_FILES := $(SGML_FILES:=.txt.gz)					\
 # are individual generated files to remove.  DIRS_TO_CLEAN are entire
 # directories to remove.
 STAMPS_TO_CLEAN := stamp-binary stamp-build
-DIRS_TO_CLEAN   := $(SGML_FILES:=.html) debian/tmp fhs
-FILES_TO_CLEAN	:= $(SGML_FILES:=.txt) $(SGML_FILES:=.txt.gz)		\
-		   $(SGML_FILES:=.html.tar.gz) $(SGML_FILES:=-1.html)	\
+DIRS_TO_CLEAN   := $(XML_FILES:=.html) debian/tmp fhs
+FILES_TO_CLEAN  := $(XML_FILES:=.txt) $(XML_FILES:=.txt.gz)		\
+		   $(XML_FILES:=.html.tar.gz) $(XML_FILES:=-1.html)	\
 		   $(MDWN_FILES:=.html) $(MDWN_FILES:=.txt)		\
 		   policy.pdf.gz policy.ps.gz				\
 		   policy.pdf policy.ps policy.tpt policy.txt		\
@@ -75,9 +76,8 @@ mkdir   := install -d -o root -g root -m 755
 all build build-indep: stamp-build
 build-arch:
 stamp-build: $(MDWN_FILES:=.md)				\
-	     $(SGML_FILES:=.sgml)			\
+	     $(XML_FILES:=.xml)				\
 	     $(XML_VERSION)				\
-	     version.ent				\
 	     copyright-format/copyright-format-1.0.xml	\
 	     autopkgtest/autopkgtest.md			\
 	     autopkgtest/version.txt			\
@@ -85,10 +85,10 @@ stamp-build: $(MDWN_FILES:=.md)				\
 	     debconf_spec/include/priorities.xml	\
 	     debconf_spec/include/statuscodes.xml	\
 	     debconf_spec/include/types.xml
-	$(MAKE) $(SGML_FILES:=.sgml.validate) \
-		$(SGML_FILES:=.html.tar.gz) \
-                $(SGML_FILES:=-1.html) \
-		$(SGML_FILES:=.txt.gz) \
+	$(MAKE)	$(XML_FILES:=.xml.validate) \
+		$(XML_FILES:=.html.tar.gz) \
+		$(XML_FILES:=-1.html) \
+		$(XML_FILES:=.txt.gz) \
 		policy.ps.gz policy.pdf.gz
 	$(MAKE) $(MDWN_FILES:=.html) \
 		$(MDWN_FILES:=.txt)
@@ -100,11 +100,7 @@ stamp-build: $(MDWN_FILES:=.md)				\
 # Create the version files for inclusion in the various documents.  We want
 # to put the Policy version and date in each document, even if they
 # separately have their own versions.
-configure: version.ent $(XML_VERSION) autopkgtest/version.txt
-version.ent: debian/changelog
-	rm -f $@
-	echo "<!entity version \"$(version)\">" >> $@
-	echo "<!entity date    \"$(date)\">"	>> $@
+configure: $(XML_VERSION) autopkgtest/version.txt
 $(XML_VERSION): debian/changelog
 	rm -f $@
 	echo '<?xml version="1.0" encoding="utf-8"?>' > $@
@@ -149,7 +145,7 @@ stamp-binary: stamp-build
 #
 # Install generated HTML directories.
 #
-	@set -ex; for file in $(SGML_FILES); do			\
+	@set -ex; for file in $(XML_FILES); do			\
 		tar -C $(DOCDIR) -zxf $$file.html.tar.gz;	\
 	done
 #
diff --git a/xsl/dblatex.xsl b/xsl/dblatex.xsl
new file mode 100644
index 0000000..5824ba8
--- /dev/null
+++ b/xsl/dblatex.xsl
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+
+  <xsl:include href="common.xsl"/>
+
+  <xsl:param name="latex.output.revhistory">0</xsl:param>
+
+</xsl:stylesheet>
-- 
2.12.2.564.g063fe858b8

