X-Git-Url: https://git.ladys.computer/Shushe/blobdiff_plain/4e4c927c458dd77fd0f6cdac5be14f964525e8b1..59bb51a638838ad413a4c89fb773df233aedb3b6:/GNUmakefile?ds=inline diff --git a/GNUmakefile b/GNUmakefile index ee342ec..f59c4d5 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -218,9 +218,11 @@ override perdec = $(foreach encoded,$1,$(shell $(PRINTF) '%s\n' $(call quote,$(e # The encoding assumes the input is a “u·r·i component”; e·g that the # resulting string should only contain `pchar´ (but can contain any # `sub-delim´). -override perenc = $(foreach unencoded,$1,$(call perdec,$(shell $(PRINTF) '%s' $(call quote,$(unencoded)) | $(OD) -t x1 | $(SED) 's/^[0-9]*//;s/2[146-9A-Ea-e]/%&/g;s/3[0-9AaBbDd]/%&/g;s/40/%&/g;s/[46][1-9A-Fa-f]/%&/g;s/[57][0-9Aa]/%&/g;s/7[Ee]/%&/g;s/[ ][0-9A-Fa-f]\{2\}/%25&/g' | $(TR) -d ' \n' | $(TR) 'abcdef' 'ABCDEF'))) +override perenc = $(foreach unencoded,$1,$(call perdec,$(shell $(PRINTF) '%s' $(call quote,$(unencoded)) | $(OD) -t x1 | $(SED) 's/^[0-9]*//;s/2[146-9A-Ea-e]/%&/g;s/3[0-9AaBbDd]/%&/g;s/40/%&/g;s/[46][1-9A-Fa-f]/%&/g;s/[57][0-9Aa]/%&/g;s/5[Ff]/%&/g;s/7[Ee]/%&/g;s/[ ][0-9A-Fa-f]\{2\}/%25&/g' | $(TR) -d ' \n' | $(TR) 'abcdef' 'ABCDEF'))) # (callable) Percent‐encode each component in the given paths. +# +# ☡ This will remove leading and trailing slashes. override pathenc = $(foreach path,$1,$(subst $(space),/,$(call perenc,$(subst /, ,$(path))))) # (overridable) Collect all of the applicable includes from the @@ -235,13 +237,13 @@ ifdef GIT ifneq ($(wildcard $(THISDIR)/.git),) # (overridable) The name of the current revision of ⛩️📰 书社, or its # hash if the current revision is not a tag. -thisrev = $(shell cd $(THISDIR); $(GIT) describe 2> /dev/null || $(GIT) rev-parse HEAD) +thisrev = $(shell cd $(THISDIR); $(GIT) describe 2> /dev/null || $(GIT) rev-parse HEAD 2> /dev/null || true) endif ifneq ($(wildcard .git),) # (overridable) The name of the current revision of the working # directory, or its hash if the current revision is not a tag. -srcrev = $(shell $(GIT) describe 2> /dev/null || $(GIT) rev-parse HEAD) +srcrev = $(shell $(GIT) describe 2> /dev/null || $(GIT) rev-parse HEAD 2> /dev/null || true) endif endif @@ -268,7 +270,7 @@ override assetfiles := $(filter-out $(xmlfiles) $(plaintextfiles),$(sourcefiles) override typeoffile = $(patsubst $(foreach file,$1,$(file)|%),%,$(filter $(foreach file,$1,$(file)|%),$(types))) # (callable) Get the identifier for the given parser or transform. -override id = $(or $(shell $(XMLLINT) --xpath '/*/*[local-name()="id" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"]/text()[1]' $1),about:shushe?$(or $2,unknown)=$(call pathenc,$(basename $(notdir $1)))) +override id = $(or $(shell $(XMLLINT) --xpath '/*/*[local-name()="id" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"]/text()[1]' $1 2> /dev/null),about:shushe?$(or $2,unknown)=$(call pathenc,$(basename $(notdir $1)))) # (callable) Get the local path for the given source file. override sourcepath = $(firstword $(foreach directory,$(SRCDIR),$(if $(filter $(directory)/%,$1),$(patsubst $(directory)/%,%,$1),))) @@ -343,8 +345,8 @@ override sourcedestinationpair := $(foreach destination,$(destinations),$(call s # (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 destination,$(file))) +# Pair each source file with its compiled location. +override sourcecompiledpair := $(foreach file,$(sourcefiles),$(file)|$(BUILDDIR)/public/$(call destination,$(file))) # (callable) Get the location of the transformed X·M·L files for the # given source files. @@ -371,10 +373,10 @@ override wrapplaintext = $(PRINTF) '%s\n' "$$($(PRINTF) '%b' ',) )) | $(TR) ' |' '\n ' + @$(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. @@ -456,7 +458,7 @@ $(BUILDDIR)/magic.mgc: $(wildcard $(MAGICDIR)/*) $(BUILDDIR)/parser.catalog: $(PARSERS) @$(ECHO) "Generating catalog of parsers…" $(silent)$(XMLCATALOG) --create --noout $(call quote,$@) - $(foreach parser,$(PARSERS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call id,$(parser),parser)) $(call quote,$(call pathenc,../$(parser))) --noout $(call quote,$@)$(newline)) + $(foreach parser,$(PARSERS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call id,$(parser),parser)) $(call quote,file:///$(call pathenc,$(abspath $(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,$<) @@ -476,7 +478,7 @@ $(call parsed,$(sourcefiles) $(sourceincludes)): %: $$(call unparsed,$$@) $(type $(BUILDDIR)/catalog: $(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 pathenc,$(patsubst $(BUILDDIR)/%,%,$(call parsed,$(source))))#$(if $(filter $(source),$(assetfiles)),asset,xml)) --noout $(call quote,$@)$(newline)) + $(foreach source,$(sourcefiles) $(sourceincludes),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call localuri,$(source))) $(call quote,file:///$(call pathenc,$(abspath $(call parsed,$(source))))#$(if $(filter $(source),$(assetfiles)),asset,xml)) --noout $(call quote,$@)$(newline)) # Build a list of dependencies for each parsed file. $(BUILDDIR)/dependencies: $(BUILDDIR)/catalog $(call parsed,$(plaintextfiles) $(xmlfiles)) $(THISDIR)/lib/catalog2dependencies.xslt @@ -494,7 +496,7 @@ $(BUILDDIR)/destinations: $(BUILDDIR)/catalog $(call parsed,$(filter-out $(asset $(BUILDDIR)/transform.catalog: $(TRANSFORMS) @$(ECHO) "Generating catalog of transforms…" $(silent)$(XMLCATALOG) --create --noout $(call quote,$@) - $(foreach transform,$(TRANSFORMS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call id,$(transform),transform)) $(call quote,$(call pathenc,../$(transform))) --noout $(call quote,$@)$(newline)) + $(foreach transform,$(TRANSFORMS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call id,$(transform),transform)) $(call quote,file:///$(call pathenc,$(abspath $(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,$<)