blog/Makefile

119 lines
2.9 KiB
Makefile
Raw Normal View History

2021-07-23 21:35:02 -04:00
HOST ?= rhiannon.website
REMOTE_USER ?= www-data
IDFILE ?= ~/.ssh/xyz
REMOTE_DIR ?= blog
TMPDIR ?= _tmp
BUILDDIR ?= _build
POSTSDIR ?= posts
TEMPLATEDIR ?= templates
2022-03-14 23:41:08 -04:00
STATICEXTS :=
2021-07-23 21:35:02 -04:00
POSTS != find $(POSTSDIR) -name '*.md'
STATICS != parallel find $(POSTSDIR) -name '\*.{}' ::: $(STATICEXTS)
OUTPUTPOSTS = \
$(patsubst $(POSTSDIR)/%.md,$(BUILDDIR)/%.html,$(POSTS)) \
$(patsubst $(POSTSDIR)/%,$(BUILDDIR)/%,$(STATICS)) \
2021-07-25 08:54:27 -04:00
$(BUILDDIR)/index.html
2021-07-23 21:35:02 -04:00
STYLE != find style -type f
OUTPUTSTYLE = $(patsubst %,$(BUILDDIR)/%,$(STYLE))
OUTPUT = $(OUTPUTPOSTS) $(OUTPUTSTYLE)
LANGFILTER = $(TMPDIR)/langfilter
LAANTAS_SCRIPT = $(TMPDIR)/laantas-script
ALL_TAGS = $(TMPDIR)/all-tags
POST_LISTS = $(TMPDIR)/post-lists
NICE_DATE = $(TMPDIR)/nice-date
EXECS = \
$(LANGFILTER) $(LAANTAS_SCRIPT) \
$(ALL_TAGS) $(POST_LISTS) $(NICE_DATE)
CABAL_FLAGS ?= -O -v0
2022-03-14 23:40:25 -04:00
SYNTAXDIR := syntax
SYNTAXFLAGS = \
$(patsubst %,--syntax-definition=%,$(shell find $(SYNTAXDIR) -name '*.xml'))
2021-07-23 21:35:02 -04:00
.PHONY: all
all: build
.PHONY: build
build: $(EXECS) $(OUTPUT)
POSTDEPS = $(TEMPLATEDIR)/* $(LANGFILTER) $(LAANTAS_SCRIPT)
$(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)
define pandoc
@echo "[pandoc] $<"
mkdir -p $(dir $@)
mkdir -p $(basename $@)
LAANTAS_SCRIPT="$(LAANTAS_SCRIPT)" \
DIRNAME="$(basename $@)" \
FILENAME="$@" \
pandoc -s --toc --template $(TEMPLATEDIR)/$(1).html -o $@ $< \
2022-03-14 23:41:20 -04:00
-f markdown+emoji \
2022-03-14 23:40:25 -04:00
$(SYNTAXFLAGS) \
2021-07-23 21:35:02 -04:00
--filter $(LANGFILTER) --filter $(NICE_DATE) --mathjax
endef
$(BUILDDIR)/%: $(POSTSDIR)/% ; $(copy)
$(BUILDDIR)/%: $(TMPDIR)/% ; $(copy)
$(BUILDDIR)/%: % ; $(copy)
define copy
@echo "[copy] $<"
mkdir -p $(dir $@)
cp $< $@
endef
BLOG_META_DEPS != find blog-meta -type f
$(LANGFILTER): lang/langfilter/* ; $(call cabal-exe)
$(LAANTAS_SCRIPT): lang/laantas-script/* ; $(call cabal-exe)
$(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:)
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: