-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
482 lines (423 loc) · 17.1 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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# -*- makefile -*-
#
# NOTE: Server-Side Includes on HCOOP only works if the included page is *not*
# a script, but a plain HTML file.
#
###############################################################################
## ##
## Settings ##
## ##
###############################################################################
source_dir := site
publish_dir := publish
remote_dir := ssh.hcoop.net:Web/klingonska.org
ignore := %.bak %.db %~ .\#% %\# %.tmp
CSS_MINIFIER ?= $(if $(MINIFIER),$(MINIFIER),yui-compressor --type css)
JS_MINIFIER ?= $(if $(MINIFIER),$(MINIFIER),yui-compressor --type js)
check-command = $(if $(shell which $2),,\
$(error $1 command '$2' not found ('make help' for more info)))
###############################################################################
## ##
## Functions ##
## ##
###############################################################################
# Usage: $(call exclude-ignores,LIST...)
# Return list of the filenames in LIST which do not match any of the patterns
# in LIST. Matching is only made against the file name (excluding any path name
# part).
exclude-ignores = $(foreach file,$1,$(if \
$(filter-out $(ignore),$(notdir $(file))),$(file)))
# These files are not processed, but included as-is in the published site.
copied_targets = \
$(patsubst $(source_dir)/%,$(publish_dir)/%, \
$(call exclude-ignores,$(shell \
find "$(source_dir)" -not -path '*/.*' -type f '(' \
-name '*.cgi' -or \
-name '*.css' -or \
-name '*.gif' -or \
-name '*.html' -or \
-name '*.ico' -or \
-name '*.jpg' -or \
-name '*.js' -or \
-name '*.ly' -or \
-name '*.map' -or \
-name '*.midi' -or \
-name '*.min.js' -or \
-name '*.mp3' -or \
-name '*.mp4' -or \
-name '*.ntd' -or \
-name '*.ogg' -or \
-name '*.pdf' -or \
-name '*.png' -or \
-name '*.ps' -or \
-name '*.svg' -or \
-name '*.swf' -or \
-name '*.ttf' -or \
-name '*.txt' -or \
-name '*.woff' -or \
-name '*.woff2' -or \
-name '*.zdb' -or \
-name '*.zip' \
')' \
)))
# Each of these results in one published HTML file.
html_targets = \
$(patsubst $(source_dir)/%.txt,$(publish_dir)/%.html, \
$(call exclude-ignores,$(wildcard \
$(source_dir)/*.txt \
$(source_dir)/academic/*.txt \
$(source_dir)/akademien/*.txt \
$(source_dir)/akademien/photos/*.txt \
$(source_dir)/akademien/logo/*.txt \
$(source_dir)/canon/[a-z]*.txt \
$(source_dir)/dict/*.txt \
$(source_dir)/klo/*.txt \
$(source_dir)/piq/*.txt \
$(source_dir)/piqad/*.txt \
$(source_dir)/ref/*.txt \
$(source_dir)/songs/index.txt \
$(source_dir)/songs/america.txt \
$(source_dir)/songs/anthem/index.txt \
$(source_dir)/songs/tahjaj_wo/index.txt \
$(source_dir)/writing/examples/*.txt \
$(source_dir)/writing/play/*.txt \
)))
css_targets = \
$(patsubst $(source_dir)/%.scss,$(publish_dir)/%.css, \
$(wildcard $(source_dir)/includes/*.scss \
))
all_targets = $(copied_targets) $(css_targets) $(html_targets)
###############################################################################
## ##
## Targets ##
## ##
###############################################################################
# Erase outputted file if rule fails.
# (Needed to make Make rebuild a failed target when run again.)
.DELETE_ON_ERROR:
## site - build web site
.PHONY: site css html js
site: $(all_targets)
## html - build HTML files of web site
html: $(filter %.html,$(all_targets))
## css - build CSS files of web site
css: $(filter %.css,$(all_targets))
## js - build Javascript files of web site
js: $(filter %.js,$(all_targets))
## ls-compiled - list compiled files
## ls-copied - list files used as-is
.PHONY: ls-compiled ls-copied
ls-compiled:
@for LINE in $(css_targets) $(html_targets); do \
echo $$LINE; \
done | if [ -t 1 ]; then column; else cat; fi
ls-copied:
@for LINE in $(copied_targets); do \
echo $$LINE; \
done | if [ -t 1 ]; then column; else cat; fi
## auto - autorun 'make site' when files change
.PHONY: auto
auto: site
@echo "================================================================="; \
echo "Auto Build Mode."; \
echo "Watching '$(source_dir)/' and rebuilding files as they change."; \
echo "Press ^C to stop."; \
if which notify-send >/dev/null && \
[ -n $$DISPLAY ]; then \
out() { \
echo "$$1 $$2"; \
notify-send -t 1000 \
--hint int:transient:1 \
"$$1" "$$2"; \
}; \
else \
out() { echo "$$1 $$2"; }; \
fi; \
inotifywait \
--event=CLOSE_WRITE \
--exclude='(/\.|[#~]$$)' \
--monitor \
--quiet \
--recursive $(source_dir) \
| while read FILE; do \
FILE="$${FILE%% *}$${FILE##* }"; \
echo "File '$$FILE' changed"; \
RESULT="Failed to process"; \
make --no-print-directory \
| sed 's/^/ /' \
&& RESULT="Processed"; \
out "$$RESULT" $$FILE; \
done
## publish - rsync generated web site to web host
.PHONY: publish
publish: .publish.done
.publish.done: $(all_targets)
@NONMINIFIED=""; \
if [ "$(CSS_MINIFIER)" = cat ]; then \
NONMINIFIED="CSS"; \
fi; \
if [ "$(JS_MINIFIER)" = cat ]; then \
NONMINIFIED="$${NONMINIFIED+CSS and }Javascript"; \
fi; \
if [ -n "$$NONMINIFIED" ]; then \
echo "ERROR: $$NONMINIFIED is not minified," \
"won't publish site without minification" >&2; \
exit 1; \
fi; \
bin/check-dict <site/dict/dict.zdb --checksum || { \
echo " in 'site/dict/dict.zdb'" >&2; \
exit 1; \
}; \
echo "Publishing site to '$(remote_dir)':"; \
FILES=$$(find ./$(publish_dir) -perm -g=w); \
[ -n "$$FILES" ] && chmod g-w $$FILES; \
rsync -Pac --exclude-from=.gitignore --delete-excluded \
--delete-after $(publish_dir)/ $(remote_dir) \
&& echo "Last published from here: `date`" >"$@"
## fetch - fetch published site
.PHONY: fetch
fetch:
@if [ ! -e fetched ]; then \
[ -e $(publish_dir) ] || make site; \
cp -a publish fetched; \
fi; \
echo "Fetching published site to 'fetched':"; \
rsync -Pac --delete-after $(remote_dir)/ fetched/
## linkcheck - check internal web page links
.PHONY: linkcheck
linkcheck: $(all_targets)
@echo "Checking <a href=\"...\"> links in all HTML files:"
@bin/linkcheck `find "$(publish_dir)" -type f '(' -iname "*.html" '!' -iname ".*" ')'`
## clean - remove all generated files
.PHONY: clean
clean:
@if [ -e $(publish_dir) ]; then \
printf "Erasing files ........ "; \
rm -f $(all_targets); \
echo "OK"; \
DIRS=`find publish -type d -empty`; \
if [ -n "$$DIRS" ]; then \
printf "Erasing directories .. "; \
rmdir --ignore-fail-on-non-empty -p $$DIRS; \
echo "OK"; \
fi; \
fi
## help - display this information
.PHONY: help
help:
@echo "Available targets:"; \
cat "$(CURDIR)/Makefile" | \
awk '/^## [^ ]/{sub(/^## */," ");print}' | \
sort; \
echo; \
echo "Options:"; \
echo " MINIFIER=<COMMAND> (default: n/a)"; \
echo " CSS_MINIFIER=<COMMAND> (default: '$(CSS_MINIFIER)')"; \
echo " JS_MINIFIER=<COMMAND> (default: '$(JS_MINIFIER)')"; \
echo; \
echo 'To disable minifying altogether use `make MINIFIER=cat` (this'; \
echo 'sets both the CSS_MINIFIER and JS_MINIFIER commands to `cat`).'
# CGI (server-side script)
$(publish_dir)/%.cgi: $(source_dir)/%.cgi
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# SCSS (sassy stylesheet) -> minified CSS
$(publish_dir)/%.css: $(source_dir)/%.scss bin/sassy
@$(call check-command,CSS_MINIFIER,$(firstword $(CSS_MINIFIER)))\
[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Processing '$<' -> '$@'"; \
bin/sassy $(filter %.scss,$^) | \
$(CSS_MINIFIER) >"$@"
# CSS (stylesheet) -> minified CSS
$(publish_dir)/%.css: $(source_dir)/%.css
@$(call check-command,CSS_MINIFIER,$(firstword $(CSS_MINIFIER)))\
[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Minifying '$<' -> '$@'"; \
$(CSS_MINIFIER) <"$<" >"$@"
# GIF (bitmap image)
$(publish_dir)/%.gif: $(source_dir)/%.gif
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# HTML (hypertext)
$(publish_dir)/%.html: $(source_dir)/%.html
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# KA Markdown -> HTML
$(publish_dir)/dict/%.html: $(source_dir)/dict/%.txt bin/parse \
parse-data/parser-markdown-ka parse-data/composer-html-ka2 \
parse-data/transformer-html-ka2 perl/ParserComposer.pm
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "HTMLifying '$<' -> '$@'"; \
bin/parse \
--input=./parse-data/parser-markdown-ka \
--apply=./parse-data/transformer-html-ka2 \
--output=./parse-data/composer-html-ka2 \
<"$<" >"$@"; \
[ -s "$@" ] || rm "$@"
# KA Markdown -> HTML
$(publish_dir)/klo/%.html: $(source_dir)/klo/%.txt \
$(source_dir)/klo/includes/template.html \
bin/markdown2html-old
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
rm -f "$@"; \
bin/markdown2html-old \
--base="$(source_dir)" \
--output="$@" \
"$<"
# KA Markdown -> HTML
$(publish_dir)/%.html: $(source_dir)/%.txt \
$(source_dir)/includes/template.html \
bin/markdown2html
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
rm -f "$@"; \
bin/markdown2html \
--base="$(source_dir)" \
--output="$@" \
--template="includes/template.html" \
"$<"
# ICO (browser favicon)
$(publish_dir)/favicon.ico: $(source_dir)/favicon.ico
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# JPEG (bitmap image)
$(publish_dir)/%.jpg: $(source_dir)/%.jpg
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# JS (client-side script, Javascript)
# (Script appears to use MSIE hacks and gets mangled in minification.)
$(publish_dir)/includes/sorttable.js: $(source_dir)/includes/sorttable.js
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# JS (client-side script, Javascript)
$(publish_dir)/%.js: $(source_dir)/%.js
@$(call check-command,JS_MINIFIER,$(firstword $(JS_MINIFIER)))\
[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Minifying '$<' -> '$@'"; \
$(JS_MINIFIER) <"$<" >"$@"
# LY (typeset musical score, LilyPond)
$(publish_dir)/%.ly: $(source_dir)/%.ly
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# MIDI (audio)
$(publish_dir)/%.midi: $(source_dir)/%.midi
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# MP3 (audio)
$(publish_dir)/%.mp3: $(source_dir)/%.mp3
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# MP4 (video)
$(publish_dir)/%.mp4: $(source_dir)/%.mp4
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# MAP (source map file)
$(publish_dir)/%.map: $(source_dir)/%.map
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# MIN JS (client-side script, pre-minified Javascript)
$(publish_dir)/%.min.js: $(source_dir)/%.min.js
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# NTD (typeset musical score, NoteEdit)
$(publish_dir)/%.ntd: $(source_dir)/%.ntd
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# OGG (audio)
$(publish_dir)/%.ogg: $(source_dir)/%.ogg
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# PDF (typeset document, PDF)
$(publish_dir)/%.pdf: $(source_dir)/%.pdf
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# PNG (bitmap image)
$(publish_dir)/%.png: $(source_dir)/%.png
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# PS (typeset document, Postscript)
$(publish_dir)/%.ps: $(source_dir)/%.ps
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# SVG (vector image)
$(publish_dir)/%.svg: $(source_dir)/%.svg
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# SWF (client-side program, Shockwave Flash)
$(publish_dir)/%.swf: $(source_dir)/%.swf
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# TTF (TrueType Font)
$(publish_dir)/%.ttf: $(source_dir)/%.ttf
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# TXT (text file)
$(publish_dir)/%-tkd.txt: $(source_dir)/%-tkd.txt
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Processing \`$<' -> \`$@'"; \
tr 'A-Za-z' 'N-ZA-Mn-za-m' <"$<" >"$@"
# TXT (text files)
$(publish_dir)/%-ck.txt: $(source_dir)/%-ck.txt
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Processing \`$<' -> \`$@'"; \
tr 'A-Za-z' 'N-ZA-Mn-za-m' <"$<" >"$@"
# TXT (text files)
$(publish_dir)/%-pk.txt: $(source_dir)/%-pk.txt
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Processing \`$<' -> \`$@'"; \
tr 'A-Za-z' 'N-ZA-Mn-za-m' <"$<" >"$@"
# TXT (text files)
$(publish_dir)/%-tkw.txt: $(source_dir)/%-tkw.txt
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Processing \`$<' -> \`$@'"; \
tr 'A-Za-z' 'N-ZA-Mn-za-m' <"$<" >"$@"
# TXT (text files)
$(publish_dir)/%-kgt.txt: $(source_dir)/%-kgt.txt
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Processing \`$<' -> \`$@'"; \
tr 'A-Za-z' 'N-ZA-Mn-za-m' <"$<" >"$@"
# TXT (text files)
$(publish_dir)/%.txt: $(source_dir)/%.txt
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# WOFF (Web Open Font Format)
$(publish_dir)/%.woff: $(source_dir)/%.woff
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# WOFF2 (Web Open Font Format, Version 2)
$(publish_dir)/%.woff2: $(source_dir)/%.woff2
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# ZDB (text database)
$(publish_dir)/%.zdb: $(source_dir)/%.zdb
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
# ZIP (compressed archive)
$(publish_dir)/%.zip: $(source_dir)/%.zip
@[ -e "$(@D)" ] || mkdir -p "$(@D)"; \
echo "Copying '$<' -> '$@'"; \
cp "$<" "$@"
#[eof]