From: Lady Date: Sat, 25 Jan 2025 19:39:04 +0000 (-0500) Subject: Add FINDFILTER⸺ variables X-Git-Tag: 1.0.1~1 X-Git-Url: https://git.ladys.computer/Shushe/commitdiff_plain/a555040fdebc4432aee0c167a89e74ed1378f735 Add FINDFILTER⸺ variables There are two possible approaches to how these variables could work :— - By filtering _during_ the `find` (i·e using `-exec`), or - By filtering _after_ the `find`. The latter generally seems more efficient and the former doesn’t seem to offer any benefits, so that is the approach taken here. Filters are separated by semicolons, which are otherwise forbidden in file·names, so it shouldn’t be a problem that the regular expressions won’t be able to contain literal semicolons themselves. The hope is that these variables provide a much cleaner solution to `EXTRAFINDRULES` and `EXTRAFINDINCLUDERULES` hackery. Those are still needed (for now) to manage two‐stage builds, but they’re cumbersome and probably aren’t ideal in most cases. --- diff --git a/GNUmakefile b/GNUmakefile index ca6bfcd..a9cf3b8 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -197,6 +197,46 @@ DATAEXT := rdf EXTRAFINDDATARULES := FINDDATARULES := -name '.' $(foreach ext,$(DATAEXT), -o -name '$(subst ','"'"',[!.]*.$(ext))')$(if $(EXTRAFINDDATARULES), -a '(' $(EXTRAFINDDATARULES) ')',) +# A semicolon‐separated list of regular expressions which paths should be required to match when finding files. +FINDFILTERONLY := + +# A semicolon‐separated list of regular expressions for paths which should be filtered out when finding files. +FINDFILTEROUT := + +# A semicolon‐separated list of regular expressions for paths which paths should be required to match when finding includes. +# +# This is generally only useful when `SRCDIR´ and `INCLUDEDIR´ point to the same location. +# In that situation, this variable can be used to select certain files as includes, leaving the others to be recognized as sources instead. +# +# Otherwise, appropriately constructing `FINDFILTERONLY´ to look at the base directory of the files it finds should be sufficient. +FINDINCLUDEFILTERONLY := + +# A semicolon‐separated list of regular expressions for paths which should be filtered out in addition to those in `FINDFILTEROUT´ when finding includes. +# +# This is generally only useful when `SRCDIR´ and `INCLUDEDIR´ point to the same location. +# In that situation, this variable can be used to exclude certain files from being recognized as includes, which will make them recognized as sources instead. +# +# Otherwise, appropriately constructing `FINDFILTEROUT´ to look at the base directory of the files it finds should be sufficient. +FINDINCLUDEFILTEROUT := + +# If not empty, the regular expression provided by `FINDFILTERONLY´ is an extended regular expression. +FINDFILTERONLYEXTENDED := + +# If not empty, the regular expression provided by `FINDFILTEROUT´ is an extended regular expression. +# +# By default, this matches `FINDFILTERONLYEXTENDED´ +FINDFILTEROUTEXTENDED := $(FINDFILTERONLYEXTENDED) + +# If not empty, the regular expression provided by `FINDFILTEROUT´ is an extended regular expression. +# +# By default, this matches `FINDFILTERONLYEXTENDED´ +FINDINCLUDEFILTERONLYEXTENDED := $(FINDFILTERONLYEXTENDED) + +# If not empty, the regular expression provided by `FINDINCLUDEFILTEROUT´ is an extended regular expression. +# +# By default, this matches `FINDFILTEROUTEXTENDED´ +FINDINCLUDEFILTEROUTEXTENDED := $(and $(FINDFILTERONLYEXTENDED),$(FINDFILTEROUTEXTENDED),1) + # The list of magic files to use when determining media types. # # Some are provided as part of this repository, but you can add more if you need different media type detection. @@ -403,10 +443,10 @@ override attresc = $(subst ",",$(call xmlesc,$1)) override sedesc = $(subst /,[/],$(subst $$,\$$,$(subst *,\*,$(subst .,\.,$(subst [,\[,$(subst ^,\^,$(subst \,\\,$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)),) +sourceincludes := $(foreach dir,$(INCLUDEDIR),$(and $(dir),$(wildcard $(dir)),$(patsubst ./%,%,$(shell $(FIND) $(call quote,$(dir)) '(' $(FINDINCLUDERULES) ')' -a -type f -a -print$(and $(FINDFILTERONLY),$(space)| $(GREP)$(and $(FINDFILTERONLYEXTENDED),$(space)-E) $(foreach filter,$(shell $(PRINTF) '%s\n' $(call quote,$(FINDFILTERONLY)) | $(TR) ' ;' '; '),-e $(call quote,$(subst ;, ,$(filter)))))$(and $(FINDINCLUDEFILTERONLY),$(space)| $(GREP)$(and $(FINDINCLUDEFILTERONLYEXTENDED),$(space)-E) $(foreach filter,$(shell $(PRINTF) '%s\n' $(call quote,$(FINDINCLUDEFILTERONLY)) | $(TR) ' ;' '; '),-e $(call quote,$(subst ;, ,$(filter)))))$(and $(FINDFILTEROUT),$(space)| $(GREP)$(and $(FINDFILTEROUTEXTENDED),$(space)-E) -v $(foreach filter,$(shell $(PRINTF) '%s\n' $(call quote,$(FINDFILTEROUT)) | $(TR) ' ;' '; '),-e $(call quote,$(subst ;, ,$(filter)))))$(and $(FINDINCLUDEFILTEROUT),$(space)| $(GREP)$(and $(FINDINCLUDEFILTEROUTEXTENDED),$(space)-E) -v $(foreach filter,$(shell $(PRINTF) '%s\n' $(call quote,$(FINDINCLUDEFILTEROUT)) | $(TR) ' ;' '; '),-e $(call quote,$(subst ;, ,$(filter))))))))) # (overridable) Collect all of the applicable source files from the source directory, removing any which are also includes. -sourcefiles := $(if $(and $(SRCDIR),$(wildcard $(SRCDIR))),$(filter-out $(sourceincludes),$(patsubst ./%,%,$(shell $(FIND) $(foreach dir,$(SRCDIR),$(call quote,$(dir))) '(' $(FINDRULES) ')' -a -type f -a -print)))) +sourcefiles := $(filter-out $(sourceincludes),$(foreach dir,$(SRCDIR),$(and $(dir),$(wildcard $(dir)),$(patsubst ./%,%,$(shell $(FIND) $(call quote,$(dir)) '(' $(FINDRULES) ')' -a -type f -a -print$(and $(FINDFILTERONLY),$(space)| $(GREP)$(and $(FINDFILTERONLYEXTENDED),$(space)-E) $(foreach filter,$(shell $(PRINTF) '%s\n' $(call quote,$(FINDFILTERONLY)) | $(TR) ' ;' '; '),-e $(call quote,$(subst ;, ,$(filter)))))$(and $(FINDFILTEROUT),$(space)| $(GREP)$(and $(FINDFILTEROUTEXTENDED),$(space)-E) -v $(foreach filter,$(shell $(PRINTF) '%s\n' $(call quote,$(FINDFILTEROUT)) | $(TR) ' ;' '; '),-e $(call quote,$(subst ;, ,$(filter)))))))))) # Figure out the file type of each source file and source include. ifneq ($(wildcard $(BUILDDIR)/magic.mgc),) diff --git a/README.markdown b/README.markdown index af78725..d4399e3 100644 --- a/README.markdown +++ b/README.markdown @@ -1,5 +1,5 @@ # ⛩📰 书社 @@ -319,6 +319,32 @@ The following additional variables can be used to control the behaviour default, to enable additional rules without overriding the existing ones. +- **`FINDFILTERONLY`:** + A semicolon‐separated list of regular expressions, at least one of which the paths for sources and includes are required to match, unless empty (default: empty). + +- **`FINDFILTEROUT`:** + A semicolon‐separated list of regular expressions, each of which matches paths that should _not_ be considered sources or includes (default: empty). + +- **`FINDINCLUDEFILTERONLY`:** + A semicolon‐separated list of regular expressions, at least one of which the paths for includes are required to match, unless empty (default: empty). + + Note that only paths which already match `FINDFILTERONLY` are considered. + +- **`FINDINCLUDEFILTEROUT`:** + A semicolon‐separated list of regular expressions, each of which matches paths that should _not_ be considered includes, but may still be considered sources (default: empty). + +- **`FINDFILTERONLYEXTENDED`:** + If non·empty, `FINDFILTERONLY` is an extended regular expression; otherwise, it is basic (default: empty). + +- **`FINDFILTEROUTEXTENDED`:** + If non·empty, `FINDFILTEROUT` is an extended regular expression; otherwise, it is basic (default: matches `FINDFILTERONLYEXTENDED`). + +- **`FINDINCLUDEFILTERONLYEXTENDED`:** + If non·empty, `FINDINCLUDEFILTERONLY` is an extended regular expression; otherwise, it is basic (default: matches `FINDFILTERONLYEXTENDED`). + +- **`FINDINCLUDEFILTEROUTEXTENDED`:** + If non·empty, `FINDINCLUDEFILTEROUT` is an extended regular expression; otherwise, it is basic (default: `1` if either `FINDFILTEROUTEXTENDED` or `FINDINCLUDEFILTERONLYEXTENDED` is non·empty). + - **`PARSERS`:** A white·space‐separated list of parsers to use (default: `$(THISDIR)/parsers/*.xslt`).