-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Makefile
123 lines (95 loc) · 5.59 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
.PHONY: book draft widgets publish clean download wc lint examples
FLAGS=
CHAPTERS=\
preface about intro history \
http graphics text \
html layout styles chrome \
forms scripts security \
visual-effects scheduling animations accessibility embeds invalidation \
skipped change \
glossary bibliography classes porting
EXAMPLE_HTML=$(patsubst src/example%.html,%,$(wildcard src/example*.html))
EXAMPLE_JS=$(patsubst src/example%.js,%,$(wildcard src/example*.js))
EXAMPLE_CSS=$(patsubst src/example%.css,%,$(wildcard src/example*.css))
book: $(patsubst %,www/%.html,$(CHAPTERS)) www/rss.xml widgets examples www/index.html
draft: $(patsubst %,www/draft/%.html,$(CHAPTERS)) www/onepage.html widgets
examples: $(patsubst %,www/examples/example%.html,$(EXAMPLE_HTML)) \
$(patsubst %,www/examples/example%.js,$(EXAMPLE_JS)) \
$(patsubst %,www/examples/example%.css,$(EXAMPLE_CSS))
widgets: \
www/widgets/lab1.js \
www/widgets/lab2-browser.html www/widgets/lab2.js \
www/widgets/lab3-browser.html www/widgets/lab3.js \
www/widgets/lab4-browser.html www/widgets/lab4.js \
www/widgets/lab5-browser.html www/widgets/lab5.js \
www/widgets/lab6-browser.html www/widgets/lab6.js \
www/widgets/lab7-browser.html www/widgets/lab7.js \
www/widgets/lab8-browser.html www/widgets/lab8.js www/widgets/server8.js \
www/widgets/lab9-browser.html www/widgets/lab9.js www/widgets/server9.js \
www/widgets/lab10-browser.html www/widgets/lab10.js www/widgets/server10.js \
www/widgets/lab11-browser.html www/widgets/lab11.js \
www/widgets/lab12-browser.html www/widgets/lab12.js \
www/widgets/lab13-browser.html www/widgets/lab13.js \
www/widgets/lab14-browser.html www/widgets/lab14.js \
www/widgets/lab15-browser.html www/widgets/lab15.js \
www/widgets/lab16-browser.html www/widgets/lab16.js
src/lab%.full.py: src/lab%.py infra/inline.py infra/asttools.py
python3 infra/inline.py $< > $@
src/outline%.txt: src/lab%.py infra/inline.py infra/asttools.py infra/outlines.py book/outline.txt
python3 infra/outlines.py $< --template book/outline.txt > $@
outlines: $(patsubst %,src/outline%.txt,$(shell seq 1 16))
CHAPTER=all
PANDOC=pandoc --from markdown --to html --lua-filter=infra/filter.lua --fail-if-warnings --metadata-file=config.json --highlight-style=infra/wbecode.theme $(FLAGS)
PANDOC_LATEX=pandoc --number-sections --standalone --from markdown --to latex --fail-if-warnings --metadata-file=config.json --lua-filter=infra/filter.lua --highlight-style=infra/wbecode.theme $(FLAGS)
# Generates a simple chapter latex rendering meant to be inserted into the larger book skeleton.
latex-chapters: $(patsubst %,latex/%-chapter.tex,$(CHAPTERS))
latex/%-chapter.tex: book/%.md infra/template-chapter.tex infra/filter.lua config.json
$(PANDOC_LATEX) --metadata=mode:print --template infra/template-chapter.tex $< -o $@
# Generates a skeleton latex output that has all of the setup necessary to render chapters.
latex/book-skeleton.tex: $(patsubst %,book/%.md,$(CHAPTERS)) infra/template-book.tex infra config.json
$(PANDOC_LATEX) --file-scope --template infra/template-book.tex $(patsubst %,book/%.md,$(CHAPTERS)) --metadata=mode:print -o latex/book-skeleton.tex
# Inserts the chapters into the book skeleton.
latex/book.tex: latex/book-skeleton.tex latex-chapters
cat $(patsubst %,latex/%-chapter.tex,$(CHAPTERS)) > latex/book-contents.tex
sed '/---Contents---/r latex/book-contents.tex' latex/book-skeleton.tex > latex/book.tex
rm latex/book-contents.tex
sed -i.bak '/---Contents---/d' latex/book.tex
latex/book.pdf: latex/book.tex latex/macros.tex
(cd latex && ln -f -s ../www/examples/ examples)
(cd latex && ln -f -s ../www/im/ im)
(cd latex && pdflatex book.tex)
www/%.html: book/%.md infra/template.html infra/signup.html infra/filter.lua config.json src/lab*.py
$(PANDOC) --toc --metadata=mode:book --template infra/template.html -c book.css $< -o $@
www/draft/%.html: book/%.md infra/template.html infra/signup.html infra/filter.lua config.json
$(PANDOC) --toc --metadata=mode:draft --template infra/template.html -c book.css $< -o $@
www/rss.xml: news.yaml infra/rss-template.xml
pandoc --template infra/rss-template.xml -f markdown -t html $< -o $@
www/widgets/lab%.js: src/lab%.py src/lab%.hints infra/compile.py infra/asttools.py src/runtime*.js
python3 infra/compile.py $< $@ --hints src/lab$*.hints
www/widgets/server%.js: src/server%.py src/server%.hints infra/compile.py infra/asttools.py
python3 infra/compile.py $< $@ --hints src/server$*.hints
www/onepage/%.html: book/%.md infra/chapter.html infra/filter.lua config.json src/lab*.py
$(PANDOC) --toc --metadata=mode:onepage --variable=cur:$* --template infra/chapter.html $< -o $@
www/onepage/onepage.html: ;
www/onepage.html: $(patsubst %,www/onepage/%.html,$(CHAPTERS))
www/onepage.html: book/onepage.md infra/template.html infra/filter.lua config.json
$(PANDOC) --metadata=mode:onepage --template infra/template.html -c book.css $< -o $@
bottle.py:
curl -O https://raw.githubusercontent.com/bottlepy/bottle/0.12.23/bottle.py
wc:
@ printf " Words Code File\n"; awk -f infra/wc.awk book/*.md | sort -rn
publish:
rsync -rtu --exclude=db.json --exclude=*.hash www/ server:/var/www/wbe/
ssh server chmod -Rf a+r /var/www/wbe/ || true
restart:
rsync infra/api.py server:/var/www/wbe/
ssh server sudo systemctl restart browser-engineering.service
backup:
rsync server:/var/www/wbe/db.json infra/db.$(shell date +%Y-%m-%d).pickle
test-server:
(cd www/ && python3 ../infra/server.py)
lint test:
python3 -m doctest infra/compiler.md
python3 -m doctest infra/annotate_code.md
python3 infra/runtests.py config.json --chapter $(CHAPTER)
! grep -n '^```' book/*.md | awk '(NR % 2) {print}' | grep -v '{.'