forked from plfa/plfa.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
273 lines (208 loc) · 8.37 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
SHELL := /usr/bin/env bash
AGDA_FILES := $(shell find . -type f -and \( -path './src/*' -or -path './courses/*' \) -and -name '*.lagda.md')
AGDAI_FILES := $(shell find . -type f -and \( -path './src/*' -or -path './courses/*' \) -and -name '*.agdai')
MARKDOWN_FILES := $(subst courses/,out/,$(subst src/,out/,$(subst .lagda.md,.md,$(AGDA_FILES))))
PLFA_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
PANDOC := pandoc
EPUBCHECK := epubcheck
RUBY := ruby
GEM := $(RUBY) -S gem
BUNDLE := $(RUBY) -S bundle
JEKYLL := $(BUNDLE) exec jekyll
HTMLPROOFER := $(BUNDLE) exec htmlproofer
LUA_FILES := $(shell find . -type f -and -path '*/epub/*' -and -name '*.lua')
RELEASE_VERSIONS := 19.08 20.07
RELEASES := $(addsuffix /,$(RELEASE_VERSIONS))
LATEST_VERSION := $(word $(words $(RELEASE_VERSIONS)),$(RELEASE_VERSIONS))
ifeq ($(AGDA_STDLIB_VERSION),)
AGDA_STDLIB_URL := https://agda.github.io/agda-stdlib/
else
AGDA_STDLIB_URL := https://agda.github.io/agda-stdlib/v$(AGDA_STDLIB_VERSION)/
endif
ifeq ($(shell sed --version >/dev/null 2>&1; echo $$?),1)
SEDI := sed -i ""
else
SEDI := sed -i
endif
# Configure the repository to use .githooks
init:
git config core.hooksPath .githooks
# Build PLFA web version and test links
default: test
# Start Jekyll server with --incremental
serve:
$(JEKYLL) serve --incremental
# Start detached Jekyll server
server-start:
$(JEKYLL) serve --no-watch --detach
# Stop detached Jekyll server
server-stop:
pkill -f jekyll
.phony: serve server-start server-stop
# Build PLFA web version using Jekyll
build: $(MARKDOWN_FILES)
$(JEKYLL) build
# Build PLFA web version using Jekyll with --incremental
build-incremental: $(MARKDOWN_FILES)
$(JEKYLL) build --incremental
# Download PLFA web releases
build-history: latest/ $(RELEASES)
latest/: $(addprefix .versions/plfa.github.io-web-,$(addsuffix /,$(LATEST_VERSION)))
cd $< \
&& $(JEKYLL) clean \
&& $(JEKYLL) build --destination '../../latest' --baseurl '/latest'
# Download PLFA web release and build it under the relevant folder
define build_release
version := $(1)
out := $(addsuffix /,$(1))
url := $(addprefix https://github.com/plfa/plfa.github.io/archive/web-,$(addsuffix .zip,$(1)))
tmp_zip := $(addprefix .versions/plfa.github.io-web-,$(addsuffix .zip,$(1)))
tmp_dir := $(addprefix .versions/plfa.github.io-web-,$(addsuffix /,$(1)))
baseurl := $(addprefix /,$(1))
$$(tmp_zip): tmp_zip = $(addprefix .versions/plfa.github.io-web-,$(addsuffix .zip,$(1)))
$$(tmp_zip): url = $(addprefix https://github.com/plfa/plfa.github.io/archive/web-,$(addsuffix .zip,$(1)))
$$(tmp_zip):
@mkdir -p .versions/
wget -c $$(url) -O $$(tmp_zip)
$$(tmp_dir): version = $(1)
$$(tmp_dir): tmp_dir = $(addprefix .versions/plfa.github.io-web-,$(addsuffix /,$(1)))
$$(tmp_dir): tmp_zip = $(addprefix .versions/plfa.github.io-web-,$(addsuffix .zip,$(1)))
$$(tmp_dir): $$(tmp_zip)
yes | unzip -qq $$(tmp_zip) -d .versions/
$(SEDI) "s/branch: dev/branch: dev-$$(version)/" $$(addsuffix _config.yml,$$(tmp_dir))
$$(out): out = $(addsuffix /,$(1))
$$(out): url = $(addprefix https://github.com/plfa/plfa.github.io/archive/web-,$(addsuffix .zip,$(1)))
$$(out): tmp_dir = $(addprefix .versions/plfa.github.io-web-,$(addsuffix /,$(1)))
$$(out): baseurl = $(addprefix /,$(1))
$$(out): $$(tmp_dir)
cd $$(tmp_dir) \
&& rm -rf _posts \
&& $(JEKYLL) clean \
&& $(JEKYLL) build --destination '../../$$(out)' --baseurl '$$(baseurl)'
endef
# Incorporate previous releases of PLFA web version
$(foreach release_version,$(RELEASE_VERSIONS),$(eval $(call build_release,$(release_version))))
# Convert literal Agda to Markdown using highlight.sh
define AGDA_template
in := $(1)
out := $(subst courses/,out/,$(subst src/,out/,$(subst .lagda.md,.md,$(1))))
$$(out) : in = $(1)
$$(out) : out = $(subst courses/,out/,$(subst src/,out/,$(subst .lagda.md,.md,$(1))))
$$(out) : $$(in)
@echo "Processing $$(subst ./,,$$(in))"
@mkdir -p out/
ifeq (,$$(findstring courses/,$$(in)))
./highlight.sh $$(subst ./,,$$(in)) --include-path=src/
else
# Fix links to the file itself (out/<filename> to out/<filepath>)
./highlight.sh $$(subst ./,,$$(in)) --include-path=src/ --include-path=$$(subst ./,,$$(dir $$(in)))
endif
endef
$(foreach agda,$(AGDA_FILES),$(eval $(call AGDA_template,$(agda))))
.phony: build build-incremental
# Test links using htmlproofer
test: build
$(HTMLPROOFER) '_site'
# Test local links using htmlproofer
test-offline: build
$(HTMLPROOFER) '_site' --disable-external
# Test local links for stability under different base URLs
test-stable-offline: $(MARKDOWN_FILES)
$(JEKYLL) clean
$(JEKYLL) build --destination '_site/stable' --baseurl '/stable'
$(HTMLPROOFER) '_site' --disable-external
.phony: test test-offline test-stable-offline
# Build EPUB using Pandoc
epub: out/epub/plfa.epub
# Test EPUB using EPUBCheck
epubcheck: out/epub/plfa.epub
$(EPUBCHECK) out/epub/plfa.epub
out/epub/plfa.epub: $(AGDA_FILES) $(LUA_FILES) epub/main.css out/epub/acknowledgements.md
@mkdir -p out/epub/
$(PANDOC) --strip-comments \
--css=epub/main.css \
--epub-embed-font='assets/fonts/mononoki.woff' \
--epub-embed-font='assets/fonts/FreeMono.woff' \
--epub-embed-font='assets/fonts/DejaVuSansMono.woff' \
--lua-filter epub/include-files.lua \
--lua-filter epub/rewrite-links.lua \
--lua-filter epub/rewrite-html-ul.lua \
--lua-filter epub/default-code-class.lua -M default-code-class=agda \
--standalone \
--fail-if-warnings \
--toc --toc-depth=2 \
--epub-chapter-level=2 \
-o "$@" \
epub/index.md
out/epub/acknowledgements.md: src/plfa/acknowledgements.md _config.yml
@mkdir -p out/epub/
$(BUNDLE) exec ruby epub/render-liquid-template.rb _config.yml $< $@
.phony: epub epubcheck
# Clean auxiliary files
clean:
rm -f .agda-stdlib.sed .links-*.sed out/epub/acknowledgements.md
rm -rf .versions
ifneq ($(strip $(AGDAI_FILES)),)
rm $(AGDAI_FILES)
endif
# Clean generated files
clobber: clean
$(JEKYLL) clean
rm -rf out/
rm -rf latest/ $(RELEASES)
.phony: clean clobber
# Setup Travis
travis-setup:\
travis-install-agda\
travis-install-agda-stdlib\
travis-install-acknowledgements
.phony: travis-setup
# Setup Agda
travis-install-agda:\
$(HOME)/.local/bin/agda\
$(HOME)/.agda/defaults\
$(HOME)/.agda/libraries
$(HOME)/.agda/defaults:
echo "standard-library" >> $(HOME)/.agda/defaults
echo "plfa" >> $(HOME)/.agda/defaults
$(HOME)/.agda/libraries:
echo "$(HOME)/agda-stdlib-$(AGDA_STDLIB_VERSION)/standard-library.agda-lib" >> $(HOME)/.agda/libraries
echo "$(PLFA_DIR)/plfa.agda-lib" >> $(HOME)/.agda/libraries
$(HOME)/.local/bin/agda:
curl -L https://github.com/agda/agda/archive/v$(AGDA_VERSION).zip\
-o $(HOME)/agda-$(AGDA_VERSION).zip
unzip -qq $(HOME)/agda-$(AGDA_VERSION).zip -d $(HOME)
cd $(HOME)/agda-$(AGDA_VERSION);\
stack install --stack-yaml=stack-$(GHC_VERSION).yaml
travis-uninstall-agda:
rm -rf $(HOME)/agda-$(AGDA_VERSION)/
rm -f $(HOME)/.local/bin/agda
rm -f $(HOME)/.local/bin/agda-mode
travis-reinstall-agda: travis-uninstall-agda travis-install-agda
.phony: travis-install-agda travis-uninstall-agda travis-reinstall-agda
# Setup Agda Standard Library
travis-install-agda-stdlib: $(HOME)/agda-stdlib-$(AGDA_STDLIB_VERSION)/src
$(HOME)/agda-stdlib-$(AGDA_STDLIB_VERSION)/src:
curl -L https://github.com/agda/agda-stdlib/archive/v$(AGDA_STDLIB_VERSION).zip\
-o $(HOME)/agda-stdlib-$(AGDA_STDLIB_VERSION).zip
unzip -qq $(HOME)/agda-stdlib-$(AGDA_STDLIB_VERSION).zip -d $(HOME)
mkdir -p $(HOME)/.agda
travis-uninstall-agda-stdlib:
rm $(HOME)/.agda/defaults
rm $(HOME)/.agda/libraries
rm -rf $(HOME)/agda-stdlib-$(AGDA_STDLIB_VERSION)/
travis-reinstall-agda-stdlib: travis-uninstall-agda-stdlib travis-install-agda-stdlib
.phony: travis-install-agda-stdlib travis-uninstall-agda-stdlib travis-reinstall-agda-stdlib epub
# Setup Acknowledgements
travis-install-acknowledgements: $(HOME)/.local/bin/acknowledgements
$(HOME)/.local/bin/acknowledgements:
curl -L https://github.com/plfa/acknowledgements/archive/master.zip\
-o $(HOME)/acknowledgements-master.zip
unzip -qq $(HOME)/acknowledgements-master.zip -d $(HOME)
cd $(HOME)/acknowledgements-master;\
stack install
travis-uninstall-acknowledgements:
rm -rf $(HOME)/acknowledgements-master/
rm $(HOME)/.local/bin/acknowledgements
travis-reinstall-acknowledgements: travis-uninstall-acknowledgements travis-reinstall-acknowledgements
.phony: travis-install-acknowledgements travis-uninstall-acknowledgements travis-reinstall-acknowledgements