-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.doc
102 lines (76 loc) · 2.99 KB
/
Makefile.doc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#
# Copyright 2019 Brightgate Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# make(1) targets for product documentation. Not standalone; include in
# top-level Makefile.
AWK = awk
SED = sed
JAVA = java
TIDY = tidy
WEASYPRINT = $(VENV_NAME)/bin/weasyprint
W3C_VALIDATOR_JAR = /opt/net.b10e/w3c-validator/18.11.5/vnu.jar
DOC_SRC_DIR = doc/src
DOC_SRC_IMGS_DIR = $(DOC_SRC_DIR)/images
# Intermediate directory where build products are produced
DOC_BLD_DIR = doc/build
DOC_BLD_IMGS_DIR = $(DOC_BLD_DIR)/images
# Output, final results of build
DOC_OUTPUT_DIR = doc/output
DOC_SRCS = \
$(DOC_SRC_DIR)/end_customer_guide.html
# If we move to an images hierarchy, this will need updating, either
# to list more directories, or to use find
DOC_IMG_PNG_SRCS = $(wildcard $(DOC_SRC_IMGS_DIR)/*.png)
DOC_IMG_MISC_SRCS = $(filter-out *.png,$(wildcard $(DOC_SRC_IMGS_DIR)/*))
DOC_BLD_IMGS = \
$(DOC_IMG_PNG_SRCS:$(DOC_SRC_IMGS_DIR)/%=$(DOC_BLD_IMGS_DIR)/%) \
$(DOC_IMG_MISC_SRCS:$(DOC_SRC_IMGS_DIR)/%=$(DOC_BLD_IMGS_DIR)/%)
DOC_BLD_KEEP = \
$(DOC_SRCS:$(DOC_SRC_DIR)/%.html=$(DOC_BLD_DIR)/%-body.html) \
$(DOC_BLD_IMGS)
DOC_OUTPUTS = \
$(DOC_SRCS:$(DOC_SRC_DIR)/%.html=$(DOC_OUTPUT_DIR)/%.pdf) \
$(DOC_BLD_KEEP)
doc: $(DOC_OUTPUTS)
doc-check:
$(JAVA) -jar $(W3C_VALIDATOR_JAR) --Werror $(DOC_SRCS)
$(TIDY) -q $(DOC_SRCS) > /dev/null
doc-clean:
$(RM) -fr $(DOC_BLD_DIR)
doc-clobber:
$(RM) -fr $(DOC_OUTPUT_DIR) $(DOC_BLD_DIR)
$(DOC_BLD_DIR):
mkdir -p $@
$(DOC_BLD_IMGS_DIR):
mkdir -p $@
$(DOC_OUTPUT_DIR):
mkdir -p $@
# Move PDF files from build to output
$(DOC_OUTPUT_DIR)/%.pdf: $(DOC_BLD_DIR)/%.pdf | $(DOC_OUTPUT_DIR)
install -m 0644 $< $@
# Run weasyprint on htmls corresponding to output pdfs
$(DOC_BLD_DIR)/%.pdf: $(DOC_BLD_DIR)/%.html $(DOC_BLD_DIR)/%.css $(DOC_BLD_IMGS) $(VENV_INSTALLED) | $(DOC_BLD_DIR)
$(PYTHON3) $(WEASYPRINT) -s $(@:.pdf=.css) $< $@
# Move any depended upon html files into the build dir
$(DOC_BLD_DIR)/%.html: $(DOC_SRC_DIR)/%.html
$(INSTALL) -m 0644 $< $@
# Move any depended upon css files into the build dir
$(DOC_BLD_DIR)/%.css: $(DOC_SRC_DIR)/%.css
$(INSTALL) -m 0644 $< $@
# Create -body.html files, which are inner portions of source HTML files
$(DOC_BLD_DIR)/%-body.html: $(DOC_SRC_DIR)/%.html | $(DOC_BLD_DIR)
$(AWK) -e '/BRIGHTGATE CONTENT END/ {p=0}; p; /BRIGHTGATE CONTENT START/ {p=1}' $< > $@
# Move images from source to build; this is the generic rule; the png rule below
# is more specific, and overrides this one where applicable
$(DOC_BLD_IMGS_DIR)/%: $(DOC_SRC_IMGS_DIR)/% | $(DOC_BLD_IMGS_DIR)
$(INSTALL) -m 0644 $< $@
# Move pngs from source to build, using pngquant to smoosh them as we go;
# ignore innocuous exit code 99
$(DOC_BLD_IMGS_DIR)/%.png: $(DOC_SRC_IMGS_DIR)/%.png | $(DOC_BLD_IMGS_DIR)
$(RM) -f $@
pngquant --quality 99-100 --speed 1 - < $< > $@; \
x=$$?; if [ $$x -eq 99 ]; then x=0; fi; exit $$x