blog/Makefile

126 lines
3.1 KiB
Makefile

HOST ?= rhiannon.website
REMOTE_USER ?= www-data
IDFILE ?= ~/.ssh/xyz
REMOTE_DIR ?= blog
TMPDIR ?= _tmp
BUILDDIR ?= _build
POSTSDIR ?= posts
IMAGESDIR ?= images
TEMPLATEDIR ?= templates
STATICS != find $(IMAGESDIR) -type f
POSTS != find $(POSTSDIR) -name '*.md'
OUTPUTPOSTS = \
$(patsubst $(POSTSDIR)/%.md,$(BUILDDIR)/%.html,$(POSTS)) \
$(addprefix $(BUILDDIR)/,$(STATICS)) \
$(BUILDDIR)/index.html
STYLE != find style -type f
OUTPUTSTYLE = $(patsubst %,$(BUILDDIR)/%,$(STYLE))
OUTPUT = $(OUTPUTPOSTS) $(OUTPUTSTYLE)
ALL_TAGS = $(TMPDIR)/all-tags
POST_LISTS = $(TMPDIR)/post-lists
NICE_DATE = $(TMPDIR)/nice-date
SLUG_TAGS = $(TMPDIR)/slug-tags
EXECS = \
$(LAANTAS_SCRIPT) \
$(ALL_TAGS) $(POST_LISTS) $(NICE_DATE) $(SLUG_TAGS)
CABAL_FLAGS ?= -O
SYNTAXDIR := syntax
SYNTAXFILES != find $(SYNTAXDIR) -name *.xml
SYNTAXFLAGS = $(patsubst %,--syntax-definition=%,$(SYNTAXFILES))
.PHONY: all
all: build
.PHONY: build
build: $(EXECS) $(OUTPUT)
LANGFILTER != cabal list-bin langfilter
LAANTAS_SCRIPT != cabal list-bin laantas-script
POSTDEPS = \
$(TEMPLATEDIR)/* \
langfilter laantas-script \
$(SYNTAXFILES) acm.csl quox.bib
$(TMPDIR)/all-tags.md $(TMPDIR)/tags.mk &: $(POSTS) $(ALL_TAGS)
@echo "[all-tags]"
$(ALL_TAGS) $(POSTSDIR) $(TMPDIR)/all-tags.md $(TMPDIR)/tags.mk
build: $(BUILDDIR)/all-tags.html
include $(TMPDIR)/tags.mk
$(BUILDDIR)/%.html: $(POSTSDIR)/%.md $(POSTDEPS) ; $(call pandoc,post)
$(BUILDDIR)/%.html: $(TMPDIR)/%.md $(POSTDEPS) ; $(call pandoc,meta)
.PHONY: langfilter laantas-script
langfilter laantas-script: %: ; cabal build $@
define pandoc
@echo "[pandoc] $<"
mkdir -p $(dir $@)
mkdir -p $(basename $@)
LAANTAS_SCRIPT="$(LAANTAS_SCRIPT)" \
DIRNAME="$(basename $@)" \
FILENAME="$@" \
pandoc -s --toc --toc-depth=2 --template $(TEMPLATEDIR)/$(1).html -o $@ $< \
-f markdown+emoji \
$(SYNTAXFLAGS) \
--filter $(LANGFILTER) --filter $(NICE_DATE) --filter $(SLUG_TAGS) \
--mathjax --citeproc --csl=apa-eu.csl
endef
$(BUILDDIR)/%: $(POSTSDIR)/% ; $(call copy)
$(BUILDDIR)/%: $(TMPDIR)/% ; $(call copy)
$(BUILDDIR)/%: % ; $(call copy)
define copy
@echo "[copy] $<"
mkdir -p $(dir $@)
cp $< $@
endef
BLOG_META_DEPS != find blog-meta -type f
$(ALL_TAGS): $(BLOG_META_DEPS) ; $(call cabal-exe,blog-meta:)
$(POST_LISTS): $(BLOG_META_DEPS) ; $(call cabal-exe,blog-meta:)
$(NICE_DATE): $(BLOG_META_DEPS) ; $(call cabal-exe,blog-meta:)
$(SLUG_TAGS): $(BLOG_META_DEPS) ; $(call cabal-exe,blog-meta:)
define cabal-exe
@echo "[build] $(notdir $@)"
cabal build $(1)$(notdir $@) $(CABAL_FLAGS)
mkdir -p $(dir $@)
find dist-newstyle -name $(notdir $@) -type f -exec cp {} $(TMPDIR) \;
endef
upload: build
@echo "[upload]"
@rsync --recursive --partial --progress --copy-links \
--compress --human-readable --hard-links --size-only \
--delete --delete-after \
--rsh='ssh -l $(REMOTE_USER) -i $(IDFILE)' \
$(BUILDDIR)/ $(HOST):$(REMOTE_DIR)/
.PHONY: clean distclean
clean:
@echo "[clean]"
rm -rf $(BUILDDIR)
rm -rf $(TMPDIR)
distclean: clean
@echo "[distclean]"
cabal clean
.SILENT: