-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
284 lines (208 loc) · 6.07 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
# =============================================================================
# Build and lint the project
# =============================================================================
.EXPORT_ALL_VARIABLES:
# POSIX locale
LC_ALL = C
# ANSI formatting
BOLD = [1m
RESET = [0m
BIN_DIR = ./bin
# $(call print-target)
define print-target
@ printf "\e$(BOLD)make %s\e$(RESET)\n" "$$(echo $@ | sed 's,.stamp,,')"
endef
# Help
# =============================================================================
.DEFAULT_GOAL = help
define print-target-list
@ grep -E '^.PHONY:' $(MAKEFILE_LIST) | grep "#" | \
sed -E "s,[^:]+: ([a-z-]+) # (.*), \x1b$(BOLD)make \1\x1b$(RESET)#\2," | \
column -t -s '#'
endef
.PHONY: help # Print this help message and exit
help:
@ echo "Usage:"
@ echo
$(call print-target-list)
# Wrappers for mdBook
# =============================================================================
# build
# -----------------------------------------------------------------------------
.PHONY: build # Builds the book from its Markdown files
build:
$(call print-target)
mdbook build
# clean
# -----------------------------------------------------------------------------
.PHONY: clean # Deletes any temporary build files
clean:
$(call print-target)
mdbook clean
rm -f index.html
rm -rf .venv
# serve
# -----------------------------------------------------------------------------
# By default, `mdbook serve` resolves `localhost` to the IPv6 address `[::1]`,
# which VS Code doesn't understand.
#
# When we specify the IPv4 address `127.0.0.1`, VS Code recognizes the open
# port and allows the user to preview the book (in VS Code itself or in an
# external browser).
.PHONY: serve # Serves the book at http://localhost:3000/ with live reload
serve:
$(call print-target)
mdbook serve -n 127.0.0.1 -p 3000
# test
# -----------------------------------------------------------------------------
.PHONY: test # Tests that the book's Rust code samples compile
test:
$(call print-target)
mdbook test
# watch
# -----------------------------------------------------------------------------
.PHONY: watch # Watches the book's files and rebuilds it on changes
watch:
$(call print-target)
mdbook watch
# Linting
# =============================================================================
.PHONY: lint # Run a suite of lint checks
lint:
# ec
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# https://github.com/editorconfig-checker/editorconfig-checker
EC = ec
lint: ec
.PHONY: ec
ec:
$(call print-target)
$(EC)
# lintspaces
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LINTSPACES := $(BIN_DIR)/lintspaces.sh
lint: lintspaces
.PHONY: lintspaces
lintspaces:
$(call print-target)
$(LINTSPACES)
# prettier
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# https://github.com/prettier/prettier
PRETTIER = prettier --check --ignore-unknown .
lint: prettier
.PHONY: prettier
prettier:
$(call print-target)
$(PRETTIER)
# black
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# https://github.com/psf/black
BLACK = black --check .
lint: black
.PHONY: black
black:
$(call print-target)
$(BLACK)
# yamllint
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# https://github.com/adrienverge/yamllint
YAMLLINT = yamllint --config-file .yamllint.yaml .
lint: yamllint
.PHONY: yamllint
yamllint:
$(call print-target)
$(YAMLLINT)
# shellcheck
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SHELLCHECK := fdfind -H -t f '\.sh$$' --print0 | \
xargs -0 shellcheck
lint: shellcheck
.PHONY: shellcheck
shellcheck:
$(call print-target)
$(SHELLCHECK)
# shfmt
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# https://github.com/mvdan/sh#shfmt
SHFMT = shfmt -d -p -i 4 .
lint: shfmt
.PHONY: shfmt
shfmt:
$(call print-target)
$(SHFMT)
# markdownlint
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# https://github.com/markdownlint/markdownlint
MARKDOWNLINT = markdownlint .
lint: markdownlint
.PHONY: markdownlint
markdownlint:
$(call print-target)
$(MARKDOWNLINT)
# cspell
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# https://github.com/streetsidesoftware/cspell
CSPELL := fdfind -H -t f --print0 | xargs -0 \
cspell --no-progress --no-summary --config .cspell.json
lint: cspell
.PHONY: cspell
cspell:
$(call print-target)
$(CSPELL)
# misspell
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MISSPELL := $(BIN_DIR)/misspell.sh
lint: misspell
.PHONY: misspell
misspell:
$(call print-target)
$(MISSPELL)
# textlint
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# https://github.com/textlint/textlint
TEXTLINT := fdfind -H -t f '\.md$$' --print0 | xargs -0 \
xargs -0 textlint
lint: textlint
.PHONY: textlint
textlint:
$(call print-target)
$(TEXTLINT)
# vale
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# https://github.com/errata-ai/vale
VALE_STYLES_DIR = .vale/styles
GOOGLE_DIR = Google
GOOGLE_ZIP = $(GOOGLE_DIR)-0.3.3.zip
VALE := fdfind -H -t f '\.md$$' --print0 | xargs -0 \
vale \
--config .vale.ini \
--no-wrap
check: vale
.PHONY: vale
vale:
$(call print-target)
@ cd $(VALE_STYLES_DIR) && rm -rf $(GOOGLE_DIR)
@ cd $(VALE_STYLES_DIR) && unzip $(GOOGLE_ZIP) >/dev/null
$(VALE)
# markdown-link-check
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# https://github.com/tcort/markdown-link-check
MARKDOWN_LINK_CHECK = fdfind -H -t f '\.md$$' --print0 | xargs -0 \
markdown-link-check \
--config .markdown-link-check.json \
--quiet \
--retry
lint: markdown-link-check
.PHONY: markdown-link-check
markdown-link-check:
$(call print-target)
$(MARKDOWN_LINK_CHECK)
# optipng
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OPTIPNG := $(BIN_DIR)/optipng.sh --dry-run
check: optipng
.PHONY: optipng
optipng:
$(call print-target)
$(OPTIPNG)