CABALFLAGS ?= --jobs --enable-optimization 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 BIG := 3000 MAKEPAGES := $(TMPDIR)/make-pages YAMLS != find -L $(DATADIR) -name $(INFONAME) TSCRIPTS != find script -name '*.ts' 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 = $(STYLES) $(STYLEPNGS) $(STYLESVGS) $(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: $(DATADIR)/index.yaml $(MAKEPAGES) echo "[index] "$@ mkdir -p $(dir $@) $(MAKEPAGES) $(MPFLAGS) index --root $(ROOT) $< --output $@ $(BUILDDIR)/%: % $(call copy,--link --force) $(BUILDDIR)/%: $(TMPDIR)/% $(call copy,--link) $(TMPDIR)/%.js: %.ts echo "[tsc] "$@ tsc --strict --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),>) $(TMPDIR)/%_big.webp: $(DATADIR)/%.webp $(call resize,$(BIG),$(BIG),>) $(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) 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 --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)" -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: