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