]> Lady’s Gitweb - Shrine-XSLT/blob - GNUmakefile
fd272ee23e55d059e145d69b0d4c4c27a905dcd3
[Shrine-XSLT] / GNUmakefile
1 SHELL = /bin/sh
2
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 :—
4 #
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).
6 #
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.
10 #
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).
12 #
13 # By default, running `make` will do this for all applicable source files.
14 #
15 # ___
16 #
17 # © 2022–2023 Lady [@ Lady’s Computer]
18 #
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/.
21
22 BASEIRI = http://example.com
23 DATETIME = $(shell date -Iseconds)
24 FEED_EXT = .atom
25 SOURCE_EXT = .xml
26 TRANSFORM = transform.xslt
27 XSLT = xsltproc
28 XSLTOPTS =
29 YIELD = cat
30 YIELD_DEPENDENCIES =
31
32 headers := $(wildcard *-header.xml)
33 footers := $(wildcard *-footer.xml)
34 override prerequisites := $(YIELD_DEPENDENCIES) template.xml $(TRANSFORM) $(headers) $(footers)
35
36 override indexsources := $(wildcard sources/index$(SOURCE_EXT) sources/index-*$(SOURCE_EXT))
37 override indices := $(patsubst sources/%$(SOURCE_EXT),public/%.html,$(indexsources))
38
39 override pagesources := $(filter-out $(indexsources),$(wildcard sources/*$(SOURCE_EXT) sources/*/*$(SOURCE_EXT)))
40 override pages := $(patsubst sources/%$(SOURCE_EXT),public/%/index.html,$(pagesources))
41
42 override resourcesources := $(wildcard $(addsuffix /*,$(basename $(pagesources))))
43 override resources := $(patsubst sources/%,public/%,$(resourcesources))
44
45 override feedsources := $(filter-out $(resourcesources),$(wildcard sources/*$(FEED_EXT) sources/*/*$(FEED_EXT)))
46 override feeds := $(patsubst sources/%$(FEED_EXT),public/%.atom,$(feedsources))
47
48 override content := $(indices) $(pages)
49
50 # This function does the following :—
51 #
52 # • Calls `transform.xslt` with the `$(1)`, providing `$(BASEIRI)` and `$(DATETIME) as params and providing `$(2)` (minus the initial `public/`) as the param `OUTPUTPATH`.
53 #
54 # • Removes any `xmlns` prefix declarations from output to `.html` files (with `sed`).
55 #
56 # • Removes any doctype for root elements other than `html` (with `grep -v`).
57 #
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]\|....[^ >]\)'\
63 > $(2)
64
65 all: $(content) $(resources) $(feeds);
66
67 $(indices): public/%.html: sources/%$(SOURCE_EXT) $(prerequisites)
68 @echo "Generating $@…"
69 @mkdir -p $(dir $@)
70 @$(call makexslt,$<,$@)
71
72 $(pages): public/%/index.html: sources/%$(SOURCE_EXT) $(prerequisites)
73 @echo "Generating $@…"
74 @mkdir -p $(dir $@)
75 @$(call makexslt,$<,$@)
76
77 $(resources): public/%: sources/%
78 @echo "Copying over $@…"
79 @mkdir -p $(dir $@)
80 @cp $< $@
81
82 $(feeds): public/%.atom: sources/%$(FEED_EXT) $(TRANSFORM)
83 @echo "Generating $@…"
84 @mkdir -p $(dir $@)
85 @$(call makexslt,$<,$@)
86
87 .PHONY: all ;
This page took 0.050181 seconds and 3 git commands to generate.