# ☡ This variable creates at least one subshell every time it is computed.
override diffprereqs = $(if $(subst $(shell $(CAT) $(call quote,$(BUILDDIR)/lastprereqs/$1) 2>>/dev/null || :),,$2),$2 FORCE$(and $(shell $(call ensuredirectory,$(BUILDDIR)/lastprereqs) && $(PRINTF) '%s\n' $(call quote,$2) >|$(BUILDDIR)/lastprereqs/$1),),$2)
+# (callable) Escape special characters for use in X·M·L.
+override xmlesc = $(subst >,>,$(subst <,<,$(subst &,&,$1)))
+
+# (callable) Escape special characters for use in X·M·L attributes.
+override attresc = $(subst ",",$(call xmlesc,$1))
+
# (callable) Escape special characters for use in sed regular expressions.
override sedesc = $(subst /,[/],$(subst $$,\$$,$(subst *,\*,$(subst .,\.,$(subst [,\[,$(subst ^,\^,$(subst \,\\,$1)))))))
# This ensures that file classifications are up·to·date immediately after the reload.
override typeupdates := $(if $(wildcard $(BUILDDIR)/.update-types),FORCE,)
+# Pair each source file and include with its metadata location.
+override sourcemetadatapair := $(foreach file,$(sourcefiles) $(sourceincludes),$(file)|$(BUILDDIR)/$(if $(filter $(file),$(sourceincludes)),includes.metadata/$(call includepath,$(file)),sources.metadata/$(call sourcepath,$(file))))
+
+# (callable) Get the location of the transformed X·M·L files for the given source files.
+override metadata = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(sourcemetadatapair))))
+
+# (callable) Get the source files for the given parsed file.
+override datadata = $(foreach file,$1,$(patsubst %|$(file),%,$(filter %|$(file),$(sourcemetadatapair))))
+
# Pair each source file and include with its parsed location.
override sourceparsedpair := $(foreach file,$(sourcefiles) $(sourceincludes),$(file)|$(BUILDDIR)/$(if $(filter $(file),$(sourceincludes)),includes/$(call includepath,$(file)),sources/$(call sourcepath,$(file))))
# (callable) Get the source files for the given parsed file.
override unparsed = $(foreach file,$1,$(patsubst %|$(file),%,$(filter %|$(file),$(sourceparsedpair))))
-# Pair each parser, transform, or parsed file with its file u·r·i.
-override fileuripairs := $(join $(patsubst %,%|,$(PARSERS) $(TRANSFORMS) $(call parsed,$(sourcefiles) $(sourceincludes))),$(call pathenc,$(foreach uriable,$(PARSERS) $(TRANSFORMS) $(call parsed,$(sourcefiles) $(sourceincludes)),file://$(abspath $(uriable)))))
+# Pair each parser, transform, source file, or parsed file with its file u·r·i.
+override fileuripairs := $(join $(patsubst %,%|,$(PARSERS) $(TRANSFORMS) $(sourcefiles) $(sourceincludes) $(call parsed,$(sourcefiles) $(sourceincludes))),$(call pathenc,$(foreach uriable,$(PARSERS) $(TRANSFORMS) $(sourcefiles) $(sourceincludes) $(call parsed,$(sourcefiles) $(sourceincludes)),file://$(abspath $(uriable)))))
# (callable) Get the file u·r·is for the given parsers, transforms, or parsed files.
override fileuri = $(foreach file,$1,$(or $(patsubst $(file)|%,%,$(filter $(file)|%,$(fileuripairs))),$(error Unable to get file u·r·i for `$(file)´)))
$(silent)$(XSLTPROC) --nonet --novalid -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2parser.xslt) $(call quote,$<)
$(silent)$(TOUCH) $(call quote,$(BUILDDIR)/.update-types)
+# Generate R·D·F metadata for files.
+$(call metadata,$(sourcefiles) $(sourceincludes)) : % : $$(call datadata,$$@) $(typeupdates)
+ $(call inform,$(PRINTF) '%s\n' $(call quote,Generating metadata for `$<´…) >&2)
+ $(silent)$(call ensuredirectory,$(dir $@))
+ $(silent){ if $(TEST) ! -f $(call quote,$(BUILDDIR)/.mtime); then $(PRINTF) '%b' '\n' >|$(call quote,$(BUILDDIR)/.mtime); fi; $(TOUCH) -r $(call quote,$<) $(call quote,$(BUILDDIR)/.mtime); TZ=UTC0 $(DIFF) -u $(call quote,$(BUILDDIR)/.mtime) /dev/null | $(SED) '1!d;s/.* \([^ ]*\) \([^ ]*\).*$$/\1T\2Z/'; $(CKSUM) $(call quote,$<) | $(SED) 's/[ ].*//'; } | $(xargsmultiquote) | $(XARGS) -E '' $(PRINTF) '<?xml version="1.0"?><nfo:LocalFileDataObject xmlns:dct="http://purl.org/dc/terms/" xmlns:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#" xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="%s" nfo:fileUrl="%s"><nie:interpretedAs>$(if $(filter $(source),$(assetfiles)),<nfo:InformationElement nie:mimeType="%s"/>,<nfo:PlainTextDocument nie:mimeType="%s"/>)</nie:interpretedAs><dct:hasFormat><nfo:LocalFileDataObject nfo:fileUrl="%s"><nie:interpretedAs><nfo:PlainTextDocument nie:mimeType="application/xml"/></nie:interpretedAs></nfo:LocalFileDataObject></dct:hasFormat><nfo:fileLastModified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">%s</nfo:fileLastModified><nfo:hasHash nfo:hashAlgorithm="CRC32" nfo:hashValue="%s"/></nfo:LocalFileDataObject>' $(call quote,$(call attresc,$(call localuri,$<))) $(call quote,$(call attresc,$(call fileuri,$<))) $(call quote,$(call attresc,$(call typeoffile,$<))) $(call quote,$(call attresc,$(call fileuri,$(call parsed,$<)))) >|$(call quote,$@)
+
# Parse the files.
#
# Even plain X·M·L files are parsed, because they may contain X·H·T·M·L `<script>´ elements which contain other kinds of data.
$(silent)$(call ensuredirectory,$(dir $@))
$(silent)$(if $(filter $<,$(assetfiles)),$(PRINTF) '%s\n' $(call quote,<?xml version="1.0"?><object xmlns="http://www.w3.org/1999/xhtml" type="$(call typeoffile,$<)" data="$(call datauri,$<)"/>) >|$(call quote,$@),$(if $(filter $<,$(plaintextfiles)),$(call wrapplaintext,$<),$(call serializexml,$<)) | $(XSLTPROC) --nonet --novalid -o $(call quote,$@) --stringparam BUILDTIME $$($(DATE) -u '+%Y-%m-%dT%H:%M:%SZ') --stringparam IDENTIFIER $(call quote,$(call localuri,$<)) --stringparam SRCTIME '$(call modtime,$<)' --stringparam CKSUM $$($(CKSUM) $(call quote,$<) | $(SED) 's/[ ].*//')$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/parser.xslt) -)
-# Generate a catalog of all parsed files, for use when processing includes.
-#
-# This does not depend on actually transforming the files.
-$(BUILDDIR)/catalog : $(call diffprereqs,sources,$(sort $(sourcefiles) $(sourceincludes))) $(typeupdates)
- $(call inform,$(PRINTF) '%s\n' 'Generating catalog of parsed files…' >&2)
- $(silent)$(XMLCATALOG) --create --noout $(call quote,$@)
- $(foreach source,$(sourcefiles) $(sourceincludes),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call localuri,$(source))) $(call quote,$(call fileuri,$(call parsed,$(source)))#$(if $(filter $(source),$(assetfiles)),asset,xml)) --noout $(call quote,$@)$(newline))
+# Collect the metadata into a single file.
+$(BUILDDIR)/metadata : $(call diffprereqs,metadatas,$(call metadata,$(sort $(sourcefiles) $(sourceincludes))))
+ $(call inform,$(PRINTF) '%s\n' 'Compiling metadata…' >&2)
+ $(silent){ $(PRINTF) '%s' '<?xml version="1.0"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'; $(foreach meta,$(call metadata,$(sort $(sourcefiles) $(sourceincludes))),$(CAT) $(call quote,$(meta)) | $(SED) 's/<?xml version="1.0"?>//';) $(PRINTF) '%s\n' '</rdf:RDF>'; } >|$(call quote,$@)
# Build a list of dependencies for each parsed file.
-$(BUILDDIR)/dependencies : $(BUILDDIR)/catalog $(call parsed,$(plaintextfiles) $(xmlfiles)) $(THISDIR)/lib/catalog2dependencies.xslt
+$(BUILDDIR)/dependencies : $(BUILDDIR)/metadata $(call parsed,$(filter-out $(assetfiles),$(sourcefiles) $(sourceincludes))) $(THISDIR)/lib/metadata2dependencies.xslt
$(call inform,$(PRINTF) '%s\n' 'Identifying dependencies…' >&2)
$(silent)$(TOUCH) $(call quote,$@)
- $(silent)$(XSLTPROC) --nonet --novalid -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2dependencies.xslt) $(call quote,$<)
+ $(silent)$(XSLTPROC) --nonet --novalid -o $(call quote,$@) $(call quote,$(THISDIR)/lib/metadata2dependencies.xslt) $(call quote,$<)
# Generate a catalog of destinations for files.
#
# This depends on parsing non·asset source files, but not assets or includes.
# It does not require knowing the dependencies.
-$(BUILDDIR)/destinations : $(BUILDDIR)/catalog $(call parsed,$(filter-out $(assetfiles),$(sourcefiles))) $(THISDIR)/lib/catalog2destinations.xslt
+$(BUILDDIR)/destinations : $(BUILDDIR)/metadata $(call parsed,$(filter-out $(assetfiles),$(sourcefiles))) $(THISDIR)/lib/metadata2destinations.xslt
$(call inform,$(PRINTF) '%s\n' 'Identifying output destinations…' >&2)
$(silent)$(TOUCH) $(call quote,$@)
- $(silent)$(XSLTPROC) --nonet --novalid -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2destinations.xslt) $(call quote,$<)
+ $(silent)$(XSLTPROC) --nonet --novalid -o $(call quote,$@) $(call quote,$(THISDIR)/lib/metadata2destinations.xslt) $(call quote,$<)
# Generate the main transform.
$(BUILDDIR)/transform.catalog : $(call diffprereqs,transforms,$(sort $(TRANSFORMS)))
$(silent)$(XSLTPROC) --nonet --novalid -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2transform.xslt) $(call quote,$<)
# Compile the result files using the dependencies as necessary.
-$(call compiled,$(compilablefiles)) : $(BUILDDIR)/results/% : $$(call parsed,$$(call uncompiled,$$@)) $(BUILDDIR)/transform.xslt $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@)))
+$(call compiled,$(compilablefiles)) : $(BUILDDIR)/results/% : $$(call parsed,$$(call uncompiled,$$@)) $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@))) $(BUILDDIR)/transform.xslt $(BUILDDIR)/metadata
$(call inform,$(PRINTF) '%s\n' $(call quote,Compiling </$*>…) >&2)
$(silent)$(call ensuredirectory,$(dir $@))
- $(silent)$(XSLTPROC) --nonet --novalid -o $(call quote,$@) --stringparam CATALOG 'catalog' --stringparam BUILDTIME $$($(DATE) -u '+%Y-%m-%dT%H:%M:%SZ') --stringparam SRCTIME '$(call modtime,$(call uncompiled,$@))' --stringparam IDENTIFIER $(call quote,$(call localuri,$(call uncompiled,$@))) --stringparam PATH $(call quote,/$*) --stringparam CKSUM $$($(CKSUM) $(call quote,$(call uncompiled,$@)) | $(SED) 's/[ ].*//')$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/transform.xslt) $(call quote,$<)
+ $(silent)$(XSLTPROC) --nonet --novalid -o $(call quote,$@) --stringparam METADATA 'metadata' --stringparam BUILDTIME $$($(DATE) -u '+%Y-%m-%dT%H:%M:%SZ') --stringparam SRCTIME '$(call modtime,$(call uncompiled,$@))' --stringparam IDENTIFIER $(call quote,$(call localuri,$(call uncompiled,$@))) --stringparam PATH $(call quote,/$*) --stringparam CKSUM $$($(CKSUM) $(call quote,$(call uncompiled,$@)) | $(SED) 's/[ ].*//')$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/transform.xslt) $(call quote,$<)
# Create the final files from the compiled results (or error in the case of recursive ones).
$(call built,$(compilablefiles)) : $(BUILDDIR)/public/% : $(BUILDDIR)/results/%
SPDX-License-Identifier: MPL-2.0
-->
<!--
-⁌ ⛩️📰 书社 ∷ lib/catalog2dependencies.xslt
+⁌ ⛩️📰 书社 ∷ lib/metadata2dependencies.xslt
© 2023–2024 Lady [@ Lady’s Computer].
-->
<transform
xmlns="http://www.w3.org/1999/XSL/Transform"
- xmlns:catalog="urn:oasis:names:tc:entity:xmlns:xml:catalog"
+ xmlns:dct="http://purl.org/dc/terms/"
xmlns:exsl="http://exslt.org/common"
+ xmlns:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"
+ xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
version="1.0"
>
- <variable name="uris" select="//catalog:uri"/>
+ <variable name="files" select="/rdf:RDF/nfo:LocalFileDataObject"/>
<template name="书社:process-dependencies">
<param name="processed"/>
<param name="unprocessed"/>
</variable>
<variable name="new">
<for-each select="exsl:node-set($queue)/书社:*">
- <for-each select="$uris[@name=string(current()) and substring-after(@uri, '#')!='asset']">
- <variable name="parent" select="@name"/>
- <for-each select="document(substring-before(@uri, '#'), .)//书社:link[@xlink:show='embed']">
+ <for-each select="$files[@rdf:about=string(current()) and nie:interpretedAs/nfo:PlainTextDocument and dct:hasFormat/*/nie:interpretedAs/*[@nie:mimeType='application/xml']]">
+ <variable name="parent" select="@rdf:about"/>
+ <for-each select="document(dct:hasFormat/*[nie:interpretedAs/*[@nie:mimeType='application/xml']]/@nfo:fileUrl[1])//书社:link[@xlink:show='embed']">
<if test="exsl:node-set($old)/书社:dependency-root[string()=string(current()/@xlink:href)]">
<书社:recursive-dependency>
<value-of select="$parent"/>
</书社:recursive-dependency>
</if>
- <if test="$uris/@name[string()=string(current()/@xlink:href)]">
+ <if test="$files/@rdf:about[string()=string(current()/@xlink:href)]">
<书社:dependency>
<value-of select="@xlink:href"/>
</书社:dependency>
</otherwise>
</choose>
</template>
- <template match="catalog:uri" mode="书社:dependencies">
- <if test="substring-after(@uri, '#')!='asset'">
+ <template match="nfo:LocalFileDataObject" mode="书社:dependencies">
+ <if test="nie:interpretedAs/nfo:PlainTextDocument">
<call-template name="书社:process-dependencies">
<with-param name="unprocessed">
<书社:dependency-root>
- <value-of select="@name"/>
+ <value-of select="@rdf:about"/>
</书社:dependency-root>
</with-param>
</call-template>
</if>
</template>
<template match="/">
- <for-each select="$uris[not(substring-after(@uri, '#')='asset')]">
- <variable name="parent" select="@name"/>
+ <for-each select="$files[nie:interpretedAs/nfo:PlainTextDocument]">
+ <variable name="parent" select="@rdf:about"/>
<variable name="dependencies">
<apply-templates select="." mode="书社:dependencies"/>
</variable>
- <value-of select="@name"/>
+ <value-of select="@rdf:about"/>
<text>
</text>
<for-each select="exsl:node-set($dependencies)/书社:recursive-dependency">
<text>	</text>