Lines 1-40
Link Here
|
1 |
ALL_DIRS := $(shell find -name "text.xml" -exec dirname {} +) |
|
|
2 |
text_files := $(addsuffix /index.html,$(ALL_DIRS)) |
3 |
image_files := $(shell find -name "*.svg" | sed -e "s/svg$$/png/") |
4 |
|
5 |
all: prereq $(text_files) $(image_files) |
6 |
|
7 |
prereq: |
8 |
@type convert >/dev/null 2>&1 || { echo "media-gfx/imagemagick with corefonts, svg and truetype required" >&2; exit 1; }; \ |
9 |
type xsltproc >/dev/null 2>&1 || { echo "dev-libs/libxslt is required" >&2; exit 1; } |
10 |
|
11 |
%.png : %.svg |
12 |
convert $< $@ |
13 |
|
14 |
clean: |
15 |
@find . -name "*.png" -a \! -path "./icons/*" -exec rm -v {} + |
16 |
@find . -name "index.html" -exec rm -v {} + |
17 |
|
18 |
# Given a directory with text.xml in it, return its immediate children as prerequisites |
19 |
# Hypothetical example: |
20 |
# INPUT: "./archs" "./archs/amd64 ./archs/x86 ./ebuild-writing ./appendices" |
21 |
# OUTPUT: ./archs/amd64/index.html ./archs/amd64/index.html |
22 |
define get_prerequisites = |
23 |
$(addsuffix /index.html,$(foreach subdir,$(2),$(if $(subst $(1)/,,$(dir $(subdir))),,$(subdir)))) |
24 |
endef |
25 |
|
26 |
# Given a directory with text.xml in it, genereate a complete build rule with prerequisites |
27 |
# Hypothetical example: |
28 |
# INPUT: "./archs" "./archs/amd64 ./archs/x86 ./ebuild-writing ./appendices" |
29 |
# OUTPUT ./archs/index.html: ./archs/text.xml devbook.xsl ./archs/amd64/index.html ./archs/x86/index.html |
30 |
# xsltproc devbook.xsl ./archs/text.xml > ./archs/index.html |
31 |
define generate_rule = |
32 |
$(1)/index.html: $(1)/text.xml devbook.xsl $(call get_prerequisites,$(1),$(2)) |
33 |
xsltproc devbook.xsl $$< > $$@ |
34 |
endef |
35 |
|
36 |
# This generates individual build rules for all the text files by |
37 |
# iterating over all the directories in the file system tree |
38 |
$(foreach dir,$(ALL_DIRS),$(eval $(call generate_rule,$(dir),$(filter-out $(dir),$(ALL_DIRS))))) |
39 |
|
40 |
.PHONY: all prereq clean |
41 |
- |