]> Lady’s Gitweb - Shushe/commitdiff
Make generator metadata more easy to override 0.5.0
authorLady <redacted>
Sat, 3 Feb 2024 03:57:52 +0000 (22:57 -0500)
committerLady <redacted>
Sun, 4 Feb 2024 00:48:43 +0000 (19:48 -0500)
GNUmakefile
README.markdown
lib/catalog2parser.xslt
lib/catalog2transform.xslt

index 0ed0e9003addc0c6407c2cac26f560871d66968c..4f1fb5b52e538e1d882a8e6f8df0e0f8501c5dd6 100644 (file)
@@ -166,6 +166,21 @@ TRANSFORMS := $(sort $(patsubst ./%,%,$(wildcard $(THISDIR)/transforms/*.xslt))
 # List of types which should be treated as X·M·L.
 XMLTYPES := application/xml text/xml
 
 # List of types which should be treated as X·M·L.
 XMLTYPES := application/xml text/xml
 
+# The name of the generator program.
+GENERATOR := ⛩️📰 书社
+
+ifdef GIT
+ifneq ($(wildcard $(THISDIR)/.git),)
+# A description of the current git revision of ⛩️📰 书社.
+VERSION := $(shell cd $(THISDIR); $(GIT) describe 2> /dev/null || $(GIT) rev-parse HEAD 2> /dev/null || true)
+endif
+
+ifneq ($(wildcard .git),)
+# A description of the current git revision of the working directory.
+SRCREV := $(shell $(GIT) describe 2> /dev/null || $(GIT) rev-parse HEAD 2> /dev/null || true)
+endif
+endif
+
 # Set to a non·empty value to print all commands as they run.
 VERBOSE :=
 
 # Set to a non·empty value to print all commands as they run.
 VERBOSE :=
 
@@ -220,18 +235,6 @@ sourceincludes := $(shell $(FIND) $(foreach dir,$(INCLUDEDIR),$(call quote,$(dir
 # (overridable) Collect all of the applicable source files from the source directory, removing any which are also includes.
 sourcefiles := $(filter-out $(sourceincludes),$(shell $(FIND) $(foreach dir,$(SRCDIR),$(call quote,$(dir))) '(' $(FINDRULES) ')' -a -type f))
 
 # (overridable) Collect all of the applicable source files from the source directory, removing any which are also includes.
 sourcefiles := $(filter-out $(sourceincludes),$(shell $(FIND) $(foreach dir,$(SRCDIR),$(call quote,$(dir))) '(' $(FINDRULES) ')' -a -type f))
 
-ifdef GIT
-ifneq ($(wildcard $(THISDIR)/.git),)
-# (overridable) The name of the current revision of ⛩️📰 书社, or its hash if the current revision is not a tag.
-thisrev = $(shell cd $(THISDIR); $(GIT) describe 2> /dev/null || $(GIT) rev-parse HEAD 2> /dev/null || true)
-endif
-
-ifneq ($(wildcard .git),)
-# (overridable) The name of the current revision of the working directory, or its hash if the current revision is not a tag.
-srcrev = $(shell $(GIT) describe 2> /dev/null || $(GIT) rev-parse HEAD 2> /dev/null || true)
-endif
-endif
-
 # Figure out the file type of each source file and source include.
 ifneq ($(wildcard $(BUILDDIR)/magic.mgc),)
 override types := $(shell $(SED) 's/^ *//;s/ *$$//;s/ {2,}/ /g' <<< $(call quote,$(sourcefiles) $(sourceincludes)) | $(TR) ' ' '\n' | $(FILE) -m $(call quote,$(BUILDDIR)/magic.mgc) --mime-type --separator '|' --files-from - | $(SED) 's/| */|/g')
 # Figure out the file type of each source file and source include.
 ifneq ($(wildcard $(BUILDDIR)/magic.mgc),)
 override types := $(shell $(SED) 's/^ *//;s/ *$$//;s/ {2,}/ /g' <<< $(call quote,$(sourcefiles) $(sourceincludes)) | $(TR) ' ' '\n' | $(FILE) -m $(call quote,$(BUILDDIR)/magic.mgc) --mime-type --separator '|' --files-from - | $(SED) 's/| */|/g')
@@ -460,7 +463,7 @@ $(BUILDDIR)/parser.xslt: $(BUILDDIR)/parser.catalog $(THISDIR)/lib/catalog2parse
 $(call parsed,$(sourcefiles) $(sourceincludes)) : % : $$(call unparsed,$$@) $(typeupdates)
        @$(PRINTF) '%s\n' $(call quote,Processing `$<´…)
        $(silent)$(call ensuredirectory,$(dir $@))
 $(call parsed,$(sourcefiles) $(sourceincludes)) : % : $$(call unparsed,$$@) $(typeupdates)
        @$(PRINTF) '%s\n' $(call quote,Processing `$<´…)
        $(silent)$(call ensuredirectory,$(dir $@))
-       $(silent)$(if $(filter $<,$(assetfiles)),$(PRINTF) '%s\n' $(call quote,<object xmlns="http://www.w3.org/1999/xhtml" type="$(call typeoffile,$<)" data="$(call datauri,$<)"/>) > $(call quote,$@),$(if $(filter $<,$(plaintextfiles)),$(call wrapplaintext,$<),$(CAT) $(call quote,$<)) | $(XSLTPROC) -o $(call quote,$@) --stringparam BUILDTIME '$(shell TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ')' --stringparam SRCTIME '$(shell TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$(call unparsed,$@)))'$(if $(thisrev), --stringparam VERSION $(call quote,$(thisrev)),)$(if $(srcrev), --stringparam SRCREV $(call quote,$(srcrev)),) $(call quote,$(BUILDDIR)/parser.xslt) -)
+       $(silent)$(if $(filter $<,$(assetfiles)),$(PRINTF) '%s\n' $(call quote,<object xmlns="http://www.w3.org/1999/xhtml" type="$(call typeoffile,$<)" data="$(call datauri,$<)"/>) > $(call quote,$@),$(if $(filter $<,$(plaintextfiles)),$(call wrapplaintext,$<),$(CAT) $(call quote,$<)) | $(XSLTPROC) -o $(call quote,$@) --stringparam BUILDTIME '$(shell TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ')' --stringparam SRCTIME '$(shell TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$(call unparsed,$@)))'$(if $(GENERATOR), --stringparam GENERATOR $(call quote,$(GENERATOR)))$(if $(VERSION), --stringparam VERSION $(call quote,$(VERSION)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/parser.xslt) -)
 
 # Generate a catalog of all parsed files, for use when processing includes.
 #
 
 # Generate a catalog of all parsed files, for use when processing includes.
 #
@@ -496,7 +499,7 @@ $(BUILDDIR)/transform.xslt : $(BUILDDIR)/transform.catalog $(THISDIR)/lib/catalo
 $(call compiled,$(compilablefiles)) : $(BUILDDIR)/public/% : $$(call parsed,$$(call uncompiled,$$@)) $(BUILDDIR)/transform.xslt $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@)))
        $(silent)$(call ensuredirectory,$(dir $@))
        @$(PRINTF) '%s\n' $(call quote,Compiling </$*>…)
 $(call compiled,$(compilablefiles)) : $(BUILDDIR)/public/% : $$(call parsed,$$(call uncompiled,$$@)) $(BUILDDIR)/transform.xslt $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@)))
        $(silent)$(call ensuredirectory,$(dir $@))
        @$(PRINTF) '%s\n' $(call quote,Compiling </$*>…)
-       $(silent)$(XSLTPROC) -o $(call quote,$@) --stringparam CATALOG 'catalog' --stringparam BUILDTIME '$(shell TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ')' --stringparam SRCTIME '$(shell TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$(call uncompiled,$@)))' --stringparam PATH $(call quote,/$*)$(if $(thisrev), --stringparam VERSION $(call quote,$(thisrev)),)$(if $(srcrev), --stringparam SRCREV $(call quote,$(srcrev)),) $(call quote,$(BUILDDIR)/transform.xslt) $(call quote,$<)
+       $(silent)$(XSLTPROC) -o $(call quote,$@) --stringparam CATALOG 'catalog' --stringparam BUILDTIME '$(shell TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ')' --stringparam SRCTIME '$(shell TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$(call uncompiled,$@)))' --stringparam PATH $(call quote,/$*)$(if $(GENERATOR), --stringparam GENERATOR $(call quote,$(GENERATOR)))$(if $(VERSION), --stringparam VERSION $(call quote,$(VERSION)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/transform.xslt) $(call quote,$<)
 $(call compiled,$(filter $(assetfiles),$(sourcefiles))) : $(BUILDDIR)/public/% : $$(call uncompiled,$$@)
        @$(PRINTF) '%s\n' $(call quote,Compiling </$*>…)
        $(silent)$(call ensuredirectory,$(dir $@))
 $(call compiled,$(filter $(assetfiles),$(sourcefiles))) : $(BUILDDIR)/public/% : $$(call uncompiled,$$@)
        @$(PRINTF) '%s\n' $(call quote,Compiling </$*>…)
        $(silent)$(call ensuredirectory,$(dir $@))
index e2838fad0204817504137d83002e34ca4f0b528e..573fb86e51fe59b89c2ac7586986d5a23330c71b 100644 (file)
@@ -213,6 +213,17 @@ The following additional variables can be used to control the behaviour
   A white·space‐separated list of media types to consider X·M·L
     (default: `application/xml text/xml`).
 
   A white·space‐separated list of media types to consider X·M·L
     (default: `application/xml text/xml`).
 
+- **`GENERATOR`:**
+  The name of the generator program (default: `⛩️📰 书社`).
+
+- **`VERSION`:**
+  The current version of `GENERATOR` (default: derived from the current
+    git tag/branch/commit).
+
+- **`SRCREV`:**
+  The current version of the source files (default: derived from the
+    current git tag/branch/commit).
+
 - **`VERBOSE`:**
   If this variable has a value, every recipe instruction will be
     printed when it runs (default: empty).
 - **`VERBOSE`:**
   If this variable has a value, every recipe instruction will be
     printed when it runs (default: empty).
@@ -420,16 +431,17 @@ The following params are made available globally in parsers and
 - **`BUILDTIME`:**
   The current time.
 
 - **`BUILDTIME`:**
   The current time.
 
+- **`GENERATOR`:**
+  The value of the `GENERATOR` variable (if present).
+
 - **`SRCREV`:**
 - **`SRCREV`:**
-  The tag or hash of the current commit in the working directory (if
-    `GIT` is defined and `./.git` exists).
+  The value of the `SRCREV` variable (if present).
 
 - **`SRCTIME`:**
   The time at which the source file was last modified.
 
 - **`VERSION`:**
 
 - **`SRCTIME`:**
   The time at which the source file was last modified.
 
 - **`VERSION`:**
-  The tag or hash of the current commit in `THISDIR` (if `GIT` is
-    defined and `$(THISDIR)/.git` exists).
+  The value of the `VERSION` variable (if present).
 
 The following params are only available in transforms :⁠—
 
 
 The following params are only available in transforms :⁠—
 
index 0b66c4ef1812b9d0382e9b3353d8fb0b2d63a0a1..1d8ad5d8d4e925e7ed0f845070820defe0d24a9b 100644 (file)
@@ -23,9 +23,10 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
        <template match="/">
                <xslt:transform version="1.0">
                        <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
        <template match="/">
                <xslt:transform version="1.0">
                        <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
+                       <xslt:param name="GENERATOR" select="false"/>
+                       <xslt:param name="SRCREV" select="false"/>
                        <xslt:param name="SRCTIME" select="'1972-12-31T00:00:00Z'"/>
                        <xslt:param name="VERSION" select="false"/>
                        <xslt:param name="SRCTIME" select="'1972-12-31T00:00:00Z'"/>
                        <xslt:param name="VERSION" select="false"/>
-                       <xslt:param name="SRCREV" select="false"/>
                        <xslt:variable name="书社:parsers">
                                <html:dl>
                                        <for-each select="//catalog:uri">
                        <xslt:variable name="书社:parsers">
                                <html:dl>
                                        <for-each select="//catalog:uri">
index 92dcaf95cfa985fdd86d25b5bfba967406476789..40e40722e8556470b17464b5b9b84ff99d566156 100644 (file)
@@ -27,10 +27,11 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                <xslt:transform exclude-result-prefixes="catalog exsl exslstr" version="1.0">
                        <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
                        <xslt:param name="CATALOG" select="'catalog'"/>
                <xslt:transform exclude-result-prefixes="catalog exsl exslstr" version="1.0">
                        <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
                        <xslt:param name="CATALOG" select="'catalog'"/>
-                       <xslt:param name="SRCTIME" select="'1972-12-31T00:00:00Z'"/>
+                       <xslt:param name="GENERATOR" select="false"/>
                        <xslt:param name="PATH" select="'/unknown'"/>
                        <xslt:param name="PATH" select="'/unknown'"/>
-                       <xslt:param name="VERSION" select="false"/>
                        <xslt:param name="SRCREV" select="false"/>
                        <xslt:param name="SRCREV" select="false"/>
+                       <xslt:param name="SRCTIME" select="'1972-12-31T00:00:00Z'"/>
+                       <xslt:param name="VERSION" select="false"/>
                        <xslt:variable name="书社:expansion">
                                <xslt:apply-templates select="/" mode="书社:expand"/>
                        </xslt:variable>
                        <xslt:variable name="书社:expansion">
                                <xslt:apply-templates select="/" mode="书社:expand"/>
                        </xslt:variable>
@@ -154,10 +155,10 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                        </xslt:for-each>
                                                </html:title>
                                                <xslt:copy-of select="exsl:node-set($metadata)/node()[not(self::*) or not(self::html:title)]"/>
                                                        </xslt:for-each>
                                                </html:title>
                                                <xslt:copy-of select="exsl:node-set($metadata)/node()[not(self::*) or not(self::html:title)]"/>
-                                               <xslt:if test="not(exsl:node-set($metadata)/html:meta[@name='generator'])">
+                                               <xslt:if test="$GENERATOR and not(exsl:node-set($metadata)/html:meta[@name='generator'])">
                                                        <html:meta name="generator">
                                                                <xslt:attribute name="content">
                                                        <html:meta name="generator">
                                                                <xslt:attribute name="content">
-                                                                       <xslt:text>⛩️📰 书社</xslt:text>
+                                                                       <xslt:value-of select="$GENERATOR"/>
                                                                        <xslt:if test="$VERSION">
                                                                                <xslt:text> (</xslt:text>
                                                                                <xslt:value-of select="$VERSION"/>
                                                                        <xslt:if test="$VERSION">
                                                                                <xslt:text> (</xslt:text>
                                                                                <xslt:value-of select="$VERSION"/>
This page took 0.074263 seconds and 4 git commands to generate.