From: Lady Date: Sat, 22 Jun 2024 20:06:53 +0000 (-0400) Subject: “Simplify” the restart mechanism using $? X-Git-Tag: 0.11.1~1 X-Git-Url: https://git.ladys.computer/Shushe/commitdiff_plain/bc83928663f56508f210ce19a607aa9a52f32983?ds=sidebyside “Simplify” the restart mechanism using $? Instead of having two GNUmakefile rules which are present under different conditions (and which could hypothetically both apply), just have one and check to see which prerequisites are out·of·date in order to adjust the behaviour. In order to prevent unnecessary builds of metadata and parsed files prior to a type update, wrap the recipes in a check to see if `$(BUILDDIR)/.update-types` was created over the course of the build. This needs to happen in the shell, not in Make, because older versions of Make cache the `$(wildcard)` function. The implementation of `$(unlesstypeswillupdate)` uses an `if` function instead of a `and` because the latter seems to trim white·space. It is no longer an error if the type of a file cannot be determined; this is required to enable recipe expansion when types are not yet generated now that the test is happening in the shell. Instead, files are given a default type of `application/octet-stream`. --- diff --git a/GNUmakefile b/GNUmakefile index a41fb96..78f9a41 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -269,6 +269,9 @@ override space := $(empty) $(empty) # A variable which contains a single comma. override comma := , +# (callable) Make empty strings non·empty, and non·empty strings empty. +override not = $(if $1,,1) + # (callable) Quote the given string for use within shell calls. override quote = '$(subst ','"'"',$1)' @@ -379,7 +382,7 @@ override plaintextfiles := $(filter-out $(xmlfiles),$(call filesoftype,$(plainte override assetfiles := $(filter-out $(xmlfiles) $(plaintextfiles),$(sourcefiles) $(sourceincludes)) # (callable) Get the types of the given files. -override typeoffile = $(foreach file,$1,$(or $(patsubst $(file)|%,%,$(filter $(file)|%,$(types))),$(error Unable to get type of file `$(file)´))) +override typeoffile = $(foreach file,$1,$(or $(patsubst $(file)|%,%,$(filter $(file)|%,$(types))),application/octet-stream)) # Pair each source magic file with its location in the build directory. override magicpair := $(foreach magicfile,$(MAGIC),$(magicfile)|$(BUILDDIR)/magic/$(call namehash,$(magicfile))) @@ -414,7 +417,7 @@ override sourcefile = $(foreach local,$1,$(patsubst %|$(local),%,$(filter %|$(lo # # This file is created before a reload due to type changes, and is removed after. # This ensures that file classifications are up·to·date immediately after the reload. -override typeupdates := $(if $(wildcard $(BUILDDIR)/.update-types),FORCE,) +override typeupdates := $(and $(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)))) @@ -519,6 +522,9 @@ override wrapplaintext = { $(PRINTF) '%s\n%s' '' '