CABALFLAGS ?= --jobs --enable-optimization DATADIR := data TMPDIR := _tmp BUILDDIR := _build INFONAME := info.yaml ROOT := https://gallery.niss.website INDEX := $(DATADIR)/index.yaml # SMALL = thumbnails, MED = single pages (link to full size) SMALL := 200 MEDW := 1000 MEDH := 1200 BIG := 3000 MAKEPAGES := $(TMPDIR)/make-pages YAMLS != find -L $(DATADIR) -name $(INFONAME) TSCRIPTS != find script -name '*.ts' STYLES != find style -type f FONTS != find fonts -type f STATIC = $(STYLES) $(FONTS) BSTATIC = $(patsubst %,$(BUILDDIR)/%,$(STATIC)) BSCRIPTS = $(patsubst %.ts,$(BUILDDIR)/%.js,$(TSCRIPTS)) .PHONY: all build all: build build: $(BUILDDIR)/index.html $(BSTATIC) $(BSCRIPTS) $(BUILDDIR)/index.html: $(INDEX) $(MAKEPAGES) echo "[index] "$@ mkdir -p $(dir $@) $(MAKEPAGES) $(MPFLAGS) index --root $(ROOT) $< --output $@ $(BUILDDIR)/%: % $(call copy,--link --force) $(BUILDDIR)/%: $(TMPDIR)/% $(call copy,--link --force) $(TMPDIR)/%.js: %.ts echo "[tsc] "$@ tsc --strict --noUncheckedIndexedAccess --noEmitOnError \ --lib dom,es2021 --target es2015 \ --outDir $(dir $@) $^ $(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)/%_big.png: $(DATADIR)/%.png $(call resize,$(BIG),$(BIG),>) $(TMPDIR)/%_small.jpg: $(DATADIR)/%.jpg $(call resize,$(SMALL),$(SMALL),^,-gravity center -crop 1:1+0) $(TMPDIR)/%_med.jpg: $(DATADIR)/%.jpg $(call resize,$(MEDW),$(MEDH),>) $(TMPDIR)/%_big.jpg: $(DATADIR)/%.jpg $(call resize,$(BIG),$(BIG),>) $(TMPDIR)/%_small.webp: $(DATADIR)/%.webp $(call resize,$(SMALL),$(SMALL),^,-gravity center -crop 1:1+0) $(TMPDIR)/%_med.webp: $(DATADIR)/%.webp $(call resize,$(MEDW),$(MEDH),>,-quality 90) $(TMPDIR)/%_big.webp: $(DATADIR)/%.webp $(call copy) $(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: $(INDEX) $(YAMLS) $(MAKEPAGES) $(call depend-gallery) NODEPS := mostlyclean clean distclean list-tags GOALS := $(if $(strip $(MAKECMDGOALS)),$(strip $(MAKECMDGOALS)),all) ifneq ($(filter-out $(NODEPS),$(GOALS)),) include $(TMPDIR)/index.mk endif .PHONY: clean mostlyclean distclean mostlyclean: echo "[clean $(BUILDDIR)]" rm -rf $(BUILDDIR) clean: mostlyclean echo "[clean $(TMPDIR)]" rm -rf $(TMPDIR) distclean: clean echo "[cabal clean]" cabal --verbose=0 v2-clean .PHONY: list-tags list-tags: $(MAKEPAGES) $(MAKEPAGES) list-tags --untagged --warnings --nsfw --index $(INDEX) 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)" -define webp:lossless=true $(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. index filename # 3. build dir # 4. data dir # 5. other flags define depend-single echo "[deps] "$@ mkdir -p "$(dir $@)" $(MAKEPAGES) $(MPFLAGS) depend-single $(5) \ --output "$@" \ --prefix "$(1)" \ --index "$(2)" \ --build-dir "$(3)" \ --data-dir "$(4)" $< 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. index file # 4. other flags define single echo "[single] "$@ mkdir -p "$(dir $@)" $(MAKEPAGES) $(MPFLAGS) single $(4) \ --root $(ROOT) \ --data-dir "$(1)" \ --prefix "$(2)" \ --index "$(3)" \ --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: