X-Git-Url: https://git.ladys.computer/Shushe/blobdiff_plain/d4281613317ae20f8d443ec17b2f0ed5fd62581b..2a4b2ff1cb88305fb662deda701ee23afbf56498:/GNUmakefile diff --git a/GNUmakefile b/GNUmakefile index a784f21..5f55e1a 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -214,6 +214,15 @@ override quote = '$(subst ','"'"',$1)' # Outputs an `@´ to silence rules, unless `VERBOSE´ is nonempty. override silent := $(if $(VERBOSE),,@) +# (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. +# +# 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. +# +# ☡ 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 || true),,$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 sed regular expressions. override sedesc = $(subst /,[/],$(subst $$,\$$,$(subst *,\*,$(subst .,\.,$(subst [,\[,$(subst ^,\^,$(subst \,\\,$1))))))) @@ -411,6 +420,9 @@ uninstall : $(call compiled,$(recursivefiles)) : @$(PRINTF) '%b\n' $(call quote,\0033[93;41mError:\0033[39;49m `$(call uncompiled,$@)´ has recursive dependencies:\n$(subst |, ,$(subst $(space),$(newline),$(foreach recursive,$(call recursives,$(call uncompiled,$@)),•|$(recursive))))) && false +# Add as a prerequisite to treat the target as tho it were phony. +FORCE : ; + # ─ ¶ Special Targets ───────────────────────────────────────────────── # Perform secondary expansion; this enables pattern rules to determine their prerequisites based on the matched pattern. @@ -420,7 +432,7 @@ $(call compiled,$(recursivefiles)) : .SUFFIXES : ; # Phony rules; always consider these out·of·date. -.PHONY : all default clean gone info install list uninstall $(call compiled,$(recursivefiles)) ; +.PHONY : FORCE all default clean gone info install list uninstall $(call compiled,$(recursivefiles)) ; ifneq ($(typeupdates)$(wildcard $(BUILDDIR)/dependencies)$(wildcard $(BUILDDIR)/destinations),) # Reload this make·file if the dependency graph or output destinations have changed. @@ -464,8 +476,7 @@ $(call magicfile,$(MAGIC)) : $(BUILDDIR)/magic/% : $$(call magicsource,$$@) # Generate the compiled magic file from its sources. # # It must be updated if any of the files in the magic directory change. -# It ⁜also⁜ should be updated if any of the files in the magic directory are deleted, but this isn’t tracked presently. -$(BUILDDIR)/magic.mgc : $(call magicfile,$(MAGIC)) +$(BUILDDIR)/magic.mgc : $(call diffprereqs,magic,$(sort $(call magicfile,$(MAGIC)))) $(foreach outdated,$(filter-out $^,$(wildcard $(BUILDDIR)/magic/*)),$(silent)$(RM) $(call quote,$(outdated))$(newline)) @$(ECHO) "Compiling new magic…" $(silent)$(call ensuredirectory,$(dir $@)) @@ -473,7 +484,7 @@ $(BUILDDIR)/magic.mgc : $(call magicfile,$(MAGIC)) $(silent)$(TOUCH) $(call quote,$(BUILDDIR)/.update-types) # Generate the main parser. -$(BUILDDIR)/parser.catalog : $(PARSERS) +$(BUILDDIR)/parser.catalog : $(call diffprereqs,parsers,$(sort $(PARSERS))) @$(ECHO) "Generating catalog of parsers…" $(silent)$(XMLCATALOG) --create --noout $(call quote,$@) $(foreach parser,$(PARSERS),$(silent)( $(call id,$(parser)) ) | $(XARGS) -I %% $(XMLCATALOG) --add uri %% $(call quote,$(call fileuri,$(parser))) --noout $(call quote,$@)$(newline)) @@ -494,7 +505,7 @@ $(call parsed,$(sourcefiles) $(sourceincludes)) : % : $$(call unparsed,$$@) $(BU # Generate a catalog of all parsed files, for use when processing includes. # # This does not depend on actually transforming the files. -$(BUILDDIR)/catalog : $(sourcefiles) $(sourceincludes) $(typeupdates) +$(BUILDDIR)/catalog : $(call diffprereqs,sources,$(sort $(sourcefiles) $(sourceincludes))) $(typeupdates) @$(ECHO) "Generating catalog of parsed files…" $(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)) @@ -513,7 +524,7 @@ $(BUILDDIR)/destinations : $(BUILDDIR)/catalog $(call parsed,$(filter-out $(asse $(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2destinations.xslt) $(call quote,$<) # Generate the main transform. -$(BUILDDIR)/transform.catalog : $(TRANSFORMS) +$(BUILDDIR)/transform.catalog : $(call diffprereqs,transforms,$(sort $(TRANSFORMS))) @$(ECHO) "Generating catalog of transforms…" $(silent)$(XMLCATALOG) --create --noout $(call quote,$@) $(foreach transform,$(TRANSFORMS),$(silent)( $(call id,$(transform)) ) | $(XARGS) -I %% $(XMLCATALOG) --add uri %% $(call quote,$(call fileuri,$(transform))) --noout $(call quote,$@)$(newline))