1 |
commit: 7977d86d8cfa8ef8b4368c338cb6933024361186 |
2 |
Author: Göktürk Yüksek <gokturk <AT> binghamton <DOT> edu> |
3 |
AuthorDate: Tue Mar 29 09:48:40 2016 +0000 |
4 |
Commit: Ulrich Müller <ulm <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Apr 2 08:07:24 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/devmanual.git/commit/?id=7977d86d |
7 |
|
8 |
Makefile: construct the full dependency tree instead of pattern matching |
9 |
|
10 |
Currently, the Makefile assumes that each document can be |
11 |
independently transformed and thus exposes a flat dependency |
12 |
hierarchy. This is incorrect because of the way table of contents |
13 |
(TOC) is generated. When a page is added or removed, its immediate |
14 |
parent and all of the parent's parents, all the way up to the root |
15 |
node, need to be recompiled in a bottom-up fashion to regenerate the |
16 |
TOC in each page. |
17 |
|
18 |
Use black magic to automatically generate build rules with proper |
19 |
prerequisites during runtime. The idea is to mirror the hierarchy in the |
20 |
document: every section has a dependency to its subsections. The rules |
21 |
are generated by iterating through each directory in the entire file |
22 |
system tree. |
23 |
|
24 |
Signed-off-by: Göktürk Yüksek <gokturk <AT> binghamton.edu> |
25 |
|
26 |
Makefile | 33 +++++++++++++++++++++++++-------- |
27 |
1 file changed, 25 insertions(+), 8 deletions(-) |
28 |
|
29 |
diff --git a/Makefile b/Makefile |
30 |
index f22f304..d4182a8 100644 |
31 |
--- a/Makefile |
32 |
+++ b/Makefile |
33 |
@@ -1,4 +1,5 @@ |
34 |
-text_files := $(shell find -name "text.xml" | sed -e "s/text.xml$$/index.html/") |
35 |
+ALL_DIRS := $(shell find -name "text.xml" -exec dirname {} +) |
36 |
+text_files := $(addsuffix /index.html,$(ALL_DIRS)) |
37 |
image_files := $(shell find -name "*.svg" | sed -e "s/svg$$/png/") |
38 |
|
39 |
all: prereq $(text_files) $(image_files) |
40 |
@@ -7,13 +8,6 @@ prereq: |
41 |
@type -p convert &>/dev/null || { echo "media-gfx/imagemagick with corefonts, svg and truetype required" >&2; exit 1; }; \ |
42 |
type -p xsltproc &>/dev/null || { echo "dev-libs/libxslt is required" >&2; exit 1; } |
43 |
|
44 |
-%index.html : %text.xml devbook.xsl |
45 |
- xsltproc devbook.xsl $< > $@ |
46 |
- |
47 |
-# Someone should figure out a way to put this to the pattern |
48 |
-index.html : text.xml devbook.xsl |
49 |
- xsltproc devbook.xsl $< > $@ |
50 |
- |
51 |
%.png : %.svg |
52 |
convert $< $@ |
53 |
|
54 |
@@ -21,3 +15,26 @@ clean: |
55 |
@find . -name "*.png" -a \! -path "./icons/*" -exec rm -v {} + |
56 |
@find . -name "index.html" -exec rm -v {} + |
57 |
|
58 |
+# Given a directory with text.xml in it, return its immediate children as prerequisites |
59 |
+# Hypothetical example: |
60 |
+# INPUT: "./archs" "./archs/amd64 ./archs/x86 ./ebuild-writing ./appendices" |
61 |
+# OUTPUT: ./archs/amd64/index.html ./archs/amd64/index.html |
62 |
+define get_prerequisites = |
63 |
+$(addsuffix /index.html,$(foreach subdir,$(2),$(if $(subst $(1)/,,$(dir $(subdir))),,$(subdir)))) |
64 |
+endef |
65 |
+ |
66 |
+# Given a directory with text.xml in it, genereate a complete build rule with prerequisites |
67 |
+# Hypothetical example: |
68 |
+# INPUT: "./archs" "./archs/amd64 ./archs/x86 ./ebuild-writing ./appendices" |
69 |
+# OUTPUT ./archs/index.html: ./archs/text.xml devbook.xsl ./archs/amd64/index.html ./archs/x86/index.html |
70 |
+# xsltproc devbook.xsl ./archs/text.xml > ./archs/index.html |
71 |
+define generate_rule = |
72 |
+$(1)/index.html: $(1)/text.xml devbook.xsl $(call get_prerequisites,$(1),$(2)) |
73 |
+ xsltproc devbook.xsl $$< > $$@ |
74 |
+endef |
75 |
+ |
76 |
+# This generates individual build rules for all the text files by |
77 |
+# iterating over all the directories in the file system tree |
78 |
+$(foreach dir,$(ALL_DIRS),$(eval $(call generate_rule,$(dir),$(filter-out $(dir),$(ALL_DIRS))))) |
79 |
+ |
80 |
+.PHONY: all prereq clean |