1 |
commit: 9b663cce9ed88ec5b86cfde8d050017d23894798 |
2 |
Author: Ulrich Müller <ulm <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Feb 26 20:21:54 2020 +0000 |
4 |
Commit: Ulrich Müller <ulm <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Mar 1 21:40:46 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/devmanual.git/commit/?id=9b663cce |
7 |
|
8 |
Makefile, depend.xsl: Use XSLT to generate the list of dependencies. |
9 |
|
10 |
Each HTML file must depend on its XML file with all its descendants |
11 |
(for the contents tree), all its ancestors (for breadcrumbs), and the |
12 |
previous and next documents (for backward and forward links). |
13 |
|
14 |
Trying to generate the list of dependencies with make seems hopeless |
15 |
(especially, how would one determine the previous and next documents?). |
16 |
OTOH, the necessary templates already exist in devbook.xsl. Therefore, |
17 |
add a simple depend.xsl on top of it, which outputs a dependency list |
18 |
as plain text. |
19 |
|
20 |
Closes: https://bugs.gentoo.org/710918 |
21 |
Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org> |
22 |
|
23 |
.gitignore | 1 + |
24 |
Makefile | 21 +++++++++++++-------- |
25 |
depend.xsl | 33 +++++++++++++++++++++++++++++++++ |
26 |
3 files changed, 47 insertions(+), 8 deletions(-) |
27 |
|
28 |
diff --git a/.gitignore b/.gitignore |
29 |
index ce644c7..7c45b92 100644 |
30 |
--- a/.gitignore |
31 |
+++ b/.gitignore |
32 |
@@ -1,4 +1,5 @@ |
33 |
*.html |
34 |
*.png |
35 |
+.depend |
36 |
documents.js |
37 |
eclass-reference/ |
38 |
|
39 |
diff --git a/Makefile b/Makefile |
40 |
index 4879792..be1224f 100644 |
41 |
--- a/Makefile |
42 |
+++ b/Makefile |
43 |
@@ -47,20 +47,23 @@ documents.js: bin/build_search_documents.py $(XMLS) |
44 |
rsvg-convert --output=$@ $< |
45 |
|
46 |
# Secondary expansion allows us to use the automatic variable $@ in |
47 |
-# the prerequisites. When it is used (and we have no idea when that |
48 |
-# is, so we assume always) our <include href="foo"> tag induces a |
49 |
-# dependency on the output of all subdirectories of the current |
50 |
-# directories. This wacky rule finds all of those subdirectories by |
51 |
-# looking for text.xml in them, and then replaces "text.xml" in the |
52 |
-# path with "index.html". |
53 |
+# the prerequisites. |
54 |
# |
55 |
# We use the pattern %.html rather than the more-sensible %index.html |
56 |
# because the latter doesn't match our top-level index.html target. |
57 |
# |
58 |
.SECONDEXPANSION: |
59 |
-%.html: $$(dir $$@)text.xml devbook.xsl xsl/*.xsl $$(subst text.xml,index.html,$$(wildcard $$(dir $$@)*/text.xml)) |
60 |
+%.html: $$(dir $$@)text.xml devbook.xsl xsl/*.xsl |
61 |
xsltproc --param offline "$(OFFLINE)" devbook.xsl $< > $@ |
62 |
|
63 |
+# Each HTML file must depend on its XML file with all its descendants |
64 |
+# (for the contents tree), all its ancestors (for breadcrumbs), and |
65 |
+# the previous and next documents (for backward and forward links). |
66 |
+# Generate the list of dependencies with XSLT, which appears to be a |
67 |
+# better tool for this than make. |
68 |
+.depend: $(XMLS) depend.xsl devbook.xsl |
69 |
+ @xsltproc depend.xsl $(XMLS) | sed ':x;s%[^ /]*/\.\./%%;tx' > $@ |
70 |
+ |
71 |
install: all |
72 |
set -e; \ |
73 |
for file in $(HTMLS) $(ECLASS_HTMLS) $(IMAGES); do \ |
74 |
@@ -89,6 +92,8 @@ tidy: $(HTMLS) $(ECLASS_HTMLS) |
75 |
exit $${status} |
76 |
|
77 |
clean: |
78 |
- @rm -f $(HTMLS) $(IMAGES) documents.js |
79 |
+ @rm -f $(HTMLS) $(IMAGES) documents.js .depend |
80 |
|
81 |
.PHONY: all prereq build install validate tidy clean |
82 |
+ |
83 |
+-include .depend |
84 |
|
85 |
diff --git a/depend.xsl b/depend.xsl |
86 |
new file mode 100644 |
87 |
index 0000000..e0ee66c |
88 |
--- /dev/null |
89 |
+++ b/depend.xsl |
90 |
@@ -0,0 +1,33 @@ |
91 |
+<?xml version="1.0" encoding="UTF-8"?> |
92 |
+<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' |
93 |
+ xmlns:exslt="http://exslt.org/common" |
94 |
+ extension-element-prefixes="exslt xsl" |
95 |
+ exclude-result-prefixes="exslt xsl"> |
96 |
+ |
97 |
+<xsl:import href="devbook.xsl"/> |
98 |
+<xsl:output method="text"/> |
99 |
+ |
100 |
+<xsl:template match="/"> |
101 |
+ <xsl:variable name="refs"> |
102 |
+ <!-- all descendants --> |
103 |
+ <xsl:call-template name="contentsTree"/> |
104 |
+ <!-- all ancestors --> |
105 |
+ <xsl:call-template name="printParentDocs"/> |
106 |
+ <!-- previous and next documents --> |
107 |
+ <xsl:call-template name="findPrevious"/> |
108 |
+ <xsl:call-template name="findNext"/> |
109 |
+ </xsl:variable> |
110 |
+ <xsl:variable name="self" select="/guide/@self"/> |
111 |
+ <xsl:value-of select="concat($self, 'index.html:')"/> |
112 |
+ <xsl:for-each select="exslt:node-set($refs)//a/@href[. != '#']"> |
113 |
+ <!-- At this point, the path can contain ".." components and |
114 |
+ should be canonicalised, but string processing in XPath 1.0 |
115 |
+ sucks (no pattern matching!). It is easier to pipe the output |
116 |
+ through sed instead. --> |
117 |
+ <xsl:value-of select="concat(' ', $self, |
118 |
+ substring-before(., 'index.html'), 'text.xml')"/> |
119 |
+ </xsl:for-each> |
120 |
+ <xsl:value-of select="$newline"/> |
121 |
+</xsl:template> |
122 |
+ |
123 |
+</xsl:stylesheet> |