gallery/Makefile

232 lines
4.8 KiB
Makefile
Raw Permalink Normal View History

2021-05-05 07:45:22 -04:00
CABALFLAGS ?= --jobs --enable-optimization
2021-03-07 14:49:25 -05:00
2020-07-19 12:05:01 -04:00
DATADIR := data
TMPDIR := _tmp
BUILDDIR := _build
INFONAME := info.yaml
ROOT := https://gallery.niss.website
2020-07-14 01:10:33 -04:00
# SMALL = thumbnails, MED = single pages (link to full size)
SMALL := 200
2020-07-18 18:11:42 -04:00
MEDW := 1000
MEDH := 1200
2022-08-16 19:22:27 -04:00
BIG := 3000
2020-07-14 01:10:33 -04:00
2020-07-19 12:05:01 -04:00
MAKEPAGES := $(TMPDIR)/make-pages
2020-07-14 01:10:33 -04:00
2021-05-24 06:58:28 -04:00
YAMLS != find -L $(DATADIR) -name $(INFONAME)
2020-07-15 05:58:44 -04:00
2020-07-31 23:09:23 -04:00
SCRIPTS != find script -name '*.js'
2020-07-19 16:36:15 -04:00
STYLES != find style -name '*.css'
STYLESVGS != find style -name '*.svg'
STYLEPNGS != find style -name '*.png'
2020-07-18 05:44:30 -04:00
2020-07-31 23:09:23 -04:00
FONTS != find fonts \
2020-07-17 06:29:13 -04:00
-iname '*.eot' -or -iname '*.svg' -or \
-iname '*.ttf' -or -iname '*.woff' -or \
2020-07-31 23:09:23 -04:00
-iname '*.woff2' -or -iname '*.css'
2020-07-18 05:44:30 -04:00
2020-07-31 23:09:23 -04:00
STATIC = $(SCRIPTS) $(STYLES) $(STYLEPNGS) $(STYLESVGS) $(FONTS)
BSTATIC = $(patsubst %,$(BUILDDIR)/%,$(STATIC))
2020-07-17 06:29:13 -04:00
2020-07-18 05:58:41 -04:00
.PHONY: all build
all: build
build: $(BUILDDIR)/index.html $(BSTATIC)
2020-07-17 06:29:13 -04:00
2020-07-19 06:08:44 -04:00
$(BUILDDIR)/index.html: $(DATADIR)/index.yaml $(MAKEPAGES)
2020-07-18 05:58:41 -04:00
echo "[index] "$@
2020-07-17 06:29:13 -04:00
mkdir -p $(dir $@)
2021-03-07 14:49:25 -05:00
$(MAKEPAGES) $(MPFLAGS) index --root $(ROOT) $< --output $@
2020-07-15 05:58:44 -04:00
2020-07-18 05:44:30 -04:00
2020-07-18 05:58:41 -04:00
$(BUILDDIR)/%: %
2022-12-29 21:18:12 -05:00
$(call copy,--link --force)
2020-07-18 05:58:41 -04:00
$(BUILDDIR)/%: $(TMPDIR)/%
2021-03-07 14:49:25 -05:00
$(call copy,--link)
2020-07-18 05:58:41 -04:00
2020-07-15 14:09:40 -04:00
2020-07-24 09:20:10 -04:00
$(TMPDIR)/%_small.png: $(DATADIR)/%.png
$(call resize,$(SMALL),$(SMALL),^,-gravity center -crop 1:1+0)
$(TMPDIR)/%_med.png: $(DATADIR)/%.png
$(call resize,$(MEDW),$(MEDH),>)
2022-05-16 04:25:16 -04:00
$(TMPDIR)/%_big.png: $(DATADIR)/%.png
$(call resize,$(BIG),$(BIG),>)
2020-07-24 09:20:10 -04:00
2020-09-13 16:11:21 -04:00
$(TMPDIR)/%_small.jpg: $(DATADIR)/%.jpg
$(call resize,$(SMALL),$(SMALL),^,-gravity center -crop 1:1+0)
$(TMPDIR)/%_med.jpg: $(DATADIR)/%.jpg
$(call resize,$(MEDW),$(MEDH),>)
2022-05-16 04:25:16 -04:00
$(TMPDIR)/%_big.jpg: $(DATADIR)/%.jpg
$(call resize,$(BIG),$(BIG),>)
2020-09-13 16:11:21 -04:00
2023-01-15 15:39:03 -05:00
%.jxl: %.png ; $(call cjxl,-e 9)
%.jxl: %.jpg ; $(call cjxl,-e 9)
%.jxl: %.gif ; $(call cjxl)
2020-07-17 06:29:13 -04:00
$(MAKEPAGES): make-pages/*.hs make-pages/make-pages.cabal
2020-07-16 10:07:28 -04:00
echo "[make-pages]"
mkdir -p $(dir $@)
2021-03-07 14:49:25 -05:00
cabal v2-build all $(CABALFLAGS)
2020-07-16 10:07:28 -04:00
find dist-newstyle -name make-pages -executable -type f \
-exec cp {} $@ \;
2020-07-14 01:10:33 -04:00
2020-07-18 05:58:41 -04:00
2020-07-21 19:48:08 -04:00
$(TMPDIR)/index.mk: $(DATADIR)/index.yaml $(YAMLS) $(MAKEPAGES)
2020-07-24 09:20:10 -04:00
$(call depend-gallery)
2020-07-15 14:09:40 -04:00
2021-03-20 06:07:23 -04:00
NODEPS := mostlyclean clean distclean list-tags
2021-03-20 12:47:02 -04:00
GOALS := $(if $(strip $(MAKECMDGOALS)),$(strip $(MAKECMDGOALS)),all)
ifneq ($(filter-out $(NODEPS),$(GOALS)),)
2021-05-24 06:58:28 -04:00
include $(TMPDIR)/index.mk
2020-07-21 05:27:31 -04:00
endif
2020-07-15 05:58:58 -04:00
2020-07-18 05:58:41 -04:00
2022-01-04 14:09:09 -05:00
.PHONY: clean mostlyclean distclean
mostlyclean:
2020-08-01 09:54:39 -04:00
echo "[clean $(BUILDDIR)]"
rm -rf $(BUILDDIR)
2022-01-04 14:09:09 -05:00
clean: mostlyclean
2020-08-01 09:54:39 -04:00
echo "[clean $(TMPDIR)]"
rm -rf $(TMPDIR)
2022-01-04 14:09:09 -05:00
distclean: clean
2020-08-01 09:54:39 -04:00
echo "[cabal clean]"
2021-03-07 14:49:25 -05:00
cabal --verbose=0 v2-clean
2020-07-16 10:07:28 -04:00
2020-07-18 05:55:53 -04:00
2020-07-25 09:05:38 -04:00
.PHONY: list-tags
list-tags: $(MAKEPAGES)
2021-03-07 14:49:25 -05:00
$(MAKEPAGES) list-tags --untagged --nsfw
2020-07-25 09:05:38 -04:00
2020-07-19 12:05:01 -04:00
HOST ?= gallery.niss.website
2020-07-18 05:55:53 -04:00
REMOTE_USER ?= www-data
2020-07-19 12:05:01 -04:00
IDFILE ?= ~/.ssh/xyz
REMOTE_DIR ?= gallery
2020-07-18 05:55:53 -04:00
2020-07-18 05:58:41 -04:00
.PHONY: upload
upload: build
2021-02-07 02:26:39 -05:00
@rsync --recursive --partial --progress --copy-links \
--compress --human-readable --hard-links --size-only \
2021-02-09 06:35:39 -05:00
--delete --delete-after \
2021-03-07 14:49:25 -05:00
--rsh='ssh -l $(REMOTE_USER) -i $(IDFILE)' \
2021-02-07 02:26:39 -05:00
$(BUILDDIR)/ $(HOST):$(REMOTE_DIR)/
2020-07-18 05:55:53 -04:00
2020-07-31 23:09:23 -04:00
# one arg for extra flags
2020-07-24 09:20:10 -04:00
define copy
echo "[copy] "$@
mkdir -p "$(dir $@)"
2021-03-07 14:49:25 -05:00
cp $(1) --dereference "$^" "$@"
2020-07-24 09:20:10 -04:00
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
2023-01-15 15:39:03 -05:00
# args:
# 1. extra flags
define cjxl
echo "[cjxl] "$@
mkdir -p "$(dir $@)"
cjxl -d 1 "$^" "$@" $(1) 2>/dev/null
endef
2020-07-24 09:20:10 -04:00
# no args
define depend-gallery
echo "[deps] "$@
mkdir -p $(dir $@)
2021-03-07 14:49:25 -05:00
$(MAKEPAGES) $(MPFLAGS) depend-gallery $< \
--output "$@" \
--build-dir "$(BUILDDIR)" \
--data-dir "$(DATADIR)" \
--tmp-dir "$(TMPDIR)" \
--info "$(INFONAME)"
2020-07-24 09:20:10 -04:00
endef
# args:
# 1. gallery prefix
# 2. index filename
# 3. build dir
# 4. data dir
# 5. other flags
2020-07-24 09:20:10 -04:00
define depend-single
echo "[deps] "$@
mkdir -p "$(dir $@)"
$(MAKEPAGES) $(MPFLAGS) depend-single $(5) \
2021-03-07 14:49:25 -05:00
--output "$@" \
--prefix "$(1)" \
--index "$(2)" \
--build-dir "$(3)" \
--data-dir "$(4)" $<
2020-07-24 09:20:10 -04:00
endef
# args
# 1. index file
2020-07-24 09:20:10 -04:00
# 2. gallery prefix
# 3. other flags
define gallery
echo "[gallery] "$@
mkdir -p "$(dir $@)"
2021-03-07 14:49:25 -05:00
$(MAKEPAGES) $(MPFLAGS) gallery $(3) \
--index "$(1)" \
--root "$(ROOT)" \
--prefix "$(2)" \
--output "$@" \
2020-07-24 09:20:10 -04:00
$(filter $(DATADIR)/%/$(INFONAME),$^)
endef
# args:
# 1. data dir
2020-08-11 14:29:54 -04:00
# 2. gallery prefix
# 3. index file
# 4. other flags
2020-07-24 09:20:10 -04:00
define single
echo "[single] "$@
mkdir -p "$(dir $@)"
$(MAKEPAGES) $(MPFLAGS) single $(4) \
2021-03-07 14:49:25 -05:00
--root $(ROOT) \
--data-dir "$(1)" \
--prefix "$(2)" \
--index "$(3)" \
2021-03-07 14:49:25 -05:00
--output "$@" \
$<
2020-07-24 09:20:10 -04:00
endef
# args:
# 1. index file
# 2. gallery prefix
# 3. data dir
# 4. other flags
2020-07-24 09:20:10 -04:00
define rss
echo "[rss] "$@
mkdir -p "$(dir $@)"
2021-03-07 14:49:25 -05:00
$(MAKEPAGES) $(MPFLAGS) rss $(4) \
--index "$(1)" \
--root "$(ROOT)" \
--prefix "$(2)" \
--data-dir "$(3)" \
--output "$@" \
2020-07-24 09:20:10 -04:00
$(filter $(DATADIR)/%/$(INFONAME),$^)
endef
# never delete intermediate files
.SECONDARY:
2020-07-16 10:07:28 -04:00
.SILENT: