From 59c226111e9c9a8f8750e6f8d33837fcf67ce779 Mon Sep 17 00:00:00 2001 From: Rhiannon Morris Date: Fri, 24 Jul 2020 15:20:10 +0200 Subject: [PATCH] reorganise make stuff --- Makefile | 90 +++++++++++++++++++++++++++++++++++-- make-pages/BuilderQQ.hs | 9 +++- make-pages/Depend.hs | 44 +++++------------- make-pages/make-pages.cabal | 1 + 4 files changed, 106 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index 28afada..ed1647a 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,13 @@ $(BUILDDIR)/%: $(TMPDIR)/% cp $< $@ +$(TMPDIR)/%_small.png: $(DATADIR)/%.png + $(call resize,$(SMALL),$(SMALL),^,-gravity center -crop 1:1+0) + +$(TMPDIR)/%_med.png: $(DATADIR)/%.png + $(call resize,$(MEDW),$(MEDH),>) + + $(MAKEPAGES): make-pages/*.hs make-pages/make-pages.cabal echo "[make-pages]" mkdir -p $(dir $@) @@ -57,10 +64,7 @@ $(MAKEPAGES): make-pages/*.hs make-pages/make-pages.cabal $(TMPDIR)/index.mk: $(DATADIR)/index.yaml $(YAMLS) $(MAKEPAGES) - echo "[deps] "$@ - mkdir -p $(dir $@) - $(MAKEPAGES) $(MPFLAGS) depend-gallery $< -o $@ \ - -B $(BUILDDIR) -D $(DATADIR) -T $(TMPDIR) -I $(INFONAME) + $(call depend-gallery) ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),distclean) @@ -89,4 +93,82 @@ upload: build $(BUILDDIR)/ $(HOST):$(REMOTE_DIR)/ +# no args +define copy +echo "[copy] "$@ +mkdir -p "$(dir $@)" +cp -Ll "$^" "$@" +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: + .SILENT: diff --git a/make-pages/BuilderQQ.hs b/make-pages/BuilderQQ.hs index 1f19fb9..95db76c 100644 --- a/make-pages/BuilderQQ.hs +++ b/make-pages/BuilderQQ.hs @@ -1,5 +1,9 @@ {-# LANGUAGE TemplateHaskell #-} -module BuilderQQ (b, Builder, toLazyText, fromText, fromString, fromChar) where +module BuilderQQ + (b, + Builder, toLazyText, fromText, fromString, fromChar, + textMap) +where import Data.Char (isLower, isSpace, isDigit, isAlphaNum) import Language.Haskell.TH @@ -179,3 +183,6 @@ pattern c :. t <- (Text.uncons -> Just (c, t)) fromChar :: Char -> Builder fromChar = singleton + +textMap :: (Char -> Builder) -> Text -> Builder +textMap f = Text.foldl' (\buf c -> buf <> f c) mempty diff --git a/make-pages/Depend.hs b/make-pages/Depend.hs index 00efeee..01e1c43 100644 --- a/make-pages/Depend.hs +++ b/make-pages/Depend.hs @@ -63,20 +63,10 @@ dependGallery' (GalleryInfo {title, description, prefix, filters}) $@index: $@path $@path: $@pages' $@files' $@rss $$(MAKEPAGES) - echo "[gallery] "$$@ - mkdir -p $$(dir $$@) - $$(MAKEPAGES) $$(MPFLAGS) gallery \ - -p "$@prefix" -t "$*title" $flags -o "$$@" \ - $$(filter $$(DATADIR)/%/$$(INFONAME),$$^) + $$(call gallery,$title',$@prefix,$flags) $@rss: $@files' $$(MAKEPAGES) - echo "[rss] "$$@ - mkdir -p $$(dir $$@) - $$(MAKEPAGES) $$(MPFLAGS) rss -t "$*title" \ - -d "$*description" \ - -R "$$(ROOT)" -p "$@prefix" \ - -o "$$@" -D "$@data_" \ - $$(filter $$(DATADIR)/%/$$(INFONAME),$$^) + $$(call rss,$title',$description',$@prefix,$@data_) $rules @@ -84,6 +74,9 @@ dependGallery' (GalleryInfo {title, description, prefix, filters}) |] where flags = filtersToFlags filters + title' = substComma title + description' = substComma description + substComma = textMap \case ',' -> "$(comma)"; c -> fromChar c makeRules :: FilePath -- ^ prefix -> GalleryFilters @@ -93,31 +86,16 @@ makeRules :: FilePath -- ^ prefix -> Builder makeRules prefix filters build data_ tmp = [b|@0 $@buildPrefix/%/index.html: $@data_/%/info.yaml $$(MAKEPAGES) - echo "[single] "$$@ - mkdir -p $$(dir $$@) - $$(MAKEPAGES) $$(MPFLAGS) single -D "$@data_" "$$<" -o "$$@" $flags + $$(call single,$@data_,$flags) $@tmpPrefix/%.mk: $@data_/%/info.yaml $$(MAKEPAGES) - echo "[deps] "$$@ - mkdir -p $$(dir $$@) - $$(MAKEPAGES) $$(MPFLAGS) depend-single $flags \ - -o "$$@" -p "$@prefix" -B "$@build" -D "$@data_" $$< + $$(call depend-single,$@prefix,$@build,$@data_,$flags) + + $@buildPrefix/%: $@tmp/% + $$(call copy) $@buildPrefix/%: $@data_/% - echo "[copy] "$$@ - mkdir -p $$(dir $$@) - cp "$$<" "$$@" - - $@buildPrefix/%_small.png: $@data_/%.png - echo "[resize] "$$@ - mkdir -p $$(dir $$@) - convert -resize '$$(SMALL)x$$(SMALL)^' \ - -gravity center -crop 1:1+0 "$$<" "$$@" - - $@buildPrefix/%_med.png: $@data_/%.png - echo "[resize] "$$@ - mkdir -p $$(dir $$@) - convert -resize '$$(MEDW)x$$(MEDH)>' "$$<" "$$@" + $$(call copy) |] where buildPrefix = build prefix diff --git a/make-pages/make-pages.cabal b/make-pages/make-pages.cabal index ab669e8..2d915df 100644 --- a/make-pages/make-pages.cabal +++ b/make-pages/make-pages.cabal @@ -32,6 +32,7 @@ executable make-pages DerivingStrategies, DuplicateRecordFields, FlexibleInstances, + LambdaCase, NamedFieldPuns, OverloadedLabels, OverloadedStrings,