## HAT TRICK -*- tab-width: 8; -*-
# (C) 2022 C. Duckworth
UPLOAD_TARGET = hetzner:/var/www/acdw.casa/
SITE_TITLE = acdw.casa
INPUT = src
BUILD = build
LASTB = .last_build
HTAWK = ./ht.awk
HTSH = ./ht.sh
HTMK = ht.mk
HT = ${HTAWK} ${HTSH} ${HTMK}
T = .tmp
TMK = $T/mk
TPG = $T/ps
PTMPL = tmpl.page.htm
PTMPC = \
$$(title) \
$$(body)
PTMPR = \
$$hb: $$ht ; \
${HTAWK} < '$$ht' | \
env HTTMP='$T' HTENV='$T/\$$<.env' HTOUT='\$$@' HTBOD='\$$<.bod.txt' \
${HTSH} '${PTMPL}' > '\$$@'
ITMPL = tmpl.index.htm
ITMPC = \
${SITE_TITLE} \
\
$$(for p in "$T"/*.env; do \
. "$$p"; \
print "- $$(title)
"; \
done) \
ITMPR = \
index.html: ${ITMPL} $$(cat ${TPG}); \
env HTTMP='$T' HTOUT='\$$@' \
${HTSH} "${ITMPL}" < /dev/null > '\$$@'
TMPL = ${PTMPL} ${ITMPL}
BUILD_INPUTS = ${INPUT}/* ${TMPL} ${HT}
RSYNCEXCLUDE = \
"*.ht" \
"*.sh" \
"*.htm" \
"*.mk" \
"*.awk" \
"*.bod.txt" \
"tmp/"
RSYNCEXCLUDEFILE = ${BUILD}/.rsync-exclude
RSYNC = rsync -avz --exclude-from="${RSYNCEXCLUDEFILE}" --delete
####################
${BUILD}: ${BUILD_INPUTS}
@touch ${LASTB}
@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 "build: $$(cat ${TPG}) index.html" >> '$@'
@printf '%s\n' 'done'
$T: ; mkdir -p "$@"
${PTMPL}: ; printf '${PTMPC}' > '$@'
${ITMPL}: ; printf '${ITMPC}' > '$@'
.PHONY: clean clean-build nuke
clean: ; -rm -rf ${BUILD} ${HTMK} $T ${LASTB}
nuke: clean ; -rm ${TMPL}
${RSYNCEXCLUDEFILE}: ${BUILD}
printf '%s\n' ${RSYNCEXCLUDE} > '$@'
.PHONY: publish
publish: build ${RSYNCEXCLUDEFILE}
${RSYNC} ${BUILD}/* '${UPLOAD_TARGET}'