diff options
author | Ulrich Müller <ulm@gentoo.org> | 2020-02-26 21:21:54 +0100 |
---|---|---|
committer | Ulrich Müller <ulm@gentoo.org> | 2020-03-01 22:40:46 +0100 |
commit | 9b663cce9ed88ec5b86cfde8d050017d23894798 (patch) | |
tree | fe51b2fa70bf3bcc6cc383b2159f82d4b0956937 | |
parent | devbook.xsl: Assign a default "depth" value for printParentDocs. (diff) | |
download | devmanual-9b663cce.tar.gz devmanual-9b663cce.tar.bz2 devmanual-9b663cce.zip |
Makefile, depend.xsl: Use XSLT to generate the list of dependencies.
Each HTML file must depend on its XML file with all its descendants
(for the contents tree), all its ancestors (for breadcrumbs), and the
previous and next documents (for backward and forward links).
Trying to generate the list of dependencies with make seems hopeless
(especially, how would one determine the previous and next documents?).
OTOH, the necessary templates already exist in devbook.xsl. Therefore,
add a simple depend.xsl on top of it, which outputs a dependency list
as plain text.
Closes: https://bugs.gentoo.org/710918
Signed-off-by: Ulrich Müller <ulm@gentoo.org>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 21 | ||||
-rw-r--r-- | depend.xsl | 33 |
3 files changed, 47 insertions, 8 deletions
@@ -1,4 +1,5 @@ *.html *.png +.depend documents.js eclass-reference/ @@ -47,20 +47,23 @@ documents.js: bin/build_search_documents.py $(XMLS) rsvg-convert --output=$@ $< # Secondary expansion allows us to use the automatic variable $@ in -# the prerequisites. When it is used (and we have no idea when that -# is, so we assume always) our <include href="foo"> tag induces a -# dependency on the output of all subdirectories of the current -# directories. This wacky rule finds all of those subdirectories by -# looking for text.xml in them, and then replaces "text.xml" in the -# path with "index.html". +# the prerequisites. # # We use the pattern %.html rather than the more-sensible %index.html # because the latter doesn't match our top-level index.html target. # .SECONDEXPANSION: -%.html: $$(dir $$@)text.xml devbook.xsl xsl/*.xsl $$(subst text.xml,index.html,$$(wildcard $$(dir $$@)*/text.xml)) +%.html: $$(dir $$@)text.xml devbook.xsl xsl/*.xsl xsltproc --param offline "$(OFFLINE)" devbook.xsl $< > $@ +# Each HTML file must depend on its XML file with all its descendants +# (for the contents tree), all its ancestors (for breadcrumbs), and +# the previous and next documents (for backward and forward links). +# Generate the list of dependencies with XSLT, which appears to be a +# better tool for this than make. +.depend: $(XMLS) depend.xsl devbook.xsl + @xsltproc depend.xsl $(XMLS) | sed ':x;s%[^ /]*/\.\./%%;tx' > $@ + install: all set -e; \ for file in $(HTMLS) $(ECLASS_HTMLS) $(IMAGES); do \ @@ -89,6 +92,8 @@ tidy: $(HTMLS) $(ECLASS_HTMLS) exit $${status} clean: - @rm -f $(HTMLS) $(IMAGES) documents.js + @rm -f $(HTMLS) $(IMAGES) documents.js .depend .PHONY: all prereq build install validate tidy clean + +-include .depend diff --git a/depend.xsl b/depend.xsl new file mode 100644 index 0000000..e0ee66c --- /dev/null +++ b/depend.xsl @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' + xmlns:exslt="http://exslt.org/common" + extension-element-prefixes="exslt xsl" + exclude-result-prefixes="exslt xsl"> + +<xsl:import href="devbook.xsl"/> +<xsl:output method="text"/> + +<xsl:template match="/"> + <xsl:variable name="refs"> + <!-- all descendants --> + <xsl:call-template name="contentsTree"/> + <!-- all ancestors --> + <xsl:call-template name="printParentDocs"/> + <!-- previous and next documents --> + <xsl:call-template name="findPrevious"/> + <xsl:call-template name="findNext"/> + </xsl:variable> + <xsl:variable name="self" select="/guide/@self"/> + <xsl:value-of select="concat($self, 'index.html:')"/> + <xsl:for-each select="exslt:node-set($refs)//a/@href[. != '#']"> + <!-- At this point, the path can contain ".." components and + should be canonicalised, but string processing in XPath 1.0 + sucks (no pattern matching!). It is easier to pipe the output + through sed instead. --> + <xsl:value-of select="concat(' ', $self, + substring-before(., 'index.html'), 'text.xml')"/> + </xsl:for-each> + <xsl:value-of select="$newline"/> +</xsl:template> + +</xsl:stylesheet> |