-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
220 lines (185 loc) · 5.64 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
# Generate HTML5 and PDF from the Markdown source files
#
# Derived from:
# https://gist.github.com/bertvv/e77e3a5d24d8c2a9bcc4
# https://gist.github.com/prwhite/8168133
#
# In order to use this makefile, you need some tools:
# - GNU make
# - Pandoc >= 3.5
# - XeLaTeX
# - KOMA-Script
# - Python >= 3.9
# - panflute
# - MarkdownPP
# - ghp-import
.SUFFIXES:
# Variables {{{
# Directory containing source files
source := $(CURDIR)
# Select default fontsize for XeLaTeX.
fontsize := 12pt
# Pandoc peripheral files for conversion.
pandoc_pdf := biblio.bib ieee-with-url.csl link_filter.py date.lua
pandoc_html := $(pandoc_pdf) pandoc.html5
# Output paths.
remodel := docs
htmloutput := $(remodel)
staticoutput := $(remodel)
templates := $(remodel)
# Directory containing pdf files
# make large overrides location, etc.
pdfoutput := print$(large)
# Static files to copy or process into docs directory.
staticfiles := $(wildcard $(source)/*.css)
staticfiles += $(wildcard $(source)/*.zip)
staticfiles += $(wildcard $(source)/*.html)
staticobjects := $(subst $(source),$(staticoutput),$(staticfiles))
# $(info staticobjects is $(staticobjects))
# All MarkdownPP files in $(source)
# Assume Markdown files are pre-requisites for MarkdownPP files.
# Otherwise, specify MarkdownPP dependencies (!INCLUDE directives)
markdownpp := $(wildcard $(source)/*.mdpp)
markdown := $(wildcard $(source)/*.md)
markdown := $(subst $(source),$(source)/tmp,$(markdown))
# $(info markdown is $(markdown))
# Map MarkdownPP files to html and pdf targets.
htmloutputs := $(subst .mdpp,.html,$(markdownpp))
htmloutputs := $(subst $(source),$(htmloutput),$(htmloutputs))
pdfoutputs := $(subst .mdpp,.pdf,$(markdownpp))
pdfoutputs := $(subst $(source),$(pdfoutput),$(pdfoutputs))
# $(info pdfoutputs is $(pdfoutputs))
texoutputs := $(subst .pdf,.tex,$(pdfoutputs))
# $(info pdfoutputs is $(pdfoutputs))
# End Variables }}}
# Help {{{
.DEFAULT_GOAL := help
.PHONY: help
.SILENT: help
## Show the help message
help:
$(HELP_MESSAGE)
# COLORS
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
TARGET_MAX_CHAR_NUM=20
define HELP_MESSAGE
echo ''
echo 'Usage:'
echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
echo ''
echo 'Targets:'
awk '/^[a-zA-Z\-_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
endef
# End Help }}}
# Explicit Rules {{{
.PHONY: all pdf html large tex publish
## Generate HTML5 and PDF from the Markdown source files
all: pdf html
## Generate PDF from the Markdown source files
pdf: $(pdfoutput)/Richland_Prefab_2BR.pdf $(pdfoutput)/Phase1.pdf | $(pdfoutput)/
## Generate HTML with CSS, JavaScript and SweetHome3D plan on website.
html: $(htmloutputs) $(staticobjects) | $(htmloutput)/
## Generate PDF with larger fonts for accessibility.
large:
$(MAKE) pdf large:=large fontsize:=17pt
## Generate intermediate LaTeX for reviewing pdf recipe.
tex: $(texoutputs) | $(pdfoutput)/
## Publish HTML5 to Github Pages.
publish: html
./gh-pages.sh
# }}}
# Recipe for converting a Markdown file to pdf or LaTeX using Pandoc {{{
$(pdfoutput)/%.pdf $(pdfoutput)/%.tex : $(source)/%.md $(pandoc_pdf) | $(pdfoutput)/
pandoc \
--citeproc \
--variable fontsize=$(fontsize) \
--variable papersize=letter \
--variable links-as-notes \
--variable colorlinks \
--filter link_filter.py \
--lua-filter date.lua \
--table-of-contents \
--number-sections \
--bibliography="biblio.bib" --csl="ieee-with-url.csl" \
--from=markdown $< \
--pdf-engine=xelatex \
--output $@
# }}}
# Recipe for converting a Markdown file into HTML5 using Pandoc {{{
.SECONDARY: $(staticobjects)
$(htmloutput)/%.html : $(source)/%.md $(pandoc_html) | $(htmloutput)/
pandoc \
--standalone \
--citeproc \
--shift-heading-level-by=1 \
--filter link_filter.py \
--lua-filter date.lua \
--table-of-contents \
--bibliography="biblio.bib" --csl="ieee-with-url.csl" \
--highlight-style=breezedark \
--template="pandoc.html5" \
--css="pandoc.css" \
--from=markdown $< \
--to="html5" \
--output $@
$(staticoutput)/Home_Plan.zip : $(source)/Home_Plan.zip | $(staticoutput)/
$(MAKE) cleanhome
unzip Home_Plan.zip lib/* Home_Plan.zip -d $(staticoutput)
touch $(staticoutput)/Home_Plan.zip
$(source)/tmp/%.md : $(source)/%.md | $(source)/tmp/
pandoc \
--from=markdown $< \
--markdown-headings=atx \
--to=markdown \
--output $@
%.md : %.mdpp $(markdown)
markdown-pp $< --output $@
$(staticoutput)/% : $(CURDIR)/% | $(staticoutput)/
cp $< $@
$(templates)/% : $(CURDIR)/% | $(templates)/
cp $< $@
$(htmloutput)/% : $(CURDIR)/% | $(htmloutput)/
cp $< $@
# }}}
# Order out rule to create directories if needed {{{
$(pdfoutput)/ $(htmloutput)/ $(source)/tmp/ :
mkdir -p $@
# }}}
# Recipe for clean {{{
.PHONY: clean cleanall cleanhtml cleanhome cleanpdf cleanlarge
## Remove all output: cleanhtml cleanhome cleanpdf cleanlarge.
clean: cleanhtml cleanhome cleanpdf cleanlarge cleantmp
## Remove HTML output.
cleanhtml :
rm -rf $(htmloutput)
## Remove SweetHome 3D Home Plan from output.
cleanhome :
rm -rf $(staticoutput)/Home_Plan.zip
rm -rf $(staticoutput)/lib
## Remove pdf output.
cleanpdf :
rm -rf $(pdfoutput)
## Remove large pdf output.
cleanlarge :
rm -rf $(pdfoutput)large
## Remove large intermediate tmp directory.
cleantmp :
rm -rf $(source)/tmp/
# }}}
# Test recipe {{{
.PHONY: test
test :
$(MAKE)
$(MAKE) help
# }}}