# Non·empty if `help´ or `clean´, and no targets other than `help´ or `clean´, were specified as goals on the commandline.
override notbuilding := $(and $(filter help clean,$(MAKECMDGOALS)),$(call not,$(filter-out help clean,$(MAKECMDGOALS))))
-# (callable) Test to see if the prerequisites provided by the second argument matches the value in the file corresponding to the first argument in `$(BUILDDIR)/lastprereqs´.
-# If not, save the new value and then add FORCE.
-# Return them regardless.
+# (callable) Tests to see if the prerequisites provided by the second argument matches the value in the file corresponding to the first argument in `$(BUILDDIR)/lastprereqs´.
+# If not, saves the new value.
+# Returns the values plus the file in `$(BUILDDIR)/lastprereqs´, which will always be newer than the target if there was a change.
#
# Calling this variable is useful when a given target should be updated whenever its list of prerequisites changes in addition to whenever there is a change to one of its prerequisites.
#
# If `$(notbuilding)´ is non·empty, this variable produces no result to avoid unnecessary work.
#
# ☡ This variable creates at least one subshell every time it is computed.
-override diffprereqs = $(if $(notbuilding),,$(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))
+override diffprereqs = $(if $(notbuilding),,$(and $(subst $(shell $(CAT) $(call quote,$(BUILDDIR)/lastprereqs/$1) 2>>/dev/null || :),,$2),$(shell $(call ensuredirectory,$(BUILDDIR)/lastprereqs) && $(PRINTF) '%s\n' $(call quote,$2) >|$(BUILDDIR)/lastprereqs/$1),)$2 $(BUILDDIR)/lastprereqs/$1)
# (callable) Escape special characters for use in X·M·L.
override xmlesc = $(subst >,>,$(subst <,<,$(subst &,&,$1)))
.PHONY : FORCE all clean gone help install list listout uninstall $(call built,$(recursivefiles)) ;
ifeq ($(notbuilding),)
-# Reload this make·file if the magic file, parser, dependencies, or destinations have changed.
+# Reload this make·file if the magic file, parser, or transform have changed.
#
# If the magic file or parser changed, then another restart will be required, as the dependencies and destinations will need to be regenerated.
-$(THISDIR)/GNUmakefile : $(BUILDDIR)/magic.mgc $(BUILDDIR)/parser.xslt $(BUILDDIR)/dependencies $(BUILDDIR)/destinations
+$(THISDIR)/GNUmakefile : $(BUILDDIR)/magic.mgc $(BUILDDIR)/parser.xslt $(BUILDDIR)/transform.xslt
$(silent)$(TOUCH) $(THISDIR)/GNUmakefile
- $(if $(filter $(BUILDDIR)/magic.mgc $(BUILDDIR)/parser.xslt,$?),$(call inform,$(PRINTF) '%b\n' '\0033[1mMagic file or parsers have updated. Restarting…\0033[22m' >&2)$(newline)$(silent)$(SLEEP) 1,$(if $(typeupdates),$(silent)$(RM) $(call quote,$(BUILDDIR)/.update-types)$(newline),)$(call inform,$(PRINTF) '%b\n' '\0033[1mDependency graph and output destinations updated. Restarting…\0033[22m' >&2))
+ $(if $(filter $(BUILDDIR)/magic.mgc $(BUILDDIR)/parser.xslt,$?),$(call inform,$(PRINTF) '%b\n' '\0033[1mMagic file or parsers have updated. Restarting…\0033[22m' >&2)$(newline)$(silent)$(SLEEP) 1,$(if $(typeupdates),$(silent)$(RM) $(call quote,$(BUILDDIR)/.update-types)$(newline),)$(call inform,$(PRINTF) '%b\n' '\0033[1mDependency graph$(comma) output destinations$(comma) or transforms updated. Restarting…\0033[22m' >&2))
endif
# ─ ¶ Build Targets ───────────────────────────────────────────────────
$(silent)$(call unlesstypeswillupdate,{ $(PRINTF) '<?xml version="1.0"?><rdf:RDF 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:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:"><书社vocab:BuildDirectory nfo:fileUrl="%s"/>' $(call quote,$(call attresc,$(call fileuri,$(BUILDDIR)))); {$(foreach meta,$(call metadata,$(sort $(sourcefiles) $(sourceincludes))), $(CAT) $(call quote,$(meta));) } | $(SED) 's/<?xml version="1.0"?>//g'; $(PRINTF) '%s\n' '</rdf:RDF>'; } | ( $(CD) $(call quote,$(BUILDDIR)); $(XSLTPROC) --nonet --novalid --nomkdir $(call quote,$(abspath $(THISDIR)/lib/expandmetadata.xslt)) - ) | $(XMLLINT) --nonet --nsclean - >|$(call quote,$(BUILDDIR)/metadata))
# Generate the main transform.
+#
+# Because this depends on the metadata, it will also update the dependencies and destinations.
$(BUILDDIR)/transform.catalog : $(call diffprereqs,transforms,$(sort $(TRANSFORMS)))
$(call inform,$(PRINTF) '%s\n' 'Generating catalog of transforms…' >&2)
$(silent)$(XMLCATALOG) --create --noout $(call quote,$@)
$(silent)$(XSLTPROC) --nonet --novalid --nomkdir --nowrite --stringparam METADATA $(call quote,$(call fileuri,$(BUILDDIR))/metadata) $(call quote,$(THISDIR)/lib/catalog2transform.xslt) $(call quote,$<) >|$(call quote,$@)
# Compile the result files using the dependencies as necessary.
-$(call compiled,$(compilablefiles)) : $(BUILDDIR)/results/% : $$(call parsed,$$(call uncompiled,$$@)) $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@))) $(BUILDDIR)/transform.xslt $(TRANSFORMLIBS) $(BUILDDIR)/metadata
+#
+# Altho this (obviously) depends on the main transform, it is not listed as a prerequisite (rather, the main transform is listed as a prerequisite for the make·file writ large). This is because the transform will update after every metadata change (i·e, basically constantly), but compiled files should only actually be updated in two cases :—
+#
+# • When one of the actual transforms are updated (tracked by `transform.catalog´), and
+# • When the metadata of ⹐source files they depend on⹑ change.
+#
+# This is to reduce the number of needless regenerations of files with no substantial change.
+$(call compiled,$(compilablefiles)) : $(BUILDDIR)/results/% : $$(call parsed,$$(call uncompiled,$$@)) $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@))) $(BUILDDIR)/transform.catalog $(TRANSFORMLIBS) $$(call metadata,$$(call dependencies,$$(call uncompiled,$$@)))
$(call inform,$(PRINTF) '%s\n' $(call quote,Compiling </$*>…) >&2)
$(silent)$(call ensuredirectory,$(dir $@))
$(silent)$(XSLTPROC) --nonet --novalid --nomkdir --nowrite --stringparam METADATA 'metadata' --stringparam BUILDTIME $$($(DATE) -u '+%Y-%m-%dT%H:%M:%SZ') --stringparam IDENTIFIER $(call quote,$(call localuri,$(call uncompiled,$@)))$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/transform.xslt) $(call quote,$<) >|$(call quote,$@)
override makefile := $(abspath $(THISDIR)/GNUmakefile)
# (overridable) Options to use when calling ⛩📰 书社 the first time.
-shushedataopts := INCLUDEDIR=$(call quote,$(DATADIR)) BUILDDIR=$(call quote,$(BUILDDIR)/stage1) DESTDIR=$(call quote,$(BUILDDIR)/data) FINDRULES=$(call quote,$(FINDRULES) -a '(' $(FINDDATARULES) ')') FINDINCLUDERULES=$(call quote,$(FINDINCLUDERULES)) MODE='urn:fdc:ladys.computer:20231231:Shu1She4:mode:default'
+shushedataopts := INCLUDEDIR=$(call quote,$(DATADIR)) BUILDDIR=$(call quote,$(BUILDDIR)/data) FINDRULES=$(subst $$,$$$$,$(call quote,$(FINDRULES) -a '(' $(FINDDATARULES) ')')) FINDINCLUDERULES=$(subst $$,$$$$,$(call quote,$(FINDINCLUDERULES))) MODE='urn:fdc:ladys.computer:20231231:Shu1She4:mode:default'
# (overridable) Options to use when calling ⛩📰 书社 the second time.
-shushesiteopts := INCLUDEDIR=$(call quote,$(INCLUDEDIR) $(BUILDDIR)/data) BUILDDIR=$(call quote,$(BUILDDIR)/stage2) FINDRULES=$(call quote,$(FINDRULES) -a '!' '(' $(FINDDATARULES) ')') FINDINCLUDERULES=$(call quote,$(FINDINCLUDERULES)) MODE='urn:fdc:ladys.computer:20231231:Shu1She4:mode:default'
+shushesiteopts := INCLUDEDIR=$(call quote,$(INCLUDEDIR) $(BUILDDIR)/data/public) BUILDDIR=$(call quote,$(BUILDDIR)/site) FINDRULES=$(subst $$,$$$$,$(call quote,$(FINDRULES) -a '!' '(' $(FINDDATARULES) ')')) FINDINCLUDERULES=$(subst $$,$$$$,$(call quote,$(FINDINCLUDERULES))) MODE='urn:fdc:ladys.computer:20231231:Shu1She4:mode:default'
# ─ ¶ Recipe Variable Definitions ─────────────────────────────────────
# Build the data and remove outdated data files.
data : $(BUILDDIR)/data.out
- @$(MAKE) -f $(call quote,$(makefile)) install $(shushedataopts)
- $(silent)$(FIND) $(call quote,$(BUILDDIR)/data) '!' -exec $(GREP) -F -q -x '{}' $(call quote,$<) ';' -a '(' -type d -o -print ')' | $(xargsmultiquote) | $(XARGS) -E '' $(RM)
+ $(silent)$(FIND) $(call quote,$(BUILDDIR)/data/public) '!' -exec $(GREP) -F -q -x '{}' $(call quote,$<) ';' -a '(' -type d -o -print ')' | $(xargsmultiquote) | $(XARGS) -E '' $(RM)
# Destroy build directory and installed files.
gone : clean uninstall ;
# Install the compiled files into `DESTDIR´.
install : all
+ @$(MAKE) -f $(call quote,$(makefile)) $@ $(shushedataopts)
@$(MAKE) -f $(call quote,$(makefile)) $@ $(shushesiteopts)
- @$(MAKE) -f $(call quote,$(makefile)) $(foreach dest,$(patsubst $(BUILDDIR)/data/%,$(DESTDIR)/%,$(shell $(CAT) $(call quote,$(BUILDDIR)/data.out))),$(call quote,$(dest)))
# List all source files and includes and their computed types.
-list listout : data
+list : data
+ @$(PRINTF) '%b' $(call quote,\0033[1;7m||Stage|1:||\0033[22;27m\0033[4m||||||||||||||||||||\0033[24m ) | $(TR) ' |' '\n '
+ @$(MAKE) -f $(call quote,$(makefile)) $@ $(shushedataopts)
+ @$(PRINTF) '%b' $(call quote, \0033[1;7m||Stage|2:||\0033[22;27m\0033[4m||||||||||||||||||||\0033[24m ) | $(TR) ' |' '\n '
@$(MAKE) -f $(call quote,$(makefile)) $@ $(shushesiteopts)
+listout : data
+ @{ $(MAKE) -f $(call quote,$(makefile)) $@ $(shushedataopts); $(MAKE) -f $(call quote,$(makefile)) $@ $(shushesiteopts); } | $(SED) '$$!s/$$/ /' | $(TR) -d '\n'
+list1 listout1 : %1 :
+ @$(MAKE) -f $(call quote,$(makefile)) $* $(shushedataopts)
+list2 listout2 : %2 : data
+ @$(MAKE) -f $(call quote,$(makefile)) $* $(shushesiteopts)
# Destroy installed files.
uninstall :
$(BUILDDIR)/data.out : FORCE
@$(MAKE) -f $(call quote,$(makefile)) $(shushedataopts)
- @$(MAKE) -s -f $(call quote,$(makefile)) listout QUIET=1 $(shushedataopts) | $(TR) ' ' '\n' | $(xargsmultiquote) | $(XARGS) -E '' $(PRINTF) $(call quote,$(BUILDDIR)/data/%s\n) >$(call quote,$(BUILDDIR)/data.out)
-
-$(BUILDDIR)/stage1/% : FORCE
- @$(MAKE) -f $(call quote,$(makefile)) $@ $(shushedataopts)
+ @$(MAKE) -s -f $(call quote,$(makefile)) listout QUIET=1 $(shushedataopts) | $(TR) ' ' '\n' | $(xargsmultiquote) | $(XARGS) -E '' $(PRINTF) $(call quote,$(BUILDDIR)/data/public/%s\n) >$(call quote,$(BUILDDIR)/data.out)
$(BUILDDIR)/data/% : FORCE
@$(MAKE) -f $(call quote,$(makefile)) $@ $(shushedataopts)
-$(BUILDDIR)/stage2/% : data
+$(BUILDDIR)/site/% : data
@$(MAKE) -f $(call quote,$(makefile)) $@ $(shushesiteopts)
$(DESTDIR)/% : data
- $(if $(shell $(GREP) -F -x $(call quote,$(BUILDDIR)/data/$*) $(BUILDDIR)/data.out),$(call inform $(PRINTF) '%s\n' $(call quote,Copying over </$*>…) >&2)$(newline),$(CP) $(call quote,$(BUILDDIR)/data/$*) $(call quote,$@),@$(MAKE) -f $(call quote,$(makefile)) $@ $(shushesiteopts))
+ @$(MAKE) -f $(call quote,$(makefile)) $@ $(if $(shell $(GREP) -F -x $(call quote,$(BUILDDIR)/data/$*) $(BUILDDIR)/data.out),$(shushedataopts),$(shushesiteopts))
# ━ § END DEFINED MAKE·FILE MODES ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━