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
30 headers := $(wildcard *-header.xml)
31 footers := $(wildcard *-footer.xml)
32 override prerequisites := $(TRANSFORM) $(headers) $(footers)
34 override indexsources := $(wildcard sources/index$(SOURCE_EXT) sources/index-*$(SOURCE_EXT))
35 override indices := $(patsubst sources/%$(SOURCE_EXT),public/%.html,$(indexsources))
37 override pagesources := $(filter-out $(indexsources),$(wildcard sources/*$(SOURCE_EXT) sources/*/*$(SOURCE_EXT)))
38 override pages := $(patsubst sources/%$(SOURCE_EXT),public/%/index.html,$(pagesources))
40 override resourcesources := $(wildcard $(addsuffix /*,$(basename $(pagesources))))
41 override resources := $(patsubst sources/%,public/%,$(resourcesources))
43 override feedsources := $(filter-out $(resourcesources),$(wildcard sources/*$(FEED_EXT) sources/*/*$(FEED_EXT)))
44 override feeds := $(patsubst sources/%$(FEED_EXT),public/%.atom,$(feedsources))
46 override content := $(indices) $(pages)
48 # This function does the following :—
50 # • Calls `transform.xslt` with the `$(1)`, providing `$(BASEIRI)` and `$(DATETIME) as params and providing `$(2)` (minus the initial `public/`) as the param `OUTPUTPATH`.
52 # • Removes any `xmlns` prefix declarations from output to `.html` files (with `sed`).
54 # • Removes any doctype for root elements other than `html` (with `grep -v`).
56 # • Saves the output to `$(2)`.
57 override makexslt = $(XSLT) --nonet --novalid $(XSLTOPTS) --stringparam BASEIRI "$(BASEIRI)" --stringparam DATETIME "$(DATETIME)" --stringparam OUTPUTPATH "$(patsubst public/%,/%,$(2))" transform.xslt $(1)\
58 $(if $(filter %.html,$(2)),| sed 's/ xmlns:[0-9A-Za-z_-]*="[^"]*"//g',)\
59 | grep -v '^<!DOCTYPE \([^h]\|.[^t]\|..[^m]\|...[^l]\|....[^ >]\)'\
62 all: $(content) $(resources) $(feeds);
64 $(indices): public/%.html: sources/%$(SOURCE_EXT) $(prerequisites)
65 @echo "Generating $@…"
67 @$(call makexslt,$<,$@)
69 $(pages): public/%/index.html: sources/%$(SOURCE_EXT) $(prerequisites)
70 @echo "Generating $@…"
72 @$(call makexslt,$<,$@)
74 $(resources): public/%: sources/%
75 @echo "Copying over $@…"
79 $(feeds): public/%.atom: sources/%$(FEED_EXT) $(TRANSFORM)
80 @echo "Generating $@…"
82 @$(call makexslt,$<,$@)