.PHONY: all assets clean deploy help tree check-git-clean check-links
SRC := md
OUT := out
HEAD := tpl/head.html
FOOT := tpl/foot.html
CSS := tpl/style.css
MD2HTML ?= /usr/bin/cmark-gfm
CMARK_FLAGS := --to html --extension table --validate-utf8 --unsafe
PYTHON ?= python3
BUILDINFO := tools/buildinfo.py
BUILD_PAGE := tools/build_page.py
GEN_INDEX := tools/gen_index.py
INDEX_HTML := $(OUT)/Index.html
DEPLOY_HOST ?= arsien23i2@dreamhost:tailrecursion.com/~alan
MD_FILES := $(shell find $(SRC) -type f -name '*.md' | LC_ALL=C sort)
HTML := $(patsubst $(SRC)/%.md,$(OUT)/%.html,$(MD_FILES))
all: assets $(OUT)/style.css $(HTML) $(INDEX_HTML)
$(OUT)/style.css: $(CSS)
mkdir -p $(OUT)
cp $(CSS) $@
$(OUT):
mkdir -p $(OUT)
$(OUT)/%.html: $(SRC)/%.md $(HEAD) $(FOOT) tools/mdlink2html.py $(BUILD_PAGE) $(BUILDINFO) | $(OUT)
OUT_DIR="$(OUT)" MD2HTML="$(MD2HTML)" CMARK_FLAGS="$(CMARK_FLAGS)" \
$(PYTHON) $(BUILD_PAGE) "$@" "$<" "$(HEAD)" "$(FOOT)" tools/mdlink2html.py
assets:
mkdir -p $(OUT)
rsync -a --include='*/' --exclude='*.md' --exclude='*.MD' --prune-empty-dirs $(SRC)/ $(OUT)/
$(INDEX_HTML): $(HTML) $(GEN_INDEX) $(HEAD) $(FOOT) $(BUILDINFO) | $(OUT)
$(PYTHON) $(GEN_INDEX) $@ $(SRC)
deploy: check-git-clean assets all
@if [ -z "$(DEPLOY_HOST)" ]; then \
echo "DEPLOY_HOST is not set"; \
exit 1; \
fi
rsync -a --chmod=F644,D755 $(OUT)/ $(DEPLOY_HOST)
git push
tree:
printf 'Markdown sources: ' && find $(SRC) -type f -name '*.md' | wc -l
printf 'HTML outputs: ' && if [ -d $(OUT) ]; then find $(OUT) -type f -name '*.html' | wc -l; else echo 0; fi
clean:
rm -rf $(OUT)
help:
@echo 'Static site generator targets:'
@echo ' make assets - copy non-Markdown assets into $(OUT)/'
@echo ' make - build HTML pages (same as make all)'
@echo ' make deploy - rsync $(OUT)/ to $$DEPLOY_HOST'
@echo ' make tree - count source and generated files'
@echo ' make clean - remove $(OUT)/'
@echo ' (deploy refuses to run with a dirty git worktree)'
check-git-clean:
@if [ -n "$$(git status --porcelain)" ]; then \
echo 'Refusing to build: git worktree has uncommitted changes.'; \
git status --short; \
exit 1; \
fi
check-links:
@python3 tools/check_links.py