X-Git-Url: https://git.ladys.computer/Shrine-XSLT/blobdiff_plain/a47140cf7262ffb49c2fe4e109deb960dd9ca6dc..ef481a0e92428b9daff97c50dc4818f05b46726c:/GNUmakefile?ds=inline diff --git a/GNUmakefile b/GNUmakefile index fa30f68..e9d08c0 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,46 +1,94 @@ SHELL = /bin/sh -# This GNUmakefile searches the `sources/` directory for files with an extension of `.xml` and applies `transform.xslt` to them, outputting the result in one of two locations :— +# 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 :— # -# • For files with a location of `sources/index.xml` or `sources/index-*.xml`, the transformed file will be written to `public/%.xhtml` (where `%` is the filename). +# • 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). # -# • For all other files with a location of `sources/*.xml` or `sources/*/*.xml`, the transformed file will be written to `public/%/index.xhtml` (where `%` is the filename and subdirectory if applicable). +# • 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). +# Any files in a corresponding sibling directory (i·e without the `.xml`) are copied over verbatim. # Only one level of subdirectory is supported. # +# • 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). +# # By default, running `make` will do this for all applicable source files. # # ___ # -# © 2022 Lady [@ Lady’s Computer] +# © 2022–2023 Lady [@ Lady’s Computer] # # This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. # If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. -XHTMLEXT = xhtml +BASEIRI = http://example.com +DATETIME = $(shell date -Iseconds) +FEED_EXT = .atom +FOOTER_SUFFIX = -footer.xml +HEADER_SUFFIX = -header.xml +OUTPUT_DIR = public +SOURCE_DIR = sources +SOURCE_EXT = .xml +TEMPLATE = template.xml +TRANSFORM = transform.xslt XSLT = xsltproc XSLTOPTS = +YIELD = cat +YIELD_DEPENDENCIES = + +headers := $(wildcard *$(HEADER_SUFFIX)) +footers := $(wildcard *$(FOOTER_SUFFIX)) +override prerequisites := $(YIELD_DEPENDENCIES) $(TEMPLATE) $(TRANSFORM) $(headers) $(footers) + +override indexsources := $(wildcard $(SOURCE_DIR)/index$(SOURCE_EXT) $(SOURCE_DIR)/index-*$(SOURCE_EXT)) +override indices := $(patsubst $(SOURCE_DIR)/%$(SOURCE_EXT),$(OUTPUT_DIR)/%.html,$(indexsources)) + +override pagesources := $(filter-out $(indexsources),$(wildcard $(SOURCE_DIR)/*$(SOURCE_EXT) $(SOURCE_DIR)/*/*$(SOURCE_EXT))) +override pages := $(patsubst $(SOURCE_DIR)/%$(SOURCE_EXT),$(OUTPUT_DIR)/%/index.html,$(pagesources)) + +override resourcesources := $(wildcard $(addsuffix /*,$(basename $(pagesources)))) +override resources := $(patsubst $(SOURCE_DIR)/%,$(OUTPUT_DIR)/%,$(resourcesources)) -headers := $(wildcard *-header.xml) -footers := $(wildcard *-footer.xml) -override prerequisites := transform.xslt $(headers) $(footers) +override feedsources := $(filter-out $(resourcesources),$(wildcard $(SOURCE_DIR)/*$(FEED_EXT) $(SOURCE_DIR)/*/*$(FEED_EXT))) +override feeds := $(patsubst $(SOURCE_DIR)/%$(FEED_EXT),$(OUTPUT_DIR)/%.atom,$(feedsources)) -override indexsources := $(wildcard sources/index.xml sources/index-*.xml) -override indices := $(patsubst sources/%.xml,public/%.$(XHTMLEXT),$(indexsources)) +override content := $(indices) $(pages) -override pagesources := $(filter-out $(indexsources),$(wildcard sources/*.xml sources/*/*.xml)) -override pages := $(patsubst sources/%.xml,public/%/index.$(XHTMLEXT),$(pagesources)) +# This function does the following :— +# +# • `$(YIELD)`s `$(1)`. +# +# • 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`. +# +# • Removes any `xmlns` prefix declarations from output to `.html` files (with `sed`). +# +# • Removes any doctype for root elements other than `html` (with `grep -v`). +# +# • Saves the output to `$(2)`. +override makexslt = $(YIELD) $(1)\ + | $(XSLT) --nonet --novalid $(XSLTOPTS) --stringparam BASEIRI "$(BASEIRI)" --stringparam DATETIME "$(DATETIME)" --stringparam OUTPUTPATH "$(patsubst $(OUTPUT_DIR)/%,/%,$(2))" $(TRANSFORM) -\ + $(if $(filter %.html,$(2)),| sed 's/ xmlns:[0-9A-Za-z_-]*="[^"]*"//g',)\ + | grep -v '^]\)'\ + > $(2) -override makexslt = $(XSLT) --nonet --novalid $(XSLTOPTS) -o $(2) transform.xslt $(1) +all: $(content) $(resources) $(feeds); -all: $(indices) $(pages) ; +$(indices): $(OUTPUT_DIR)/%.html: $(SOURCE_DIR)/%$(SOURCE_EXT) $(prerequisites) + @echo "Generating $@…" + @mkdir -p $(dir $@) + @$(call makexslt,$<,$@) -$(indices): public/%.$(XHTMLEXT): sources/%.xml $(prerequisites) - $(call makexslt,$<,$@) +$(pages): $(OUTPUT_DIR)/%/index.html: $(SOURCE_DIR)/%$(SOURCE_EXT) $(prerequisites) + @echo "Generating $@…" + @mkdir -p $(dir $@) + @$(call makexslt,$<,$@) -$(pages): public/%/index.$(XHTMLEXT): sources/%.xml $(prerequisites) - $(call makexslt,$<,$@) +$(resources): $(OUTPUT_DIR)/%: $(SOURCE_DIR)/% + @echo "Copying over $@…" + @mkdir -p $(dir $@) + @cp $< $@ -clean: - rm -f $(indices) $(pages) +$(feeds): $(OUTPUT_DIR)/%.atom: $(SOURCE_DIR)/%$(FEED_EXT) $(TRANSFORM) + @echo "Generating $@…" + @mkdir -p $(dir $@) + @$(call makexslt,$<,$@) -.PHONY: all clean ; +.PHONY: all ;