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