From: Lady Date: Sat, 25 Jan 2025 20:09:34 +0000 (-0500) Subject: Add DATAOPTS X-Git-Tag: 1.0.1^0 X-Git-Url: https://git.ladys.computer/Shushe/commitdiff_plain/ca7be60f15de191e25f8cc1890e13dc499576ec4 Add DATAOPTS This is a bit hacky, but probably is still the simplest and most elegant solution to the problem of ⛩📰 书社 needing to use different variables for different stages of a two‐stage build. Note that the core variables used to manage the two‐stage process (`INCLUDEDIR`, `BUILDDIR`, `FINDRULES`, `FINDINCLUDERULES`, and `MODE`) can _not_ be overridden thru this (or any) mechanism. This commit also adds a new callable variable, `varquote`, for escaping dollar signs when passing them thru to submakes. --- diff --git a/GNUmakefile b/GNUmakefile index a9cf3b8..80e1c4c 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -188,6 +188,11 @@ EXTRAFINDINCLUDERULES := FINDRULES := '!' '(' '(' -name '[.-]*' -a '!' -name '.' -o -name '*[][*?:|$$%\#\\; ]*' -o -name '*[)]' ')' -a -prune ')'$(if $(EXTRAFINDRULES), -a '(' $(EXTRAFINDRULES) ')',) FINDINCLUDERULES := $(FINDRULES)$(if $(EXTRAFINDINCLUDERULES), -a '(' $(EXTRAFINDINCLUDERULES) ')',) +# Options to use when calling Make for the first build of a two‐stage build. +# +# This can be used to override variables which are only applicable to the second build. +DATAOPTS := + # File extensions which indicate files in `SRCDIR´ which should be built as part of the first, rather than second, stage of the two‐stage `MODE´. DATAEXT := rdf @@ -351,6 +356,9 @@ override not = $(if $1,,1) # (callable) Quote the given string for use within shell calls. override quote = '$(subst ','"'"',$1)' +# (callable) Quote the given string for use defining a variable to send to a submake. +override varquote = $(subst $$,$$$$,$(call quote,$1)) + # The command to use for percent‐decoding. override perdeccmd := $(SED) 's/|/%7C/g;s/[\]/%5C/g;s/%[0123456789ABCDEFabcdef]\{2\}/|&|/g' | $(TR) '|' '\n' | $(SED) '/^%[0123456789ABCDEFabcdef]\{2\}$$/!s/%/|%25|/' | $(TR) '|' '\n' | $(AWK) '$$0!~/%/{printf "%s",$$0}/%/{d="0123456789ABCDEF";v=substr(toupper($$0),2,2);printf "\\%04o",(index(d,substr(v,1,1))-1)*16+index(d,substr(v,2,1))-1}' | $(SED) $(call quote,s/'/'"'"'/g;s/^/'/;s/$$/'/;$$!s/$$/\\/) | $(XARGS) -E '' $(PRINTF) '%b' @@ -425,7 +433,7 @@ override id = $(XMLLINT) --noent --nonet --xpath '/*/*[local-name()="id" and nam override extracttext = $(PRINTF) '%s' '' | $(XSLTPROC) --nonet --novalid --nomkdir --nowrite - $(call quote,$1) # (callable) Process the provided transformation result and output the result to the provided location, given the provided relative path. -override processresultto = if $(call xpath,/*[local-name()="raw-text" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"],$1); then $(call extracttext,$1) >|$(call quote,$2); elif $(call xpath,/*[local-name()="base64-binary" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"],$1); then { $(PRINTF) '%s\n' 'begin-base64 644 -'; $(call extracttext,$1) | $(TR) -d '\t\n\f\r '; $(PRINTF) '\n%s\n' '===='; } | $(UUDECODE) -o /dev/stdout >|$(call quote,$2); elif $(call xpath,/*[local-name()="archive" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"],$1); then $(MAKE) -f $(makefile) NAME=$(call quote,$3) SRC=$(call quote,$1) BUILDDIR=$(call quote,$(BUILDDIR)/archive/$3) DESTDIR=$(call quote,$(patsubst %/,%,$(dir $2))) MODE='urn:fdc:ladys.computer:20231231:Shu1She4:mode:archive' $(call quote,$2); else $(FINALIZE) $(call quote,$1) >|$(call quote,$2); fi +override processresultto = if $(call xpath,/*[local-name()="raw-text" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"],$1); then $(call extracttext,$1) >|$(call quote,$2); elif $(call xpath,/*[local-name()="base64-binary" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"],$1); then { $(PRINTF) '%s\n' 'begin-base64 644 -'; $(call extracttext,$1) | $(TR) -d '\t\n\f\r '; $(PRINTF) '\n%s\n' '===='; } | $(UUDECODE) -o /dev/stdout >|$(call quote,$2); elif $(call xpath,/*[local-name()="archive" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"],$1); then $(MAKE) -f $(makefile) NAME=$(call varquote,$3) SRC=$(call varquote,$1) BUILDDIR=$(call varquote,$(BUILDDIR)/archive/$3) DESTDIR=$(call varquote,$(patsubst %/,%,$(dir $2))) MODE='urn:fdc:ladys.computer:20231231:Shu1She4:mode:archive' $(call varquote,$2); else $(FINALIZE) $(call quote,$1) >|$(call quote,$2); fi # ━ § BEGIN DEFAULT MAKE·FILE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -808,10 +816,10 @@ ifeq ($(twostep),) shusheopts := MODE='urn:fdc:ladys.computer:20231231:Shu1She4:mode:default' else # (overridable) Options to use when calling ⛩📰 书社 the first time. -shushedataopts := INCLUDEDIR=$(call quote,$(DATADIR)) BUILDDIR=$(call quote,$(BUILDDIR)/data) FINDRULES=$(subst $$,$$$$,$(call quote,$(FINDRULES) -a '(' $(FINDDATARULES) ')')) FINDINCLUDERULES=$(subst $$,$$$$,$(call quote,$(FINDINCLUDERULES))) MODE='urn:fdc:ladys.computer:20231231:Shu1She4:mode:default' +shushedataopts := $(and $(DATAOPTS),$(DATAOPTS)$(space))INCLUDEDIR=$(call varquote,$(DATADIR)) BUILDDIR=$(call varquote,$(BUILDDIR)/data) FINDRULES=$(call varquote,$(FINDRULES) -a '(' $(FINDDATARULES) ')') FINDINCLUDERULES=$(call varquote,$(FINDINCLUDERULES)) MODE='urn:fdc:ladys.computer:20231231:Shu1She4:mode:default' # (overridable) Options to use when calling ⛩📰 书社 the second time. -shushesiteopts := INCLUDEDIR=$(call quote,$(INCLUDEDIR) $(BUILDDIR)/data/public) BUILDDIR=$(call quote,$(BUILDDIR)/site) FINDRULES=$(subst $$,$$$$,$(call quote,$(FINDRULES) -a '!' '(' $(FINDDATARULES) ')')) FINDINCLUDERULES=$(subst $$,$$$$,$(call quote,$(FINDINCLUDERULES))) MODE='urn:fdc:ladys.computer:20231231:Shu1She4:mode:default' +shushesiteopts := INCLUDEDIR=$(call varquote,$(INCLUDEDIR) $(BUILDDIR)/data/public) BUILDDIR=$(call varquote,$(BUILDDIR)/site) FINDRULES=$(call varquote,$(FINDRULES) -a '!' '(' $(FINDDATARULES) ')') FINDINCLUDERULES=$(call varquote,$(FINDINCLUDERULES)) MODE='urn:fdc:ladys.computer:20231231:Shu1She4:mode:default' endif # ─ ¶ Recipe Variable Definitions ───────────────────────────────────── diff --git a/README.markdown b/README.markdown index d4399e3..70a9730 100644 --- a/README.markdown +++ b/README.markdown @@ -307,6 +307,12 @@ The following additional variables can be used to control the behaviour default, to enable additional rules without overriding the existing ones. +- **`DATAOPTS`:** + Additional options to use when calling Make during the first stage of a two‐stage build using `DATADIR`. + + This can be used to override variables which are only applicable during the second stage. + Note that when supplying this variable on the shell, it will need to be double‐quoted. + - **`DATAEXT`:** A list of file extensions which signify “data” files during a two‐stage build using `DATADIR`.