-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
309 lines (243 loc) · 8.42 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
###############################################################################
#
# How To Use this Makefile
#------------------------------------------------------------------------------
# Let's say you have a markdown source file named foo.md in the 'fr' directory
#
# - `make fr/foo.pdf` will build a PDF from fr/foo.md
# - `make fr/foo.epub` will build an EPUB from fr/foo.md
# - `make all` will build all source files in all formats
# - `make clean` will remove all build artifacts
#
# Pandoc or docker ?
#------------------------------------------------------------------------------
#
# - by default, we use pandoc to compile documents
# - if pandoc is not installed, we use a docker image instead
# see https://github.com/dalibo/pandocker/
# - use `DOCKER=latest make all` to force make to use docker
#
###############################################################################
###############################################################################
# Folders
SOURCES=en fr
DEST=_build
PATHS := $(shell find $(SOURCES) -maxdepth 1 -mindepth 1 -type d)
PATHS := $(filter-out %/include %/medias, $(PATHS))
WORKSHOPS := $(notdir $(PATHS))
INDEX := $(shell find $(SOURCES) -type f -name index.md)
THEME := $(realpath theme/)
###############################################################################
# Functions
ECHO=$(info Compiling $^ into $@)
DIR=`dirname $^`
###############################################################################
# Sources and default formats
# README files and other documentation markdown files are not compiled
EXCLUDE_FILES=.*\(LICENSE\|README\|QUICKSTART\|CONTRIBUTING\|SYNTAX\|INSTALL\|AUTHORS\)\.md
EXCLUDE_SRC=$(shell find $(SOURCES) -regex "$(EXCLUDE_FILES)" -type f)
# SRC is the list of all the source markdown files
SRC := $(filter-out $(EXCLUDE_SRC), $(shell find $(PATHS) -maxdepth 1 -type f -name '*.md'))
# See make help to know which are really supported
# Uncommented formats are generated by default
SRC_FORMATS = FILE.md
#SRC_FORMATS+= FILE.docx
SRC_FORMATS+= FILE.epub
SRC_FORMATS+= FILE.handout.html
#SRC_FORMATS+= FILE.odt
#SRC_FORMATS+= FILE.tex
SRC_FORMATS+= FILE.pdf
#SRC_FORMATS+= FILE.beamer.pdf
SRC_FORMATS+= FILE.slides.html
#SRC_FORMATS+= FILE.slides.local.html
#SRC_FORMATS+= FILE.slides.s5.html
###############################################################################
# Pandoc
#
# Parameters common to pandoc when called directly and through docker
PANDOC_HEADERS=theme/metadata.yml
PANDOC_PARAMS?=--filter=pandoc-jinja --filter=pandoc-include
# PANDOC_MARKDOWN_FLAVOR=markdown-smart
PANDOC_MARKDOWN_FLAVOR=markdown-escaped_line_breaks
# Common arguments
PANDOC_ARGS?=--from=$(PANDOC_MARKDOWN_FLAVOR) \
--metadata-file=$(PANDOC_HEADERS) \
--strip-comments \
--resource-path=.:theme
# by default we use the local pandoc (if installed)
PANDOC_BIN?=pandoc
PANDOC:=$(PANDOC_BIN) $(PANDOC_PARAMS) $(PANDOC_ARGS)
# if pandoc is not installed, force docker use
ifeq (, $(shell which $(PANDOC_BIN)))
# do not forget to update .gitlab-ci.yml too
PANDOCKER_TAG?=latest
# PANDOCKER_TAG?=23.03
# --privileged is necessary for people using SELinux
# --rm removes the container after execution
PANDOC:=docker run \
--privileged --rm -it \
--volume `pwd`:/pandoc --volume $(THEME):/pandoc/theme \
dalibo/pandocker:$(PANDOCKER_TAG) $(PANDOC_PARAMS) $(PANDOC_ARGS)
endif
# Default templates
PANDOC_PDF_TEMPLATE?=eisvogel
PANDOC_HTML_TEMPLATE?=uikit
# Relative path to resources
PANDOC_RESOURCES=--resource-path=$(DIR) --metadata=include-entry:$(DIR)
##########################
# Pandoc Compilation Flags
MARKDOWN_FLAGS=--to markdown
# Included in make all
HTML_FLAGS=--to html --template=$(PANDOC_HTML_TEMPLATE) \
--embed-resources --standalone --toc --toc-depth=2 \
--css theme/dalibo.uikit.css \
$(PANDOC_RESOURCES)
PDF_FLAGS=--template=$(PANDOC_PDF_TEMPLATE) \
--pdf-engine=xelatex \
--pdf-engine-opt=-shell-escape \
--toc --number-sections \
--top-level-division=chapter \
--filter=pandoc-cover \
--filter=pandoc-latex-environment \
$(PANDOC_RESOURCES)
EPUB_FLAGS=$(PANDOC_RESOURCES)
# Force the use of the revealjs cache inside pandocker
REVEAL_FLAGS=--to revealjs --standalone --variable=revealjs-url:file:/// \
--css theme/dalibo.reveal.css --embed-resources \
$(PANDOC_RESOURCES)
# NOT included in make All
S5_FLAGS=--to s5 --embed-resources --standalone $(PANDOC_RESOURCES)
# NOT supported
BEAMER_FLAGS= -st beamer $(PANDOC_RESOURCES)
ODT_FLAGS=$(PANDOC_RESOURCES)
DOC_FLAGS=$(PANDOC_RESOURCES)
###############################################################################
# HTML handout
HTML_OJBS=$(SRC:.md=.handout.html)
OBJS += $(HTML_OJBS)
%.handout.html: %.md
$(ECHO)
$(PANDOC) $(HTML_FLAGS) $^ -o $@
###############################################################################
# Marketing markdown
%.pdf.md: %.md
$(ECHO)
cat $^ \
$(THEME)/marketing/notes.md \
$(THEME)/marketing/publications.md \
$(THEME)/marketing/backcover.md > $@
###############################################################################
# Peecho and Nocover PDF handouts
PEECHO_OBJS=$(SRC:.md=.pdf)
OBJS += $(PEECHO_OBJS)
%.pdf: %.pdf.md
$(ECHO)
$(PANDOC) $(PDF_FLAGS) $^ -o $@
PDF_OBJS=$(SRC:.md=.nocover.pdf)
OBJS += $(PDF_OBJS)
%.nocover.pdf: %.md
$(ECHO)
$(PANDOC) $(PDF_FLAGS) $^ -o $@
###############################################################################
# Reveal Slides
REVEAL_OBJS=$(SRC:.md=.slides.html)
OBJS += $(REVEAL_OBJS)
%.slides.html: %.md
$(ECHO)
$(PANDOC) $(REVEAL_FLAGS) $^ -o $@
REVEAL_LOCAL_OBJS=$(SRC:.md=.slides.local.html)
OBJS += $(REVEAL_LOCAL_OBJS)
%.slides.local.html: %.md
$(ECHO)
$(PANDOC) $(REVEAL_LOCAL_FLAGS) $^ -o $@
###############################################################################
# Epub handout
EPUB_OBJS=$(SRC:.md=.epub)
OBJS += $(EPUB_OBJS)
%.epub: %.md
$(ECHO)
$(PANDOC) $(EPUB_FLAGS) $^ -o $@
###############################################################################
# DOCX and ODT handouts
DOCX_OBJS=$(SRC:.md=.docx)
OBJS += $(DOCX_OBJS)
%.docx: %.md
$(ECHO)
$(PANDOC) $(DOCX_FLAGS) $^ -o $@
ODT_OBJS=$(SRC:.md=.odt)
OBJS += $(ODT_OBJS)
%.odt: %.md
$(ECHO)
$(PANDOC) $(ODT_FLAGS) $^ -o $@
###############################################################################
# Others slides
BEAMER_OBJS=$(SRC:.md=.beamer.pdf)
OBJS += $(BEAMER_OBJS)
%.beamer.pdf: %.md
$(ECHO)
TEXMFHOME=$(DLB)/beamer $(PANDOC) $(BEAMER_FLAGS) $^ -o $@
S5_OJBS=$(SRC:.md=.slides.s5.html)
OBJS += $(S5_OJBS)
%.slides.s5.html: %.md
$(ECHO)
$(PANDOC) $(S5_FLAGS) $^ -o $@
###############################################################################
# Others formats rules
JSON_OBJS=$(SRC:.md=.json)
OBJS += $(JSON_OBJS)
%.json: %.md
$(ECHO)
$(PANDOC) $(JSON_FLAGS) $^ -o $@
TEX_OBJS=$(SRC:.md=.tex)
OBJS += $(TEX_OBJS)
%.tex: %.md
$(ECHO)
$(PANDOC) $(TEX_FLAGS) $^ -o $@
%.all: %.html %.tex %.beamer.pdf %.pdf %.odt %.docx %.epub
$(ECHO)
###############################################################################
# Index
INDEX_OJBS=$(INDEX:.md=.html)
OBJS += $(INDEX_OJBS)
%/index.html: %/index.md
$(PANDOC) -t html5 --embed-resources --standalone $^ -o $@
###############################################################################
# Global Targets
all: reveal html pdf epub index
# Dynamic target definition
define workshop_target =
$(lastword $(subst /, ,$(dir $(1)))): $(subst FILE, $(basename $(1)),$(SRC_FORMATS)) index
endef
# Invoke markdown rules for each workshop directory
$(foreach src, $(SRC), $(eval $(call workshop_target,$(src))))
# Supported formats
beamer: $(BEAMER_OBJS)
docx: $(DOCX_OBJS)
epub: $(EPUB_OBJS)
html: $(HTML_OJBS)
json: $(JSON_OBJS)
nocover_pdf: $(PDF_OBJS)
odt: $(ODT_OBJS)
pdf: $(PEECHO_OBJS)
reveal: $(REVEAL_OBJS)
tex: $(TEX_OBJS)
index: $(INDEX_OJBS)
clean:
rm -f $(OBJS)
rm -r $(DEST)
test:
@echo $(OBJS) | tr " " "\n"
# stage generated files into _build directory, needed by deploy CI stage
deploy:
for LANG in en fr ; do \
mkdir -p $(DEST)/$$LANG ;\
find $$LANG \( -name "*.html" -or -name "*.pdf" -or -name "*.epub" \) \
-print -exec cp {} _build/$$LANG \; ;\
done
# stage all archived files from _archives to $(DEST) directory
archives: deploy
for LANG in en fr ; do \
mkdir -p $(DEST)/$$LANG ;\
find _archives/$$LANG \( -name "*.html" -or -name "*.pdf" -or -name "*.epub" \) \
-print -exec cp {} $(DEST)/$$LANG \; ;\
done