summaryrefslogtreecommitdiffhomepage
path: root/GNUmakefile
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-11-05 00:05:37 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-11-05 00:05:37 +0100
commit98e4ba2773b97de3385bbfbd6c344c2e15c3f623 (patch)
tree447894dd4ba55bb05905095f91f9fe32e07f19a3 /GNUmakefile
parent3e19472096334582fb9893350b22085ca43e5b01 (diff)
Rename Makefile to GNUmakefile
Diffstat (limited to 'GNUmakefile')
-rw-r--r--GNUmakefile94
1 files changed, 94 insertions, 0 deletions
diff --git a/GNUmakefile b/GNUmakefile
new file mode 100644
index 0000000..f0c56b7
--- /dev/null
+++ b/GNUmakefile
@@ -0,0 +1,94 @@
+# Eurozone coin and -banknote types
+eznotes := 5e 10e 20e 50e 100e 200e 500e
+ezcoins := 1c 2c 5c 10c 20c 50c 1e 2e
+ezcodes := $(shell \
+ grep -Eo '^[A-Z]{2}' data/coins \
+ | sort \
+ | uniq \
+ | tr A-Z a-z \
+)
+
+# Source files that aren’t dynamically generated
+sources := \
+ $(shell find src -type f -name 'index.gsp') \
+ $(shell find src -type f -name '*.css') \
+ $(shell find src -type f -name '*.svg') \
+ $(shell find src -type f -name '*.woff2')
+
+# Different euro coin and -banknote page types
+eurocc := $(ezcodes:%=out/euro/%/index.html)
+eurocd := $(ezcoins:%=out/euro/%/index.html)
+eurond := $(eznotes:%=out/euro/%/index.html)
+euront := out/euro/tn/index.html
+
+# Output files we want to generate
+outputs := $(sources:%.gsp=%.html)
+outputs := $(outputs:src/%=out/%)
+outputs := $(outputs) $(eurocc) $(eurocd) $(eurond) $(euront)
+
+# Folders we need to generate before the files. The sort function is used to
+# remove duplicates.
+outdirs := $(sort $(dir $(outputs)))
+
+# Common files that (almost) all *.gsp files depend on
+gspdeps := lib.m4 src/nav.gsp src/head.gsp src/foot.gsp src/table-key.gsp
+
+# Dependencies for certain /euro files
+euroxyzdeps := src/euro/index.xyz.gsp src/euro/nav.xyz.gsp data/country-info
+euroccdeps := $(subst xyz,ccoins,$(euroxyzdeps)) data/coins data/ccs data/errors
+eurocddeps := $(subst xyz,dcoins,$(euroxyzdeps)) data/coins
+euronddeps := $(subst xyz,dnotes,$(euroxyzdeps)) data/notes data/note-info
+eurotndeps := src/euro/index.tnotes.gsp src/euro/nav.dnotes.gsp data/notes
+
+# Macro to get a countries demonym from their country code
+demonym = $(shell awk '$$1 == toupper("$1") { print $$2 }' data/country-info)
+
+# Macros to handle dependencies for world pages
+wpath = $(if $(filter $2,o),\
+ out/world/$(if $(filter $2,c),coins,notes)/$1/index.html,\
+ src/world/$(if $(filter $2,c),coins,notes)/$1/index.gsp\
+)
+wout = $(foreach x,$1,$(call wpath,$x,o $2))
+_wdeps = $(wildcard data/world/*.$(if $(filter $1,br),bra,$1))
+wdeps = $(call wpath,$1,$2) $(call _wdeps,$1) $(gspdeps)
+
+all: $(outdirs) $(outputs)
+
+$(outdirs)&:
+ mkdir -p $(outdirs)
+
+$(call wout,ez): $(call wdeps,ez)
+out/%.html: src/%.gsp $(gspdeps)
+ m4 -P lib.m4 $< | gsp >$@
+
+$(eurocc): out/euro/%/index.html: $(gspdeps) $(euroccdeps)
+ m4 -P -D__coins -D__code=$* -D__demonym=$(call demonym,$*) \
+ lib.m4 src/euro/index.ccoins.gsp | gsp >$@
+
+$(eurocd): out/euro/%/index.html: $(eurocddeps) $(gspdeps)
+ m4 -P -D__coins -D__denom=$* lib.m4 $< | gsp >$@
+$(eurond): out/euro/%/index.html: $(euronddeps) $(gspdeps)
+ m4 -P -D__notes -D__denom=$* lib.m4 $< | gsp >$@
+
+$(euront): out/euro/%/index.html: $(eurotndeps) $(gspdeps)
+ m4 -P -D__notes lib.m4 $< | gsp >$@
+
+$(call wout,br,c): $(call wdeps,br,c)
+$(call wout,us,c): $(call wdeps,us,c)
+$(call wout,br us,c):
+ m4 -P -D__coins lib.m4 $< | gsp >$@
+
+out/%: src/%
+ cp $< $@
+
+check:
+ LANG=en_US.UTF-8 find src -name '*.gsp' -exec \
+ aspell --home-dir=./ --ignore-case check {} \;
+
+clean:
+ rm -rf out
+
+serve:
+ darkhttpd out --daemon
+
+.PHONY: all check clean serve