-
Notifications
You must be signed in to change notification settings - Fork 243
/
Makefile
101 lines (80 loc) · 2.49 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
PANDOC = pandoc
IFORMAT = markdown+raw_tex+raw_attribute+auto_identifiers+implicit_header_references
GHC = ghc
INPUT = tutorial.md
HTEMPLATE = resources/template.html
LTEMPLATE = resources/template.tex
ETEMPLATE = resources/template.epub
FLAGS = --standalone --toc --toc-depth=2 --highlight-style tango
LFLAGS = --top-level-division=chapter
PFLAGS = -V colorlinks
HFLAGS = -c css/style.css -c css/layout.css
DFLAGS =
EFLAGS =
# Targets
HTML = tutorial.html
EPUB = tutorial.epub
PPDF = tutorial_print.pdf
WPDF = tutorial.pdf
TEX = tutorial.tex
DOCX = tutorial.tex
# LaTeX
COVER = resources/cover.tex
BACK = resources/back.tex
UNICODE_MAP = resources/unicodemapping.tex
all: $(PDF) $(HTML) $(EPUB)
html: $(HTML)
docx: $(DOCX)
epub: $(epub)
pdf: $(PPDF)
# Code snippet preprocessor
includes: includes.hs
$(GHC) --make $<
# .html Target
%.html: %.md includes
./includes < $< \
| $(PANDOC) --template $(HTEMPLATE) -s -f $(IFORMAT) -t html $(FLAGS) $(HFLAGS) \
| sed '/<extensions>/r extensions.html' \
| sed '/<copyright>/r resources/copyright.html' > $@
# .docx Target
%.docx: %.md includes
./includes < $< \
| $(PANDOC) --template $(HTEMPLATE) -s -f $(IFORMAT) -t docx $(FLAGS) $(DFLAGS) > $@
# .epub Target
%.epub: %.md includes
(cat $(ETEMPLATE); ./includes < $<) \
| $(PANDOC) -f $(IFORMAT) -t epub $(FLAGS) $(EFLAGS) -o $@
# .tex Target
%.tex: %.md includes $(COVER) $(BACK)
./includes < $< \
| $(PANDOC) -c -s -f $(IFORMAT) --template $(LTEMPLATE) --include-in-header $(UNICODE_MAP) --pdf-engine=xelatex $(FLAGS) $(LFLAGS) -o $@
# .pdf Target for Print
%.pdf: $(INPUT) includes $(COVER) $(BACK)
./includes < $< \
| $(PANDOC) -c -s -f $(IFORMAT) --template $(LTEMPLATE) --include-in-header $(UNICODE_MAP) --pdf-engine=xelatex $(FLAGS) $(LFLAGS) -o $(PPDF)
# dirty hack
# .pdf Target for Web
webpdf: $(INPUT) includes $(COVER) $(BACK)
./includes < $< \
| $(PANDOC) -c -s -f $(IFORMAT) --template $(LTEMPLATE) --include-in-header $(UNICODE_MAP) --pdf-engine=xelatex $(FLAGS) $(LFLAGS) $(PFLAGS) -o $(WPDF)
errata:
$(PANDOC) -i errata.md -o errata.tex
$(PANDOC) -i errata.md -o errata.html
links:
brok tutorial.md
clean:
-rm -f $(CHAPTERS) $(HTML) $(PDF) $(EPUB) $(TEX)
# pandoc executable 'includes' is rather large
clean-all:
rm -rf $(CHAPTERS) $(HTML) includes
# NIX BUILD
# Enter nix shell with 'make run-shell' first (then 'make all')
.PHONY : run-shell
run-shell : shell.nix
ifndef NIX_GHC
nix-shell
else
$(error Already in GHC shell!)
endif
shell.nix : wiwinwlh.cabal
cabal2nix --shell . > shell.nix