X-Git-Url: https://git.ladys.computer/Shushe/blobdiff_plain/e4f65cee884c40d631209b5cbb711de161a2969a..76093b7b94e9c1de606e9f42a1f2897f70a114e9:/GNUmakefile?ds=sidebyside diff --git a/GNUmakefile b/GNUmakefile index fe0cbd5..9ae7a92 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -16,13 +16,17 @@ override define makefileinfo ║│ │║ ║│ • cat │║ ║│ • cp │║ +║│ • date │║ ║│ • echo │║ ║│ • file │║ ║│ • find │║ ║│ • mkdir (requires support for `-p´) │║ ║│ • mv │║ ║│ • printf │║ +║│ • rm │║ ║│ • sed │║ +║│ • sleep │║ +║│ • stat │║ ║│ • test │║ ║│ • touch │║ ║│ • tr (requires support for `-d´) │║ @@ -57,7 +61,10 @@ override define makefileinfo ║│ See `README.markdown´ for a more involved description of │║ ║│ the capabilities and configuration of this program. │║ ║╰────────────────────────────────────────────────────────────╯║ -╟┬ ¶ License ─────────────────────────────────────────────────┬╢ +╟┬ ¶ Copyright & License ─────────────────────────────────────┬╢ +║│ │║ +║│ Copyright © 2023–2024 Lady [@ Lady’s Computer]. │║ +║│ │║ ║│ This Source Code Form is subject to the terms of the │║ ║│ Mozilla Public License, v 2.0. If a copy of the M·P·L was │║ ║│ not distributed with this file, You can obtain one at │║ @@ -74,6 +81,7 @@ endef # different implementation, you can override the appropriate variable. CAT := cat CP := cp +DATE := date ECHO := echo FILE := file FIND := find @@ -82,6 +90,8 @@ MV := mv PRINTF := printf RM := rm SED := sed +SLEEP := sleep +STAT := stat TEST := test TOUCH := touch TR := tr @@ -183,7 +193,7 @@ override silent := $(if $(VERBOSE),,@) # (callable) Escape special characters for use in sed regular # expressions. -override sedesc = $(subst $$,\$$,$(subst *,\*,$(subst .,\.,$(subst [,\[,$(subst ^,\^,$(subst \,\\,$1)))))) +override sedesc = $(subst /,[/],$(subst $$,\$$,$(subst *,\*,$(subst .,\.,$(subst [,\[,$(subst ^,\^,$(subst \,\\,$1))))))) # Collect all of the applicable includes from the includes directory. sourceincludes := $(shell $(FIND) $(FINDOPTS) $(INCLUDEDIR) -type f '(' $(FINDRULES) ')') @@ -218,6 +228,9 @@ override assetfiles := $(filter-out $(xmlfiles) $(plaintextfiles),$(sourcefiles) # (callable) Get the types of the given files. override typeoffile = $(patsubst $(foreach file,$1,$(file)?type=%),%,$(filter $(foreach file,$1,$(file)?type=%),$(types))) +# (callable) Get the identifier for the given transform. +override id = $(or $(shell $(XMLLINT) --xpath '/*/*[local-name()="id" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"]/text()[1]' $1),$(basename $(notdir $1)) | $(SED)) + # (callable) Get base64 data u·r·i’s for the given files. override datauri = $(foreach file,$1,data:$(call typeoffile,$(file));base64,$(shell $(UUENCODE) -m -r $(call quote,$(file)) _ | tr -d ' \n')) @@ -233,7 +246,7 @@ override sourcefile = $(foreach file,$1,$(if $(filter about:shushe?include=%,$(f # This file is created after a reload due to type changes, and is # removed after. Requiring it ensures that file classifications are # up‐to‐date immediately after the reload. -override typeupdates := $(if $(wildcard $(BUILDDIR)/.update-types),$(BUILDDIR)/.update-types,) +override typeupdates := $(wildcard $(BUILDDIR)/.update-types) # (callable) Get the location of the transformed X·M·L files for the # given source files. @@ -289,7 +302,7 @@ help: $(silent)$(PRINTF) '%b' '$(subst $(newline),\n,$(makefileinfo))' # Compile all files, or error if any are recursive. -all: $(call compiled,$(recursivefiles) $(compilablefiles) $(assetfiles)) ; +all: $(call compiled,$(recursivefiles) $(compilablefiles) $(filter $(sourcefiles),$(assetfiles))) ; # Destroy buildfiles. clean: @@ -300,7 +313,7 @@ gone: $(silent)$(RM) -rf $(BUILDDIR)/ $(call compiled,$(recursivefiles) $(compilablefiles)) # Install the compiled files into `DESTDIR´. -install: $(call installed,$(recursivefiles) $(compilablefiles) $(assetfiles)) ; +install: $(call installed,$(recursivefiles) $(compilablefiles) $(filter $(sourcefiles),$(assetfiles))) ; # List all source files and includes and their computed types. list: @@ -323,17 +336,6 @@ $(call compiled,$(recursivefiles)): $(BUILDDIR)/public/%: # Phony rules; always consider these out‐of‐date. .PHONY: all default clean gone info install list $(call compiled,$(recursivefiles)); -# Reload this make·file if any of the magic files or parsers have -# changed. -# -# These are used to classify source files, so if they have changed then -# the make·file must be reloaded. -$(THISDIR)/GNUmakefile:: $(BUILDDIR)/magic.mgc $(BUILDDIR)/parser.xslt $(THISDIR)/lib/parser2types.xslt - $(silent)$(TOUCH) $(THISDIR)/GNUmakefile - $(silent)$(TOUCH) $(call quote,$(BUILDDIR)/.update-types) - $(silent)$(RM) -f $(call quote,$(BUILDDIR)/dependencies) - @$(PRINTF) '%b\n' '\0033[1mMagic file or parsers have updated. Restarting…\0033[22m' - ifneq ($(wildcard $(BUILDDIR)/.update-types)$(wildcard $(BUILDDIR)/dependencies),) # Reload this make·file if the dependency graph has changed. # @@ -349,6 +351,23 @@ $(THISDIR)/GNUmakefile:: $(BUILDDIR)/dependencies @$(PRINTF) '%b\n' '\0033[1mDependency graph updated. Restarting…\0033[22m' endif +ifeq ($(wildcard $(BUILDDIR)/.update-types),) +# Reload this make·file if any of the magic files or parsers have +# changed. +# +# These are used to classify source files, so if they have changed then +# the make·file must be reloaded. +# +# This recipe sleeps for one second to ensure that files built after +# the restart have a more current time·stamp. +$(THISDIR)/GNUmakefile:: $(BUILDDIR)/magic.mgc $(BUILDDIR)/parser.xslt $(THISDIR)/lib/parser2types.xslt + $(silent)$(TOUCH) $(THISDIR)/GNUmakefile + $(silent)$(RM) -f $(call quote,$(BUILDDIR)/dependencies) + @$(PRINTF) '%b\n' '\0033[1mMagic file or parsers have updated. Restarting…\0033[22m' + $(silent)$(SLEEP) 1 + $(silent)$(TOUCH) $(call quote,$(BUILDDIR)/.update-types) +endif + # ─ ¶ Build Targets ─────────────────────────────────────────────────── # Generate the compiled magic file from its sources. @@ -359,24 +378,17 @@ endif $(BUILDDIR)/magic.mgc: $(wildcard $(MAGICDIR)/*) @$(ECHO) "Compiling new magic…" $(silent)$(call ensuredirectory,$(dir $@)) - $(silent)$(FILE) -C -m $(call quote,$(MAGICDIR)) - $(silent)$(MV) $(call quote,$(MAGICDIR).mgc) $(call quote,$(BUILDDIR)/magic.mgc) + $(silent)cd $(call quote,$(BUILDDIR)) && $(FILE) -C -m $(call quote,$(realpath $(MAGICDIR))) # Generate the main parser. $(BUILDDIR)/parser.catalog: $(PARSERS) @$(ECHO) "Generating catalog of parsers…" $(silent)$(XMLCATALOG) --create --noout $(call quote,$@) - $(foreach parser,$(PARSERS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(basename $(notdir $(parser)))) $(call quote,../$(parser)) --noout $(call quote,$@)$(newline)) + $(foreach parser,$(PARSERS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call id,$(parser))) $(call quote,../$(parser)) --noout $(call quote,$@)$(newline)) $(BUILDDIR)/parser.xslt: $(BUILDDIR)/parser.catalog $(THISDIR)/lib/catalog2parser.xslt @$(ECHO) "Generating main parser…" $(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2parser.xslt) $(call quote,$<) -# Note updates to parsers or magic. -# -# This file is actually generated as part of the make·file restart -# process, so it doesn’t need any recipes. -$(BUILDDIR)/.update-types: $(BUILDDIR)/magic.mgc $(BUILDDIR)/parser.xslt $(THISDIR)/lib/parser2types.xslt ; - # Parse the files. # # Even plain X·M·L files are parsed, because they may contain X·H·T·M·L @@ -399,20 +411,15 @@ $(BUILDDIR)/catalog: $(sourcefiles) $(sourceincludes) $(typeupdates) $(foreach source,$(sourcefiles) $(sourceincludes),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call localuri,$(source))) $(call quote,$(patsubst $(BUILDDIR)/%,%,$(call parsed,$(source)))#$(if $(filter $(source),$(assetfiles)),asset,xml)) --noout $(call quote,$@)$(newline)) # Build a list of dependencies for each transformed file. -# -# This recipe also adjusts backwards the modification time of this -# make·file by one second, to ensure that it is always more outdated -# than the built dependencies (triggering a restart). $(BUILDDIR)/dependencies: $(BUILDDIR)/catalog $(call parsed,$(plaintextfiles) $(xmlfiles)) $(THISDIR)/lib/catalog2dependencies.xslt @$(ECHO) "Identifying dependencies…" $(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2dependencies.xslt) $(call quote,$<) - $(silent)$(TOUCH) -A -000001 -am $(THISDIR)/GNUmakefile # Generate the main transform. $(BUILDDIR)/transform.catalog: $(TRANSFORMS) @$(ECHO) "Generating catalog of transforms…" $(silent)$(XMLCATALOG) --create --noout $(call quote,$@) - $(foreach transform,$(TRANSFORMS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(basename $(notdir $(transform)))) $(call quote,../$(transform)) --noout $(call quote,$@)$(newline)) + $(foreach transform,$(TRANSFORMS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call id,$(transform))) $(call quote,../$(transform)) --noout $(call quote,$@)$(newline)) $(BUILDDIR)/transform.xslt: $(BUILDDIR)/transform.catalog $(THISDIR)/lib/catalog2transform.xslt @$(ECHO) "Generating main transform…" $(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2transform.xslt) $(call quote,$<) @@ -421,7 +428,7 @@ $(BUILDDIR)/transform.xslt: $(BUILDDIR)/transform.catalog $(THISDIR)/lib/catalog $(call compiled,$(compilablefiles)): $(BUILDDIR)/public/%: $$(call parsed,$(SRCDIR)/%) $(BUILDDIR)/transform.xslt $$(call parsed,$$(call dependencies,$(SRCDIR)/%)) $(silent)$(call ensuredirectory,$(dir $@)) @$(PRINTF) '%s\n' $(call quote,Compiling `$*´…) - $(silent)$(XSLTPROC) -o $(call quote,$@) --stringparam catalog 'catalog' $(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,$(SRCDIR)/$*))' --stringparam path $(call quote,/$*) $(call quote,$(BUILDDIR)/transform.xslt) $(call quote,$<) $(call compiled,$(filter $(assetfiles),$(sourcefiles))): $(BUILDDIR)/public/%: $(SRCDIR)/% @$(PRINTF) '%s\n' $(call quote,Compiling `$*´…) $(silent)$(call ensuredirectory,$(dir $@))