-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
265 lines (232 loc) · 9.56 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
## markdown-easy Makefile
##
## See installation targets at the bottom.
##-----------------------------------------------------------------------------
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
##-----------------------------------------------------------------------------
## helpers and settings
##-----------------------------------------------------------------------------
## parse meta.yaml
DOC_TITLE := $(shell grep '^title:' meta.yaml | head -n1 | sed -e 's/title:[[:space:]]*//' | tr -d "'" | tr -d '"')
TEMPLATE_HTML := $(shell grep '^template_html:' meta.yaml | head -n1 | sed -e 's/template_html:[[:space:]]*//' | tr -d "'" | tr -d '"')
TEMPLATE_TEX := $(shell grep '^template_tex:' meta.yaml | head -n1 | sed -e 's/template_tex:[[:space:]]*//' | tr -d "'" | tr -d '"')
BACKMATTER_MD := $(shell grep '^backmatter_md:' meta.yaml | head -n1 | sed -e 's/backmatter_md:[[:space:]]*//' | tr -d "'" | tr -d '"')
BACKMATTER_TEX := $(shell grep '^backmatter_tex:' meta.yaml | head -n1 | sed -e 's/backmatter_tex:[[:space:]]*//' | tr -d "'" | tr -d '"')
OUTPUT := $(shell grep '^output:' meta.yaml | head -n1 | sed -e 's/output:[[:space:]]*//' | tr -d "'" | tr -d '"')
## set fixed variables
DATE_NOW := $(shell date +"%B %-d, %Y")
MD_FILES := $(filter-out README.md LICENSE.md VERSIONS.md, $(sort $(wildcard *.md)))
HTML_FILES := $(MD_FILES:%.md=%.html)
BIB_OPTIONS := --bibliography=bibs/mybib.bib --citeproc
BIB_TXT_FILES := $(sort $(wildcard bibs/*.txt))
## helpers ran within targets
PAGE_TITLE = $(shell (grep '^\#' $< | head -n1 | sed -e 's/^\#[[:space:]]*//')||(grep -B1 '====' $< | head -n1))
PRINT = @echo '==> '
##-----------------------------------------------------------------------------
## main targets
##-----------------------------------------------------------------------------
.PHONY: all default html pdf install install_for_ubuntu install_for_mac clean realclean
default: html
all: html pdf
html: $(HTML_FILES)
pdf: $(OUTPUT).pdf
install: install_for_ubuntu
##-----------------------------------------------------------------------------
## file targets
##-----------------------------------------------------------------------------
## create html
%.html: %.md bibs/mybib.bib meta.yaml
@pandoc \
-f markdown+smart \
-t html \
--ascii \
--standalone \
--variable=date_now:"$(DATE_NOW)" \
--variable=page_title:"$(PAGE_TITLE)" \
--variable=doc_title:"$(DOC_TITLE)" \
--template=$(TEMPLATE_HTML) \
--mathjax \
--filter pandoc-crossref \
$(BIB_OPTIONS) \
-o $@ $< $(BACKMATTER_MD) meta.yaml > pandoc-html.log 2>&1
$(PRINT) "make $@ done."
## create tex with references replaced and bibliography created
$(OUTPUT).tex: $(MDP_FILES) bibs/mybib.bib meta.yaml
@pandoc \
-f markdown+smart \
-t latex \
--ascii \
--standalone \
--variable=date_now:"$(DATE_NOW)" \
--template=$(TEMPLATE_TEX) \
--filter pandoc-crossref \
$(BIB_OPTIONS) \
-o $@ $(MD_FILES) $(BACKMATTER_TEX) meta.yaml > pandoc-tex.log 2>&1
$(PRINT) "make $@ done."
## create the pdf from tex
%.pdf: %.tex
@pdflatex -interaction=nonstopmode $< > latex.log 2>&1
@pdflatex -interaction=nonstopmode $< > latex.log 2>&1
@pdflatex -interaction=nonstopmode $< > latex.log 2>&1
$(PRINT) "make $@ done."
## create bibs/mybib.bib from bibs/*.txt
bibs/mybib.bib: $(BIB_TXT_FILES)
@if [ -z "$(BIB_TXT_FILES)" ] ; \
then \
echo "==> ERROR: No bibliography files found in bibs/." ; \
exit 1 ; \
else \
python scripts/markdown2bib.py --out=bibs/mybib.bib $(BIB_TXT_FILES) ; \
fi
$(PRINT) "make $@ done."
##-----------------------------------------------------------------------------
## clean targets
##-----------------------------------------------------------------------------
JUNK = *.aux *.log *.out *.tex *.toc
OUTS = *.html *.pdf bibs/*.bib
## clean up (do this)
clean:
@rm -f $(JUNK)
$(PRINT) "make $@ done."
## clean up everything including the output
realclean: clean
@rm -f $(OUTS)
$(PRINT) "make $@ done."
## make realclean and make default again
over: realclean default
##-----------------------------------------------------------------------------
## Be careful using these destructive targets
destroy: realclean
rm -f *.md
$(PRINT) "make $@ done."
destroygit:
rm -rf .git
$(PRINT) "make $@ done."
newdoc: destroy destroygit
@echo "Introduction" > 01-introduction.md
@echo "===============================================================================" >> 01-introduction.md
@echo "" >> 01-introduction.md
@echo "First subsection" >> 01-introduction.md
@echo "-------------------------------------------------------------------------------" >> 01-introduction.md
@echo "" >> 01-introduction.md
@echo "Start writing..." >> 01-introduction.md
@echo "" >> 01-introduction.md
@echo "" >> 01-introduction.md
@echo "Conclusion" >> 01-introduction.md
@echo "===============================================================================" >> 01-introduction.md
@echo "" >> 01-introduction.md
@echo "Ain't it something?" >> 01-introduction.md
@echo "" >> 01-introduction.md
@echo "" >> 01-introduction.md
@echo "Acknowledgements {.unnumbered}" >> 01-introduction.md
@echo "===============================================================================" >> 01-introduction.md
@echo "" >> 01-introduction.md
@echo "Thanks to everyone who helped with this manuscript." >> 01-introduction.md
@echo "" >> 01-introduction.md
@echo "" >> 01-introduction.md
$(PRINT) "make $@ done."
##-----------------------------------------------------------------------------
## install
## See: https://askubuntu.com/questions/1335772/using-pandoc-crossref-on-ubuntu-20-04
##-----------------------------------------------------------------------------
install_for_ubuntu:
@echo "Installing for ubuntu..." ; \
sudo apt-get -y update ; \
if [ ! -f /usr/bin/pdflatex ]; then \
echo "Installing texlive..." ; \
sudo apt-get -y install texlive-latex-extra ; \
fi ;
@echo "which pdflatex: `which pdflatex`" ; \
if [ ! -f /usr/bin/pandoc ]; then \
echo "Installing pandoc..." ; \
wget https://github.com/jgm/pandoc/releases/download/2.13/pandoc-2.13-1-amd64.deb ; \
sudo dpkg -i pandoc-2.13-1-amd64.deb ; \
fi ;
@echo "which pandoc: `which pandoc`" ; \
pandoc --version ; \
if [ ! -f /usr/local/bin/pandoc-crossref ]; then \
echo "Installing pandoc-crossref..." ; \
wget -c https://github.com/lierdakil/pandoc-crossref/releases/download/v0.3.10.0a/pandoc-crossref-Linux.tar.xz ; \
tar -xf pandoc-crossref-Linux.tar.xz ; \
sudo mv pandoc-crossref /usr/local/bin/ ; \
sudo chmod a+x /usr/local/bin/pandoc-crossref ; \
sudo mkdir -p /usr/local/man/man1 ; \
sudo mv pandoc-crossref.1 /usr/local/man/man1 ; \
fi ;
@echo "which pandoc-crossref: `which pandoc-crossref`" ; \
if [ ! -f requirements.txt ]; then \
echo "pip installing other dependencies..." ; \
pip install --upgrade pip ; \
pip install -r requirements.txt ; \
fi ;
$(PRINT) "make $@ done."
install_for_mac:
@echo "Installing for mac..." ; \
echo "Installing xcode..." ; \
xcode-select --install ; \
sudo xcodebuild -license accept ; \
echo "Installing brew..." ; \
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ; \
brew doctor ; \
brew update ; \
brew cleanup ; \
if [ ! -f /usr/local/bin/pdflatex ]; then \
echo "Installing texlive..." ; \
brew install texlive ; \
fi ;
@echo "which pdflatex: `which pdflatex`" ; \
if [ ! -f /usr/local/bin/pandoc ]; then \
echo "Installing pandoc..." ; \
wget https://github.com/jgm/pandoc/releases/download/2.13/pandoc-2.13-macOS.pkg ; \
sudo installer -pkg pandoc-2.13-macOS.pkg -target / ; \
fi ;
@echo "which pandoc: `which pandoc`" ; \
pandoc --version ; \
if [ ! -f /usr/local/bin/pandoc-crossref ]; then \
echo "Installing pandoc-crossref..." ; \
wget -c https://github.com/lierdakil/pandoc-crossref/releases/download/v0.3.10.0a/pandoc-crossref-macOS.tar.xz ; \
tar -xf pandoc-crossref-macOS.tar.xz ; \
sudo mv pandoc-crossref /usr/local/bin/ ; \
sudo chmod a+x /usr/local/bin/pandoc-crossref ; \
fi ;
@echo "which pandoc-crossref: `which pandoc-crossref`" ; \
if [ ! -f requirements.txt ]; then \
echo "pip installing other dependencies..." ; \
pip install --upgrade pip ; \
pip install -r requirements.txt ; \
fi ;
$(PRINT) "make $@ done."
install_for_windows:
@echo "Installing for windows..." ; \
choco install wget ; \
if [ ! -f /c/texlive/2024/bin/windows/pdflatex.exe ]; then \
echo "Installing texlive..." ; \
choco install texlive --params="/collections:latexrecommended,fontsrecommended,plaingeneric /extraPackages:xpatch" ; \
fi ;
@echo "which latex: `which latex`" ;
@echo "which pdftex: `which pdftex`" ;
@echo "which pdflatex: `which pdflatex`" ; \
if [ ! -f /c/texlive/2024/bin/windows/pandoc.exe ]; then \
echo "Installing pandoc..." ; \
wget https://github.com/jgm/pandoc/releases/download/2.13/pandoc-2.13-windows-x86_64.zip ; \
unzip pandoc-2.13-windows-x86_64.zip ; \
ls ; \
mv pandoc-2.13/pandoc.exe /c/texlive/2024/bin/windows/ ; \
fi ;
@echo "which pandoc: `which pandoc`" ; \
pandoc --version ; \
if [ ! -f /c/texlive/2024/bin/windows/pandoc-crossref.exe ]; then \
echo "Installing pandoc-crossref..." ; \
wget -c https://github.com/lierdakil/pandoc-crossref/releases/download/v0.3.10.0a/pandoc-crossref-Windows.7z ; \
7z x pandoc-crossref-Windows.7z ; \
ls ; \
mv pandoc-crossref.exe /c/texlive/2024/bin/windows/ ; \
fi ;
@echo "which pandoc-crossref: `which pandoc-crossref`" ; \
if [ ! -f requirements.txt ]; then \
echo "pip installing other dependencies..." ; \
pip install --upgrade pip ; \
pip install -r requirements.txt ; \
fi ;
$(PRINT) "make $@ done."