gallery/Makefile
2021-04-16 23:48:55 +02:00

181 lines
3.7 KiB
Makefile

DATADIR := data
TMPDIR := _tmp
BUILDDIR := _build
INFONAME := info.yaml
ROOT := https://gallery.niss.website
# SMALL = thumbnails, MED = single pages (link to full size)
SMALL := 200
MEDW := 1000
MEDH := 1200
MAKEPAGES := $(TMPDIR)/make-pages
YAMLS != find $(DATADIR) -name $(INFONAME)
SCRIPTS != find script -name '*.js'
STYLES != find style -name '*.css'
STYLESVGS != find style -name '*.svg'
STYLEPNGS != find style -name '*.png'
FONTS != find fonts \
-iname '*.eot' -or -iname '*.svg' -or \
-iname '*.ttf' -or -iname '*.woff' -or \
-iname '*.woff2' -or -iname '*.css'
STATIC = $(SCRIPTS) $(STYLES) $(STYLEPNGS) $(STYLESVGS) $(FONTS)
BSTATIC = $(patsubst %,$(BUILDDIR)/%,$(STATIC))
.PHONY: all build
all: build
build: $(BUILDDIR)/index.html $(BSTATIC)
$(BUILDDIR)/index.html: $(DATADIR)/index.yaml $(MAKEPAGES)
echo "[index] "$@
mkdir -p $(dir $@)
$(MAKEPAGES) $(MPFLAGS) index $< -o $@
$(BUILDDIR)/%: %
$(call copy)
$(BUILDDIR)/%: $(TMPDIR)/%
$(call copy,-l)
$(TMPDIR)/%_small.png: $(DATADIR)/%.png
$(call resize,$(SMALL),$(SMALL),^,-gravity center -crop 1:1+0)
$(TMPDIR)/%_med.png: $(DATADIR)/%.png
$(call resize,$(MEDW),$(MEDH),>)
$(MAKEPAGES): make-pages/*.hs make-pages/make-pages.cabal
echo "[make-pages]"
mkdir -p $(dir $@)
cabal v2-build all -O0 -v0 -j
find dist-newstyle -name make-pages -executable -type f \
-exec cp {} $@ \;
$(TMPDIR)/index.mk: $(DATADIR)/index.yaml $(YAMLS) $(MAKEPAGES)
$(call depend-gallery)
ifneq ($(MAKECMDGOALS),mostlyclean)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),distclean)
ifneq ($(MAKECMDGOALS),list-tags)
-include $(TMPDIR)/index.mk
endif
endif
endif
endif
.PHONY: mostlyclean clean distclean
mostlyclean:
echo "[clean $(BUILDDIR)]"
rm -rf $(BUILDDIR)
clean: mostlyclean
echo "[clean $(TMPDIR)]"
rm -rf $(TMPDIR)
distclean: clean
echo "[cabal clean]"
cabal -v0 v2-clean
.PHONY: list-tags
list-tags: $(MAKEPAGES)
$(MAKEPAGES) list-tags -Un
HOST ?= gallery.niss.website
REMOTE_USER ?= www-data
IDFILE ?= ~/.ssh/xyz
REMOTE_DIR ?= gallery
.PHONY: upload
upload: build
@rsync -rPLzhH --delete -e 'ssh -l $(REMOTE_USER) -i $(IDFILE)' \
$(BUILDDIR)/ $(HOST):$(REMOTE_DIR)/
# one arg for extra flags
define copy
echo "[copy] "$@
mkdir -p "$(dir $@)"
cp $(1) -L "$^" "$@"
endef
# args:
# 1. width
# 2. height
# 3. imagemagick resize hint (^, <, !, etc)
# 4. other flags (e.g. cropping)
define resize
echo "[resize] "$@
mkdir -p "$(dir $@)"
convert -resize "$(1)x$(2)$(3)" $(4) "$^" "$@"
endef
# no args
define depend-gallery
echo "[deps] "$@
mkdir -p $(dir $@)
$(MAKEPAGES) $(MPFLAGS) depend-gallery $< -o "$@" \
-B "$(BUILDDIR)" -D "$(DATADIR)" -T "$(TMPDIR)" -I "$(INFONAME)"
endef
# args:
# 1. gallery prefix
# 2. build dir
# 3. data dir
# 4. other flags
define depend-single
echo "[deps] "$@
mkdir -p "$(dir $@)"
$(MAKEPAGES) $(MPFLAGS) depend-single \
$(4) -o "$@" -p "$(1)" -B "$(2)" -D "$(3)" $<
endef
# args
# 1. title
# 2. gallery prefix
# 3. other flags
define gallery
echo "[gallery] "$@
mkdir -p "$(dir $@)"
$(MAKEPAGES) $(MPFLAGS) gallery -t "$(1)" -p "$(2)" $(3) -o "$@" \
$(filter $(DATADIR)/%/$(INFONAME),$^)
endef
# args:
# 1. data dir
# 2. other flags
define single
echo "[single] "$@
mkdir -p "$(dir $@)"
$(MAKEPAGES) $(MPFLAGS) single -D "$(1)" $< -o "$@" $(2)
endef
# args:
# 1. title with commas replaced with $(comma)
# 2. description with commas replaced
# 3. gallery prefix
# 4. data dir
# 5. other flags
define rss
echo "[rss] "$@
mkdir -p "$(dir $@)"
$(MAKEPAGES) $(MPFLAGS) rss -t "$(1)" -d "$(2)" \
-R "$(ROOT)" -p "$(3)" -D "$(4)" -o "$@" $(5) \
$(filter $(DATADIR)/%/$(INFONAME),$^)
endef
comma := ,
# never delete intermediate files
.SECONDARY:
.SILENT: