X-Git-Url: https://git.ladys.computer/Shushe/blobdiff_plain/63533c3d25fa8837f0d99f8984405320d8c758a6..56637a1e803cab7a53a1259d1fa4b84513a1c5b1:/GNUmakefile diff --git a/GNUmakefile b/GNUmakefile index 93a8a13..2de20b2 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -146,9 +146,8 @@ MAGICDIR := $(patsubst ./%,%,$(THISDIR)/magic) # Configuration of `find´. # -# By default, `find´ will not follow symlinks and will use extended -# regular expressions, ignoring hidden files and those which begin with -# a period. +# By default, `find´ will ignore hidden files, those which begin with a +# period, and those which are likely to cause problems for `make´. FINDRULES := -flags -nohidden -and ! '(' '(' -name '[.-]*' -or -name '*[:|$$%]*' ')' -and -prune ')' FINDINCLUDERULES := $(FINDRULES) @@ -208,7 +207,7 @@ override silent := $(if $(VERBOSE),,@) override sedesc = $(subst /,[/],$(subst $$,\$$,$(subst *,\*,$(subst .,\.,$(subst [,\[,$(subst ^,\^,$(subst \,\\,$1))))))) # (callable) Percent‐decode the given strings. -override perdec = $(foreach encoded,$1,$(shell $(PRINTF) '%s\n' $(call quote,$(encoded)) | $(SED) 's/|/|%7C|/g;s/[\]/|%5C|/g;s/%[0-9A-Fa-f]\{2\}/|&|/g' | $(TR) '|' '\n' | $(SED) '/^%[0-9A-Fa-f]\{2\}$$/!s/%/|%25|/' | $(TR) '|' '\n' | $(AWK) '$$0!~/%/{printf("%s",$$0)}/%/{sub("%","0x");printf("\\%04o",$$0)}' | $(XARGS) -0 $(PRINTF) '%b')) +override perdec = $(foreach encoded,$1,$(shell $(PRINTF) '%s\n' $(call quote,$(encoded)) | $(SED) 's/|/%7C/g;s/[\]/%5C/g;s/%[0-9A-Fa-f]\{2\}/|&|/g' | $(TR) '|' '\n' | $(SED) '/^%[0-9A-Fa-f]\{2\}$$/!s/%/|%25|/' | $(TR) '|' '\n' | $(AWK) '$$0!~/%/{printf("%s",$$0)}/%/{sub("%","0x");printf("\\%04o",$$0)}' | $(XARGS) -0 $(PRINTF) '%b')) # (callable) Percent‐encode the given strings. # @@ -318,8 +317,18 @@ override recursivefiles := $(foreach file,$(filter-out $(assetfiles),$(sourcefil # This is all of the non·asset, nonrecursive files. override compilablefiles := $(filter-out $(assetfiles) $(recursivefiles),$(sourcefiles)) +ifneq ($(wildcard $(BUILDDIR)/destinations),) +# Get the output of the destination transform. +override destinations := $(shell $(CAT) $(BUILDDIR)/destinations) + +# Pair source files and their destinations. +override sourcedestinationpair := $(foreach destination,$(destinations),$(call sourcefile,$(firstword $(subst |, ,$(destination))))|$(call perdec,$(subst $(space),|,$(wordlist 2,$(words $(subst |, ,$(destination))),$(subst |, ,$(destination)))))) + +# (callable) Get the destination for the given source files. +override destination = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(sourcedestinationpair)))) + # Pair each source file and include with its compiled location. -override sourcecompiledpair := $(foreach file,$(sourcefiles) $(sourceincludes),$(file)|$(BUILDDIR)/public/$(call sourcepath,$(file))) +override sourcecompiledpair := $(foreach file,$(sourcefiles) $(sourceincludes),$(file)|$(BUILDDIR)/public/$(call destination,$(file))) # (callable) Get the location of the transformed X·M·L files for the # given source files. @@ -329,7 +338,8 @@ override compiled = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%, override uncompiled = $(foreach file,$1,$(patsubst %|$(file),%,$(filter %|$(file),$(sourcecompiledpair)))) # (callable) Get the installed locations for the given source files. -override installed = $(foreach file,$1,$(DESTDIR)/$(call sourcepath,$(file))) +override installed = $(foreach file,$1,$(DESTDIR)/$(call destination,$(file))) +endif # ─ ¶ Recipe Variable Definitions ───────────────────────────────────── @@ -363,7 +373,7 @@ install: $(call installed,$(recursivefiles) $(compilablefiles) $(filter $(source # List all source files and includes and their computed types. list: - $(silent)$(PRINTF) '%b' $(call quote,$(foreach file,$(sort $(sourcefiles)) $(sort $(sourceincludes)),\0033[1m$(file)\0033[22m|$(call typeoffile,$(file))|[\0033[3m$(if $(filter $(file),$(xmlfiles)),xml,$(if $(filter $(file),$(plaintextfiles)),text,asset))$(if $(filter $(file),$(sourceincludes)),|include,)\0033[23m]$(if $(call dependencies,$(file))$(call recursives,$(file)), $(strip $(foreach recursive,$(call recursives,$(file)),\0033[93;41m•|Recursive|Dependency|\0033[39;49m|$(recursive)) $(foreach dependency,$(call dependencies,$(file)),\0033[2m•|Dependency|\0033[22m|$(dependency)))) )) | $(TR) ' |' '\n ' + $(silent)$(PRINTF) '%b' $(call quote,$(foreach file,$(sort $(sourcefiles)) $(sort $(sourceincludes)),\0033[1m$(file)\0033[22m|$(call typeoffile,$(file))|[\0033[3m$(if $(filter $(file),$(xmlfiles)),xml,$(if $(filter $(file),$(plaintextfiles)),text,asset))$(if $(filter $(file),$(sourceincludes)),|include,)\0033[23m]$(if $(call dependencies,$(file))$(call recursives,$(file)), $(strip $(foreach recursive,$(call recursives,$(file)),\0033[93;41m•|Recursive|Dependency|\0033[39;49m|$(recursive)) $(foreach dependency,$(call dependencies,$(file)),\0033[2m•|Dependency|\0033[22m|$(dependency))))$(if $(filter $(file),$(sourcefiles)), →|<\0033[4m/$(call destination,$(file))\0033[24m>,) )) | $(TR) ' |' '\n ' # Raise an error when attempting to build any files with recursive # dependencies. @@ -391,10 +401,10 @@ ifneq ($(wildcard $(BUILDDIR)/.update-types)$(wildcard $(BUILDDIR)/dependencies) # # This recipe only exists after types have been updated or when the # dependency graph already exists. -$(THISDIR)/GNUmakefile:: $(BUILDDIR)/dependencies +$(THISDIR)/GNUmakefile:: $(BUILDDIR)/dependencies $(BUILDDIR)/destinations $(silent)$(TOUCH) $(THISDIR)/GNUmakefile $(silent)$(RM) -f $(BUILDDIR)/.update-types - @$(PRINTF) '%b\n' '\0033[1mDependency graph updated. Restarting…\0033[22m' + @$(PRINTF) '%b\n' '\0033[1mDependency graph and output destinations updated. Restarting…\0033[22m' endif ifeq ($(wildcard $(BUILDDIR)/.update-types),) @@ -457,6 +467,13 @@ $(BUILDDIR)/dependencies: $(BUILDDIR)/catalog $(call parsed,$(plaintextfiles) $( @$(ECHO) "Identifying dependencies…" $(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2dependencies.xslt) $(call quote,$<) +# Generate a catalog of destinations for files. This depends on parsing +# non·asset source files, but not assets or includes. It does not +# require knowing the dependencies. +$(BUILDDIR)/destinations: $(BUILDDIR)/catalog $(call parsed,$(filter-out $(assetfiles),$(sourcefiles))) $(THISDIR)/lib/catalog2destinations.xslt + @$(ECHO) "Identifying output destinations…" + $(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2destinations.xslt) $(call quote,$<) + # Generate the main transform. $(BUILDDIR)/transform.catalog: $(TRANSFORMS) @$(ECHO) "Generating catalog of transforms…"