Separate out .default.xsl generation from Makefile

This commit is contained in:
Reinhard Müller 2020-04-23 15:17:37 +02:00
parent 06f757c6ab
commit ffb1c53bd0
3 changed files with 57 additions and 27 deletions

2
.gitignore vendored
View File

@ -1,9 +1,9 @@
d_year.en.xml
d_month.en.xml
d_day.en.xml
.default.xsl
tools/.texts-??.xml
.fundraising.??.xml
.default.xsl
.localmenu.*.xml
.*.xmllist
tags/tagged-*.en.xhtml

View File

@ -56,15 +56,6 @@ $(SUBDIRS): .FORCE
echo "* Preparing subdirectory $@"
$(MAKE) --silent --directory=$@
# -----------------------------------------------------------------------------
# Handle local menus
# -----------------------------------------------------------------------------
.PHONY: localmenus
all: localmenus
localmenus: $(SUBDIRS)
tools/update_localmenus.sh
# -----------------------------------------------------------------------------
# Timestamp files for regular jobs and XML inclusion in various places
# -----------------------------------------------------------------------------
@ -115,6 +106,12 @@ all: $(FUNDRAISING_LINKS)
ln -sf fundraising.en.xml $@; \
fi
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# The following steps are handled in an external script, because the list of
# files to generate is not known when the Makefile starts - some new tags might
# be introduced when generating the .xml files in the news/* subdirectories.
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# -----------------------------------------------------------------------------
# Create XSL symlinks
# -----------------------------------------------------------------------------
@ -125,23 +122,21 @@ all: $(FUNDRAISING_LINKS)
# determine which XSL script should be used to build a HTML page from a source
# file.
# All directories containing source files for HTML pages.
# FIXME: This runs when the makefile is parsed, before maybe new *.xhtml files
# are created in the news/<year>/ and events/<year>/ directories.
XHTML_DIRS := $(patsubst %/,%,$(sort $(dir $(shell find -name '*.??.xhtml'))))
.PHONY: default_xsl
all: default_xsl
default_xsl:
for directory in $(XHTML_DIRS); do \
dir="$${directory}"; \
prefix=""; \
until [ -f "$${dir}/default.xsl" -o "$${dir}" = "." ]; do \
dir="$${dir%/*}"; \
prefix="$${prefix}../"; \
done; \
ln -sf "$${prefix}default.xsl" "$${directory}/.default.xsl"; \
done
tools/update_defaultxsls.sh
# -----------------------------------------------------------------------------
# Update local menus
# -----------------------------------------------------------------------------
# After this step, all .localmenu.??.xml files will be up to date.
.PHONY: localmenus
all: localmenus
localmenus: $(SUBDIRS)
tools/update_localmenus.sh
# -----------------------------------------------------------------------------
# Update XML filelists
@ -158,9 +153,6 @@ default_xsl:
# correct XML files when generating the HTML pages. It is taken care that
# these files are only updated whenever their content actually changes, so
# they can serve as a prerequisite in the phase 2 Makefile.
# This step is handled in an external script, because the list of files to
# generate is not known when the Makefile starts - some new tags might be
# introduced when generating the .xml files in the news/* subdirectories.
.PHONY: xmllists
all: xmllists

38
tools/update_defaultxsls.sh Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Update default sytlesheets
# -----------------------------------------------------------------------------
# This script is called from the phase 1 Makefile and places a .default.xsl
# into each directory containing source files for HTML pages (*.xhtml). These
# .default.xsl are symlinks to the first available actual default.xsl found
# when climbing the directory tree upwards, it's the XSL stylesheet to be used
# for building the HTML files from this directory.
# -----------------------------------------------------------------------------
set -e
echo "* Updating default stylesheets"
# -----------------------------------------------------------------------------
# Get a list of all directories containing .xhtml source files
# -----------------------------------------------------------------------------
directories=$(
find -name "*.??.xhtml" \
| xargs dirname \
| sort --unique
)
# -----------------------------------------------------------------------------
# In each dir, place a .default.xsl symlink pointing to the nearest default.xsl
# -----------------------------------------------------------------------------
for directory in ${directories}; do
dir="${directory}"
prefix=""
until [ -f "${dir}/default.xsl" -o "${dir}" = "." ]; do
dir="$(dirname "${dir}")"
prefix="${prefix}../"
done
ln -sf "${prefix}default.xsl" "${directory}/.default.xsl"
done