From: Lady Date: Thu, 11 Jul 2024 01:45:26 +0000 (-0400) Subject: Give magic file symlinks unique names X-Git-Tag: 0.9.6^0 X-Git-Url: https://git.ladys.computer/Shushe/commitdiff_plain/3a299f48959110fd4f621d75378129d96e4ad631 Give magic file symlinks unique names Rather than deal with the potential for conflicts in the names of magic files from different sources, give each file a unique name by taking the `cksum` of its absolute path. --- diff --git a/GNUmakefile b/GNUmakefile index 5237a2d..f5b738a 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -343,6 +343,11 @@ override perenc = $(shell $(PRINTF) '%s\n' $(foreach unencoded,$1,$(call quote,$ # ☡ This variable creates a subshell every time it is computed. override pathenc = $(subst %2F,/,$(call perenc,$1)) +# (callable) Create a unique name for the given file, based on its absolute path. +# +# ☡ This variable creates a subshell every time it is computed. +namehash = $(shell $(PRINTF) '%s' $(call quote,$(abspath $1)) | $(CKSUM) | $(SED) 's/ .*//' | $(XARGS) -E '' $(PRINTF) '%X')-$(notdir $1) + # (overridable) Collect all of the applicable includes from the includes directory. sourceincludes := $(if $(and $(INCLUDEDIR),$(wildcard $(INCLUDEDIR))),$(patsubst ./%,%,$(shell $(FIND) $(foreach dir,$(INCLUDEDIR),$(call quote,$(dir))) '(' $(FINDINCLUDERULES) ')' -a -type f -a -print)),) @@ -373,7 +378,7 @@ override assetfiles := $(filter-out $(xmlfiles) $(plaintextfiles),$(sourcefiles) override typeoffile = $(foreach file,$1,$(or $(patsubst $(file)|%,%,$(filter $(file)|%,$(types))),$(error Unable to get type of file `$(file)´))) # Pair each source magic file with its location in the build directory. -override magicpair := $(foreach magicfile,$(MAGIC),$(magicfile)|$(BUILDDIR)/magic/$(notdir $(magicfile))) +override magicpair := $(foreach magicfile,$(MAGIC),$(magicfile)|$(BUILDDIR)/magic/$(call namehash,$(magicfile))) # (callable) Get the source file for the given magic files. override magicsource = $(foreach magicpath,$1,$(patsubst %|$(magicpath),%,$(firstword $(filter %|$(magicpath),$(magicpair)))))