║│ • touch │║
║│ • tr (requires support for `-d´) │║
║│ • uuencode (requires support for `-m´ and `-r´) │║
+║│ • uudecode (requires support for `-m´ and `-r´) │║
║│ • xargs (requires support for `-0´) │║
║│ • xmlcatalog (provided by libxml2) │║
║│ • xmllint (provided by libxml2) │║
TEST := test
TOUCH := touch
TR := tr
+UUDECODE := uudecode
UUENCODE := uuencode
XARGS := xargs
XMLCATALOG := xmlcatalog
override destination = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(sourcedestinationpair))))
# Pair each source file with its compiled location.
-override sourcecompiledpair := $(foreach file,$(sourcefiles),$(file)|$(BUILDDIR)/public/$(call destination,$(file)))
+override sourcecompiledpair := $(foreach file,$(sourcefiles),$(file)|$(BUILDDIR)/results/$(call destination,$(file)))
# (callable) Get the location of the transformed X·M·L files for the given source files.
override compiled = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(sourcecompiledpair))))
# (callable) Get the source files for the given compiled file.
override uncompiled = $(foreach file,$1,$(patsubst %|$(file),%,$(filter %|$(file),$(sourcecompiledpair))))
+# (callable) Get the location of the final built file for the given source files.
+override built = $(foreach file,$1,$(patsubst $(BUILDDIR)/results/%,$(BUILDDIR)/public/%,$(call compiled,$(file))))
+
# (callable) Get the installed locations for the given source files.
override installed = $(foreach file,$1,$(DESTDIR)/$(call destination,$(file)))
endif
# This isn’t a perfect substitution (it makes some assumptions about the format of the underlying X·M·L), but it should be workable for most sensible, welformed files.
override serializexml = $(SED) "$$($(PRINTF) '%b' '/<?xml[ \t]\\{1,\\}version=[\0042\0047]1.1/,$${ s/<?xml[^>]*?>/<!--<?xml version=\00421.1\0042?>-->/\n s/&\0043x0*[1-8BCEFbcef];/\0302\0221/g\n s/&\0043x0*1[0-9A-Fa-f];/\0302\0221/g\n s/&\00430*[1-8];/\0302\0221/g\n s/&\00430*1[124-9];/\0302\0221/g\n s/&\00430*2[0-9];/\0302\0221/g\n s/&\00430*3[01];/\0302\0221/g\n}')" < $(call quote,$1) | $(SED) "$$(PRINTF '%b' ':a\n/^\\n*$$/{ $$d\n N\n ba\n}')"
+# (callable) Test if the provided xpath expression matches the provided document.
+override xpath = $(XMLLINT) --xpath $(call quote,$1) $(call quote,$2) > /dev/null 2> /dev/null
+
+# (callable) Extract the value of the text nodes in the provided X·M·L document and print them to `stdout´.
+override extracttext = $(PRINTF) '%s' '<transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0"><output method="text" encoding="UTF-8"/></transform>' | $(XSLTPROC) - $(call quote,$1)
+
# ─ ¶ Phony Targets ───────────────────────────────────────────────────
# Compile all files, or error if any are recursive.
-all : $(call compiled,$(recursivefiles) $(compilablefiles)) ;
+all : $(call built,$(recursivefiles) $(compilablefiles)) ;
# Destroy buildfiles.
clean :
@$(ECHO) "Generating main transform…"
$(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2transform.xslt) $(call quote,$<)
-# Generate the output files using the dependencies as necessary.
-$(call compiled,$(compilablefiles)) : $(BUILDDIR)/public/% : $$(call parsed,$$(call uncompiled,$$@)) $(BUILDDIR)/transform.xslt $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@)))
- $(silent)$(call ensuredirectory,$(dir $@))
+# 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,$$@)))
@$(PRINTF) '%s\n' $(call quote,Compiling </$*>…)
+ $(silent)$(call ensuredirectory,$(dir $@))
$(silent)$(XSLTPROC) -o $(call quote,$@) --stringparam CATALOG 'catalog' --stringparam BUILDTIME $$(TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ') --stringparam SRCTIME $$(TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$(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,$<)
-$(call compiled,$(filter $(assetfiles),$(sourcefiles))) : $(BUILDDIR)/public/% : $$(call uncompiled,$$@)
+$(call compiled,$(filter $(assetfiles),$(sourcefiles))) : $(BUILDDIR)/results/% : $$(call uncompiled,$$@)
@$(PRINTF) '%s\n' $(call quote,Compiling </$*>…)
$(silent)$(call ensuredirectory,$(dir $@))
$(silent)$(CP) $(call quote,$<) $(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/%
+ @$(PRINTF) '%s\n' $(call quote,Building </$*>…)
+ $(silent)$(call ensuredirectory,$(dir $@))
+ $(silent)if $(call xpath,/*[local-name()="raw-text" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"],$<); then $(RM) -f $(call quote,$@); $(call extracttext,$<) > $(call quote,$@); elif $(call xpath,/*[local-name()="base64-binary" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"],$<); then $(RM) -f $(call quote,$@); $(call extracttext,$<) | $(TR) -d '\t\n\f\r ' | $(UUDECODE) -m -r > $(call quote,$@); else $(LN) -s -f $(call quote,$(subst $(space),,$(foreach component,$(subst /, ,$*),../))results/$*) $(call quote,$@); fi
+$(call built,$(filter $(assetfiles),$(sourcefiles)) $(recursivefiles)) : $(BUILDDIR)/public/% : $(BUILDDIR)/results/%
+ @$(PRINTF) '%s\n' $(call quote,Building </$*>…)
+ $(silent)$(call ensuredirectory,$(dir $@))
+ $(silent)$(LN) -s -f $(call quote,../results/$*) $(call quote,$@)
+
# Install compiled files (or error in the case of recursive ones).
$(call installed,$(filter $(assetfiles),$(sourcefiles)) $(recursivefiles) $(compilablefiles)) : $(DESTDIR)/% : $(BUILDDIR)/public/%
@$(PRINTF) '%s\n' $(call quote,Installing </$*>…)
5. ⛩️📰 书社 uses the dependency tree to establish prerequisites for
each output file.
-6. ⛩️📰 书社 compiles each output file to `build/public`.
+6. ⛩️📰 书社 compiles each output file to `build/result`.
-7. ⛩️📰 书社 copies the output files to `public`.
+7. ⛩️📰 书社 symlinks most output files from `build/result` to
+ `build/public`, but it does some additional processing instead on
+ those which indicate a non‐X·M·L desired final output form.
+
+8. ⛩️📰 书社 copies the final resulting files to `public`.
You can use `make list` to list each identified source file or include
alongside its computed type and dependencies.
- `touch`
- `tr` (requires support for `-d`)
- `uuencode` (requires support for `-m` and `-r`)
+- `uudecode` (requires support for `-m` and `-r`)
- `xargs` (requires support for `-0`)
- `xmlcatalog` (provided by `libxml2`)
- `xmllint` (provided by `libxml2`)
Output wrapping can be entirely disabled by adding a
`@书社:disable-output-wrapping` attribute to the top‐level element in
the result tree.
-This attribute will also prevent wrapping non‐H·T·M·L embeds with an
- `<html:div>`.
+It will not be performed on outputs whose root elements are
+ `<书社:raw-text>` or `<书社:base64-binary>` (described below).
## Applying Attributes
On H·T·M·L and S·V·G elements, `@lang` has the same behaviour as
`@xml:lang`.
+## Other Kinds of Output
+
+There are a few special elements in the `书社:` namespace which, if
+ they appear as the toplevel element in a transformation result, cause
+ ⛩️📰 书社 to produce something other than an X·M·L file.
+They are :—
+
+- **`<书社:raw-text>`:**
+ A plaintext (U·T·F‐8) file will be produced from the text nodes in
+ the transformation result.
+
+- **`<书社:base64-binary>`:**
+ The text nodes in the transformation result will, after removing all
+ Ascii whitespace, be treated as a Base·64 string, which is then
+ decoded.
+
## License
This repository conforms to [REUSE][].