gallery/Makefile

210 lines
4.2 KiB
Makefile

CABALFLAGS ?= --verbose=0 --jobs
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 --root $(ROOT) $< --output $@
$(BUILDDIR)/%: %
$(call copy)
$(BUILDDIR)/%: $(TMPDIR)/%
$(call copy,--link)
$(TMPDIR)/%_small.png: $(DATADIR)/%.png
$(call resize,$(SMALL),$(SMALL),^,-gravity center -crop 1:1+0)
$(TMPDIR)/%_med.png: $(DATADIR)/%.png
$(call resize,$(MEDW),$(MEDH),>)
$(TMPDIR)/%_small.jpg: $(DATADIR)/%.jpg
$(call resize,$(SMALL),$(SMALL),^,-gravity center -crop 1:1+0)
$(TMPDIR)/%_med.jpg: $(DATADIR)/%.jpg
$(call resize,$(MEDW),$(MEDH),>)
$(MAKEPAGES): make-pages/*.hs make-pages/make-pages.cabal
echo "[make-pages]"
mkdir -p $(dir $@)
cabal v2-build all $(CABALFLAGS)
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: clean distclean
clean:
echo "[clean $(BUILDDIR)]"
rm -rf $(BUILDDIR)
distclean: clean
echo "[clean $(TMPDIR)]"
rm -rf $(TMPDIR)
echo "[cabal clean]"
cabal --verbose=0 v2-clean
.PHONY: list-tags
list-tags: $(MAKEPAGES)
$(MAKEPAGES) list-tags --untagged --nsfw
HOST ?= gallery.niss.website
REMOTE_USER ?= www-data
IDFILE ?= ~/.ssh/xyz
REMOTE_DIR ?= gallery
.PHONY: upload
upload: build
@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)/
# one arg for extra flags
define copy
echo "[copy] "$@
mkdir -p "$(dir $@)"
cp $(1) --dereference "$^" "$@"
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 $< \
--output "$@" \
--build-dir "$(BUILDDIR)" \
--data-dir "$(DATADIR)" \
--tmp-dir "$(TMPDIR)" \
--info "$(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) \
--output "$@" \
--prefix "$(1)" \
--build-dir "$(2)" \
--data-dir "$(3)" $<
endef
# args
# 1. index file
# 2. gallery prefix
# 3. other flags
define gallery
echo "[gallery] "$@
mkdir -p "$(dir $@)"
$(MAKEPAGES) $(MPFLAGS) gallery $(3) \
--index "$(1)" \
--root "$(ROOT)" \
--prefix "$(2)" \
--output "$@" \
$(filter $(DATADIR)/%/$(INFONAME),$^)
endef
# args:
# 1. data dir
# 2. gallery prefix
# 3. other flags
define single
echo "[single] "$@
mkdir -p "$(dir $@)"
$(MAKEPAGES) $(MPFLAGS) single $(3) \
--root $(ROOT) \
--data-dir "$(1)" \
--prefix "$(2)" \
--output "$@" \
$<
endef
# args:
# 1. index file
# 2. gallery prefix
# 3. data dir
# 4. other flags
define rss
echo "[rss] "$@
mkdir -p "$(dir $@)"
$(MAKEPAGES) $(MPFLAGS) rss $(4) \
--index "$(1)" \
--root "$(ROOT)" \
--prefix "$(2)" \
--data-dir "$(3)" \
--output "$@" \
$(filter $(DATADIR)/%/$(INFONAME),$^)
endef
# never delete intermediate files
.SECONDARY:
.SILENT: