3 # This GNUmakefile searches the `sources/` directory for files with an extension of `.atom` or `.xml` and applies `transform.xslt` to them, outputting the result in one of the following locations :—
5 # • For files with a location of `sources/index.xml` or `sources/index-*.xml`, the transformed file will be written to `public/%.html` (where `%` is the filename).
7 # • For all other files with a location of `sources/*.xml` or `sources/*/*.xml`, the transformed file will be written to `public/%/index.html` (where `%` is the filename and subdirectory if applicable).
8 # Any files in a corresponding sibling directory (i·e without the `.xml`) are copied over verbatim.
9 # Only one level of subdirectory is supported.
11 # • For files with a location of `sources/*.atom` or `sources/*/*.atom`, the transformed file will be written to `public/%.atom` (where `%` is the filename and subdirectory if applicable).
13 # By default, running `make` will do this for all applicable source files.
17 # © 2022–2023 Lady [@ Lady’s Computer]
19 # This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
20 # If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
22 BASEIRI = http://example.com
23 DATETIME = $(shell date -Iseconds)
26 TRANSFORM = transform.xslt
32 headers := $(wildcard *-header.xml)
33 footers := $(wildcard *-footer.xml)
34 override prerequisites := $(YIELD_DEPENDENCIES) template.xml $(TRANSFORM) $(headers) $(footers)
36 override indexsources := $(wildcard sources/index$(SOURCE_EXT) sources/index-*$(SOURCE_EXT))
37 override indices := $(patsubst sources/%$(SOURCE_EXT),public/%.html,$(indexsources))
39 override pagesources := $(filter-out $(indexsources),$(wildcard sources/*$(SOURCE_EXT) sources/*/*$(SOURCE_EXT)))
40 override pages := $(patsubst sources/%$(SOURCE_EXT),public/%/index.html,$(pagesources))
42 override resourcesources := $(wildcard $(addsuffix /*,$(basename $(pagesources))))
43 override resources := $(patsubst sources/%,public/%,$(resourcesources))
45 override feedsources := $(filter-out $(resourcesources),$(wildcard sources/*$(FEED_EXT) sources/*/*$(FEED_EXT)))
46 override feeds := $(patsubst sources/%$(FEED_EXT),public/%.atom,$(feedsources))
48 override content := $(indices) $(pages)
50 # This function does the following :—
52 # • Calls `transform.xslt` with the `$(1)`, providing `$(BASEIRI)` and `$(DATETIME) as params and providing `$(2)` (minus the initial `public/`) as the param `OUTPUTPATH`.
54 # • Removes any `xmlns` prefix declarations from output to `.html` files (with `sed`).
56 # • Removes any doctype for root elements other than `html` (with `grep -v`).
58 # • Saves the output to `$(2)`.
59 override makexslt = $(YIELD) $(1)\
60 | $(XSLT) --nonet --novalid $(XSLTOPTS) --stringparam BASEIRI "$(BASEIRI)" --stringparam DATETIME "$(DATETIME)" --stringparam OUTPUTPATH "$(patsubst public/%,/%,$(2))" transform.xslt -\
61 $(if $(filter %.html,$(2)),| sed 's/ xmlns:[0-9A-Za-z_-]*="[^"]*"//g',)\
62 | grep -v '^<!DOCTYPE \([^h]\|.[^t]\|..[^m]\|...[^l]\|....[^ >]\)'\
65 all: $(content) $(resources) $(feeds);
67 $(indices): public/%.html: sources/%$(SOURCE_EXT) $(prerequisites)
68 @echo "Generating $@…"
70 @$(call makexslt,$<,$@)
72 $(pages): public/%/index.html: sources/%$(SOURCE_EXT) $(prerequisites)
73 @echo "Generating $@…"
75 @$(call makexslt,$<,$@)
77 $(resources): public/%: sources/%
78 @echo "Copying over $@…"
82 $(feeds): public/%.atom: sources/%$(FEED_EXT) $(TRANSFORM)
83 @echo "Generating $@…"
85 @$(call makexslt,$<,$@)