-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
175 lines (140 loc) · 6.02 KB
/
Makefile
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
RULES := pdf epub sample
CONTENT := book
PANDOC_OPTS := -F pandoc-crossref \
--citeproc \
--filter design-tools-exe \
--from markdown+fancy_lists+raw_tex+raw_html \
--bibliography=bibliography.bib \
-M link-citations \
--tab-stop=100 \
--no-highlight \
--top-level-division=part
PANDOC_PDF_OPTS := --from latex+raw_tex \
--template format/tex/template.tex \
--toc \
-s \
--top-level-division=chapter \
-t latex+lagda
PANDOC_EPUB_OPTS := --from markdown+fancy_lists+raw_html \
-F pandoc-crossref \
--toc \
--citeproc \
-s \
--css=format/epub/css.css \
--epub-cover-image art/epub-cover.png \
--no-highlight \
-M title="Certainty by Construction" \
-M subtitle="Software & Mathematics in Agda" \
-M author="Sandy Maguire" \
-M publisher="Cofree Press" \
-M rights="© 2023 Sandy Maguire" \
--top-level-division=chapter \
-f html-native_spans+raw_html \
-t epub
ALL_CHAPTERS := Chapter00-preface \
Chapter0-coblub \
Chapter1-Agda \
Chapter2-Numbers \
Chapter3-Proofs \
Chapter4-Relations \
Chapter5-Modular-Arithmetic \
Chapter6-Decidability \
Chapter7-Structures \
Chapter8-Isomorphisms \
Chapter9-ProgramOptimization \
Appendix1-Ring-Solving \
Bibliography \
Backmatter
ALL_LITERATE_AGDA := $(patsubst %,src/book/%.lagda.md,$(ALL_CHAPTERS))
ALL_LAGDA_TEX := $(patsubst src/book/%.lagda.md,build/tex/agda/%.lagda.tex,$(ALL_LITERATE_AGDA))
ALL_LAGDA_HTML := $(patsubst src/book/%.lagda.md,build-epub/agda/%.lagda.html,$(ALL_LITERATE_AGDA))
ALL_TEX := $(patsubst src/book/%.lagda.md,build/tex/book/%.tex,$(ALL_LITERATE_AGDA))
ALL_FINAL_HTML := $(patsubst src/book/%.lagda.md,build-epub/book/%.html,$(ALL_LITERATE_AGDA))
ALL_BUILD_LAGDA := $(patsubst src/book/%.lagda.md,build-epub/agda/%.lagda.md,$(ALL_LITERATE_AGDA))
ALL_BUILD_AGDA_HTML := $(patsubst src/book/%.lagda.md,build-epub/agda/html/%.md,$(ALL_LITERATE_AGDA))
ALL_BUILD_BOOK_HTML := $(patsubst src/book/%.lagda.md,build-epub/book/%.html,$(ALL_LITERATE_AGDA))
# $(RULES): %: build/%.pdf
pdf : build/pdf.pdf
print : build/print.pdf
epub : build/epub.epub
sample : build/sample.pdf
all : build/pdf.pdf build/print.pdf build/sample.pdf build-epub.epub
# -- Source the files
# Transpile markdown to latex
build/tex/agda/%.lagda.tex : src/book/%.lagda.md
pandoc $(PANDOC_OPTS) -t latex+lagda -o $@ $^
# -- Run the agda processor
# TEX
build/tex/agda/latex/%.tex : build/tex/agda/%.lagda.tex
(cd build/tex/agda && agda --latex $*.lagda.tex)
(grep UnsolvedMeta $@ > /dev/null && scripts/fix-metaspan.sh $@) || echo "ok"
# -- Copy the resulting documents
# TEX
build/tex/book/%.tex : build/tex/agda/latex/%.tex
mv $^ $@
# EPUB PIPELINE
build-epub/agda/%.lagda.md : src/book/%.lagda.md
pandoc $(PANDOC_OPTS) -t html+lagda -o $@ $^
build-epub/agda/html/%.md : build-epub/agda/%.lagda.md
(cd build-epub/agda && agda --html --html-highlight=code $*.lagda.md)
build-epub/book/%.html : build-epub/agda/html/%.md
cp $^ $@
sed -i 's/⅋[^ {}()._\\<>"]*//g' $@
sed -i 's/⅋[^ {}()._\\<>"]*//g' $@
sed -i 's/id="\([^"]\+\)"//g' $@
sed -i 's/href="\([^"]\+\)"//g' $@
sed -i 's/doc-endnotes/doc-footnote/g' $@
sed -i 's/illegal-code/code/g' $@
# HTML
build-epub/epub.epub : $(ALL_FINAL_HTML) format/epub/metadata.md build/.design-tools Makefile format/epub/css.css
cp .design-tools/*.png build/.design-tools
pandoc $(PANDOC_EPUB_OPTS) -o $@ $(ALL_FINAL_HTML)
build/epub.epub : build-epub/epub.epub
cp $^ $@
build/.design-tools :
mkdir build/.design-tools
# -- Compile all the resulting latex documents together
# TEX
build/tex/pdf.tex : $(ALL_TEX) format/tex/template.tex build/.design-tools Makefile
cp .design-tools/*.png build/.design-tools
pandoc $(PANDOC_PDF_OPTS) -M wants-cover -V wants-cover -o $@ $(ALL_TEX)
sed -i 's/\AgdaComment{--\\ !\\ \([0-9a-z]\)}/annotate{\1}/g' $@
sed -i 's/\AgdaPostulate{Level}/\AgdaFunction{Level}/g' $@
sed -i 's/\\hypertarget{fig:\([^}]\+\)}{}//g' $@
sed -i 's/⅋[^ {}()._\\]*//g' $@
sed -i 's/VERYILLEGALCODE/code/g' $@
sed -i '/{part}/d' $@
build/tex/print.tex : $(ALL_TEX) format/tex/template.tex build/.design-tools Makefile
cp .design-tools/*.png build/.design-tools
pandoc $(PANDOC_PDF_OPTS) -o $@ $(ALL_TEX)
sed -i 's/\AgdaComment{--\\ !\\ \([0-9a-z]\)}/annotate{\1}/g' $@
sed -i 's/\AgdaPostulate{Level}/\AgdaFunction{Level}/g' $@
sed -i 's/\\hypertarget{fig:\([^}]\+\)}{}//g' $@
sed -i 's/⅋[^ {}()._\\]*//g' $@
sed -i 's/VERYILLEGALCODE/code/g' $@
sed -i '/{part}/d' $@
# Copy the agda style
build/tex/agda.sty : format/tex/agda.sty
cp $^ $@
# Build the pdf!
build/pdf.pdf : $(ALL_LAGDA_TEX) build/tex/pdf.tex build/tex/agda.sty art/cover.pdf
make -C build pdf.pdf
build/print.pdf : $(ALL_LAGDA_TEX) build/tex/print.tex build/tex/agda.sty
make -C build print.pdf
# Build the sample!!
build/sample.pdf : build/pdf.pdf
qpdf build/pdf.pdf --pages . 1-24 ./build/pdf.pdf 77-114 ./build/pdf.pdf 219-258 ./build/pdf.pdf 381-384 -- build/sample.pdf
.NOTINTERMEDIATE: build/tex/agda/%.lagda.tex $(ALL_LAGDA_TEX) $(ALL_LAGDA_HTML) $(ALL_TEX) $(ALL_FINAL_HTML) $(ALL_BUILD_LAGDA) $(ALL_BUILD_AGDA_HTML) $(ALL_BUILD_BOOK_HTML)
.PHONY: clean clean-epub all $(RULES) refresh-epub
refresh-epub:
rm build-epub/book/*.html
clean-epub:
rm -r build-epub/agda/* || echo 0
rm -r build-epub/agda/html/* || echo 0
rm -r build-epub/book/* || echo 0
rm build/epub.epub || echo 0
rm build-epub/epub.epub || echo 0
clean:
rm -r build/tex/agda/*
rm -r build/tex/book/*
make -C build clean