]> Lady’s Gitweb - Shrine-XSLT/blob - GNUmakefile
7f20dea36fa87d58640751d0b04d03ef7c7e324c
[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
30 headers := $(wildcard *-header.xml)
31 footers := $(wildcard *-footer.xml)
32 override prerequisites := $(TRANSFORM) $(headers) $(footers)
33
34 override indexsources := $(wildcard sources/index$(SOURCE_EXT) sources/index-*$(SOURCE_EXT))
35 override indices := $(patsubst sources/%$(SOURCE_EXT),public/%.html,$(indexsources))
36
37 override pagesources := $(filter-out $(indexsources),$(wildcard sources/*$(SOURCE_EXT) sources/*/*$(SOURCE_EXT)))
38 override pages := $(patsubst sources/%$(SOURCE_EXT),public/%/index.html,$(pagesources))
39
40 override resourcesources := $(wildcard $(addsuffix /*,$(basename $(pagesources))))
41 override resources := $(patsubst sources/%,public/%,$(resourcesources))
42
43 override feedsources := $(filter-out $(resourcesources),$(wildcard sources/*$(FEED_EXT) sources/*/*$(FEED_EXT)))
44 override feeds := $(patsubst sources/%$(FEED_EXT),public/%.atom,$(feedsources))
45
46 override content := $(indices) $(pages)
47
48 # This function does the following :—
49 #
50 # • Calls `transform.xslt` with the `$(1)`, providing `$(BASEIRI)` and `$(DATETIME) as params and providing `$(2)` (minus the initial `public/`) as the param `OUTPUTPATH`.
51 #
52 # • Removes any `xmlns` prefix declarations from output to `.html` files (with `sed`).
53 #
54 # • Removes any doctype for root elements other than `html` (with `grep -v`).
55 #
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]\|....[^ >]\)'\
60 > $(2)
61
62 all: $(content) $(resources) $(feeds);
63
64 $(indices): public/%.html: sources/%$(SOURCE_EXT) $(prerequisites)
65 @echo "Generating $@…"
66 @mkdir -p $(dir $@)
67 @$(call makexslt,$<,$@)
68
69 $(pages): public/%/index.html: sources/%$(SOURCE_EXT) $(prerequisites)
70 @echo "Generating $@…"
71 @mkdir -p $(dir $@)
72 @$(call makexslt,$<,$@)
73
74 $(resources): public/%: sources/%
75 @echo "Copying over $@…"
76 @mkdir -p $(dir $@)
77 @cp $< $@
78
79 $(feeds): public/%.atom: sources/%$(FEED_EXT) $(TRANSFORM)
80 @echo "Generating $@…"
81 @mkdir -p $(dir $@)
82 @$(call makexslt,$<,$@)
83
84 .PHONY: all ;
This page took 0.046483 seconds and 3 git commands to generate.