gallery/Makefile

182 lines
3.7 KiB
Makefile
Raw Normal View History

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
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
2020-07-17 06:29:13 -04:00
YAMLS != find $(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 $@)
2020-07-18 05:58:41 -04:00
$(MAKEPAGES) $(MPFLAGS) index $< -o $@
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)/%: %
2020-07-25 21:04:40 -04:00
$(call copy)
2020-07-18 05:58:41 -04:00
$(BUILDDIR)/%: $(TMPDIR)/%
2020-07-31 23:09:23 -04:00
$(call copy,-l)
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),>)
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 $@)
2020-07-18 05:44:51 -04:00
cabal v2-build all -O0 -v0 -j
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
2020-08-01 09:54:39 -04:00
ifneq ($(MAKECMDGOALS),mostlyclean)
2020-07-21 05:27:31 -04:00
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),distclean)
2020-07-25 09:05:38 -04:00
ifneq ($(MAKECMDGOALS),list-tags)
2020-07-19 06:08:44 -04:00
-include $(TMPDIR)/index.mk
2020-07-21 05:27:31 -04:00
endif
endif
2020-07-25 09:05:38 -04:00
endif
2020-08-01 09:54:39 -04:00
endif
2020-07-15 05:58:58 -04:00
2020-07-18 05:58:41 -04:00
2020-08-01 09:54:39 -04:00
.PHONY: mostlyclean clean distclean
mostlyclean:
echo "[clean $(BUILDDIR)]"
rm -rf $(BUILDDIR)
clean: mostlyclean
echo "[clean $(TMPDIR)]"
rm -rf $(TMPDIR)
2020-07-15 05:58:44 -04:00
distclean: clean
2020-08-01 09:54:39 -04:00
echo "[cabal clean]"
cabal -v0 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)
$(MAKEPAGES) list-tags -Un
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
2020-07-24 12:30:52 -04:00
@rsync -rPLzhH --delete -e 'ssh -l $(REMOTE_USER) -i $(IDFILE)' \
2020-07-18 05:55:53 -04:00
$(BUILDDIR)/ $(HOST):$(REMOTE_DIR)/
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 $@)"
2020-07-31 23:09:23 -04:00
cp $(1) -L "$^" "$@"
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
# 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:
2020-07-16 10:07:28 -04:00
.SILENT: