about summary refs log tree commit diff stats
path: root/Makefile
blob: 537fabe03d32ed5f983e72101a2fb7e0938a8ec7 (plain)
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
## HAT TRICK -*- tab-width: 8; -*-
# (C) 2022 C. Duckworth

UPLOAD_TARGET = hetzner:/var/www/acdw.casa/

SITE_TITLE = acdw.casa

INPUT = src
BUILD = build

HTAWK = ./ht.awk
HTSH  = ./ht.sh
HTMK  = ht.mk
HT    = ${HTAWK} ${HTSH} ${HTMK}

INCLUDES = _head.htm _foot.htm

T   = .tmp
TMK = $T/mk
TPG = $T/ps

PTMPL = tmpl.page.htm
PTMPC = \
	<title>$$(title)</title> \
	$$(body)
PTMPR = \
	$$hb: $$ht ${INCLUDES} ; \
		${HTAWK} < '$$ht' | \
	env HTTMP='$T' HTENV='$T/\$$<.env' HTOUT='\$$@' HTBOD='\$$<.bod.txt' \
	${HTSH} '${PTMPL}' > '\$$@'

ITMPL = tmpl.index.htm
ITMPC = \
	<title>${SITE_TITLE}</title> \
	<ul id="idx"> \
	$$(for p in "$T"/*.env; do \
		. "$$p"; \
		print "<li><a href=\"$$HTOUT\">$$(title)</a></li>"; \
	done) \
	</ul>
ITMPR = \
	index.html: ${ITMPL} $$(cat ${TPG}); \
	env HTTMP='$T' HTOUT='\$$@' \
	${HTSH} "${ITMPL}" < /dev/null > '\$$@'

RTMPL = tmpl.feed.xml
RTMPR = \
	feed.xml: ${RTMPL} index.html $$(cat ${TPG}); \
	env HTTMP='$T' HTOUT='\$$@' \
	${HTSH} "${RTMPL}" < /dev/null > '\$$@'

TMPL = ${PTMPL} ${ITMPL} ${RTMPL}
BUILD_INPUTS = ${INPUT}/* ${TMPL} ${HT}

RSYNCEXCLUDE = \
	"*.ht" \
	"*.sh" \
	"*.htm" \
	"*.mk" \
	"*.awk" \
	"*.bod.txt" \
	"tmpl.*" \
	"tmp/"
RSYNCEXCLUDEFILE = ${BUILD}/.rsync-exclude
RSYNC = rsync -auvz --exclude-from="${RSYNCEXCLUDEFILE}" --delete

####################

${BUILD}: ${BUILD_INPUTS}
	@mkdir -p ${BUILD}
	cp -a ${BUILD_INPUTS} $@
	${MAKE} -C $@ -f ${HTMK} build

${HTMK}: Makefile ${INPUT}/*.ht $T
	@printf '%s' 'Generating "$@"...'
	@: > '$@'
	@: > '${TPG}'

	@for ht in $$(find ${INPUT} -type f -name '*.ht'); do \
		ht="$$(echo "$$ht" | sed 's#${INPUT}/##')"; \
		hb="$${ht}ml"; \
		printf '%s ' "$$hb" >> "${TPG}"; \
		printf '%s\n' "${PTMPR}"; \
	done >> '$@'

	@printf '%s\n' "${ITMPR}" >> '$@'
	@printf '%s\n' "${RTMPR}" >> '$@'
	@printf "build: $$(cat ${TPG}) index.html feed.xml" >> '$@'
	@printf '%s\n' 'done'

$T: ; mkdir -p "$@"
${PTMPL}: ; printf '${PTMPC}' > '$@'
${ITMPL}: ; printf '${ITMPC}' > '$@'

.PHONY: clean clean-build nuke
clean: ; -rm -rf ${BUILD} ${HTMK} $T
nuke: clean ; -rm ${TMPL}

${RSYNCEXCLUDEFILE}: ${BUILD}
	printf '%s\n' ${RSYNCEXCLUDE} > '$@'

.PHONY: publish
publish: build ${RSYNCEXCLUDEFILE}
	${RSYNC} ${BUILD}/* '${UPLOAD_TARGET}'