X-Git-Url: https://git.ladys.computer/Shushe/blobdiff_plain/3d56020bffefecf41aceb500f74de4547e35b842..c430638b245e4ff141c7b6c69d64f87d4d163e9f:/GNUmakefile diff --git a/GNUmakefile b/GNUmakefile index d1a7f6e..be1cf1a 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -101,12 +101,18 @@ XMLLINT := xmllint XSLTPROC := xsltproc # The directory which contains the source files. +# +# Multiple directories can be given so long as files with the same name +# do not exist in each. SRCDIR := sources # The directory which contains “includes”: Files which may be included # in other files but for which no final output will be generated. # -# This can be inside of `SOURCES_DIRECTORY´ if desired. +# Multiple directories can be given so long as files with the same name +# do not exist in each. +# +# These can be inside of `SRCDIR´ directories if desired. INCLUDEDIR := sources/includes # The directory in which to generate temporary buildfiles. @@ -134,11 +140,13 @@ MAGICDIR := $(patsubst ./%,%,$(THISDIR)/magic) # Configuration of `find´. # -# By default, `find´ will follow symlinks and use extended regular -# expressions, ignoring hidden files and those which begin with a -# period. -FINDOPTS := -LE +# By default, `find´ will not follow symlinks and will use extended +# regular expressions, ignoring hidden files and those which begin with +# a period. +FINDOPTS := -PE FINDRULES := -flags -nohidden -and -not -name '.*' +FINDINCLUDEOPTS := $(FINDOPTS) +FINDINCLUDERULES := $(FINDRULES) # The list of parsers for plaintext file types. # @@ -193,13 +201,14 @@ override silent := $(if $(VERBOSE),,@) # (callable) Escape special characters for use in sed regular # expressions. -override sedesc = $(subst $$,\$$,$(subst *,\*,$(subst .,\.,$(subst [,\[,$(subst ^,\^,$(subst \,\\,$1)))))) +override sedesc = $(subst /,[/],$(subst $$,\$$,$(subst *,\*,$(subst .,\.,$(subst [,\[,$(subst ^,\^,$(subst \,\\,$1))))))) -# Collect all of the applicable includes from the includes directory. +# (overridable) Collect all of the applicable includes from the +# includes directory. sourceincludes := $(shell $(FIND) $(FINDOPTS) $(INCLUDEDIR) -type f '(' $(FINDRULES) ')') -# Collect all of the applicable source files from the source directory, -# removing any which are also includes. +# (overridable) Collect all of the applicable source files from the +# source directory, removing any which are also includes. sourcefiles := $(filter-out $(sourceincludes),$(shell $(FIND) $(FINDOPTS) $(SRCDIR) -type f '(' $(FINDRULES) ')')) # Figure out the file type of each source file and source include. @@ -209,36 +218,41 @@ endif # Get the list of supported plaintext file types from the parser. ifneq ($(wildcard $(BUILDDIR)/parser.xslt),) -override plaintexttypes := $(shell $(XSLTPROC) $(call quote,$(THISDIR)/lib/parser2types.xslt) $(call quote,$(BUILDDIR)/parser.xslt)) +override plaintexttypes := $(filter-out $(XMLTYPES),$(shell $(XSLTPROC) $(call quote,$(THISDIR)/lib/parser2types.xslt) $(call quote,$(BUILDDIR)/parser.xslt))) endif -# Simplify the file type by only taking the first component (image, -# text, ⁊·c). -override simpletypes := $(shell $(TR) ' ' '\n' <<< $(call quote,$(types)) | $(SED) 's`/[^/]*$$``g') - # (callable) Get all of the files (source and includes) which have the # given types. override filesoftype = $(foreach type,$1,$(patsubst %?type=$(type),%,$(filter %?type=$(type),$(types)))) # Build up collections of various file types. -override plaintextfiles := $(call filesoftype,$(plaintexttypes)) -override xmlfiles := $(filter-out $(plaintextfiles),$(call filesoftype,$(XMLTYPES))) +override xmlfiles := $(call filesoftype,$(XMLTYPES)) +override plaintextfiles := $(filter-out $(xmlfiles),$(call filesoftype,$(plaintexttypes))) override assetfiles := $(filter-out $(xmlfiles) $(plaintextfiles),$(sourcefiles) $(sourceincludes)) # (callable) Get the types of the given files. override typeoffile = $(patsubst $(foreach file,$1,$(file)?type=%),%,$(filter $(foreach file,$1,$(file)?type=%),$(types))) # (callable) Get the identifier for the given transform. -override id = $(or $(shell $(XMLLINT) --xpath '/*/*[local-name()="id" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"]/text()[1]' $1),$(basename $(notdir $1)) | $(SED)) +override id = $(or $(shell $(XMLLINT) --xpath '/*/*[local-name()="id" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"]/text()[1]' $1),$(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),))) + +# (callable) Get the local path for the given include. +override includepath = $(firstword $(foreach directory,$(INCLUDEDIR),$(if $(filter $(directory)/%,$1),$(patsubst $(directory)/%,%,$1),))) # (callable) Get base64 data u·r·i’s for the given files. override datauri = $(foreach file,$1,data:$(call typeoffile,$(file));base64,$(shell $(UUENCODE) -m -r $(call quote,$(file)) _ | tr -d ' \n')) # (callable) Get local leiris for the given files. -override localuri = $(foreach file,$1,$(if $(filter $(file),$(sourceincludes)),$(patsubst $(INCLUDEDIR)/%,about:shushe?include=%,$(file)),$(patsubst $(SRCDIR)/%,about:shushe?source=%,$(file)))) +override localuri = $(foreach file,$1,$(if $(filter $(file),$(sourceincludes)),about:shushe?include=$(call includepath,$(file)),about:shushe?source=$(call sourcepath,$(file)))) + +# Pair each source file and include with its local u·r·i. +override sourcelocalpair = $(foreach file,$(sourcefiles) $(sourceincludes),$(file)`$(call localuri,$(file))) # (callable) Get the source files for the given local leiris. -override sourcefile = $(foreach file,$1,$(if $(filter about:shushe?include=%,$(file)),$(patsubst about:shushe?include=%,$(INCLUDEDIR)/%,$(file)),$(patsubst about:shushe?source=%,$(SRCDIR)/%,$(file)))) +override sourcefile = $(foreach local,$1,$(patsubst %`$(local),%,$(filter %`$(local),$(sourcelocalpair)))) # Adds a requirement on `$(BUILDDIR)/.update-types´ if the file is # present. @@ -250,7 +264,13 @@ override typeupdates := $(wildcard $(BUILDDIR)/.update-types) # (callable) Get the location of the transformed X·M·L files for the # given source files. -override parsed = $(foreach file,$1,$(if $(filter $(file),$(sourceincludes)),$(patsubst $(INCLUDEDIR)/%,$(BUILDDIR)/includes/%,$(file)),$(patsubst $(SRCDIR)/%,$(BUILDDIR)/sources/%,$(file)))) +override parsed = $(foreach file,$1,$(if $(filter $(file),$(sourceincludes)),$(BUILDDIR)/includes/$(call includepath,$(file)),$(BUILDDIR)/sources/$(call sourcepath,$(file)))) + +# Pair each source file and include with its parsed location. +override sourceparsedpair = $(foreach file,$(sourcefiles) $(sourceincludes),$(file)`$(call parsed,$(file))) + +# (callable) Get the source files for the given parsed file. +override unparsed = $(foreach file,$1,$(patsubst %`$(file),%,$(filter %`$(file),$(sourceparsedpair)))) ifneq ($(wildcard $(BUILDDIR)/dependencies),) # Pair each file with a list of dependencies for it. @@ -280,10 +300,16 @@ override recursivefiles := $(foreach file,$(filter-out $(assetfiles),$(sourcefil override compilablefiles := $(filter-out $(assetfiles) $(recursivefiles),$(sourcefiles)) # (callable) Get the compiled locations for the given source files. -override compiled = $(patsubst $(SRCDIR)/%,$(BUILDDIR)/public/%,$(1)) +override compiled = $(foreach file,$1,$(BUILDDIR)/public/$(call sourcepath,$(file))) + +# Pair each source file and include with its compiled location. +override sourcecompiledpair = $(foreach file,$(sourcefiles) $(sourceincludes),$(file)`$(call compiled,$(file))) + +# (callable) Get the source files for the given compiled file. +override uncompiled = $(foreach file,$1,$(patsubst %`$(file),%,$(filter %`$(file),$(sourcecompiledpair)))) # (callable) Get the installed locations for the given source files. -override installed = $(patsubst $(SRCDIR)/%,$(DESTDIR)/%,$(1)) +override installed = $(foreach file,$1,$(DESTDIR)/$(call sourcepath,$(file))) # ─ ¶ Recipe Variable Definitions ───────────────────────────────────── @@ -302,7 +328,7 @@ help: $(silent)$(PRINTF) '%b' '$(subst $(newline),\n,$(makefileinfo))' # Compile all files, or error if any are recursive. -all: $(call compiled,$(recursivefiles) $(compilablefiles) $(assetfiles)) ; +all: $(call compiled,$(recursivefiles) $(compilablefiles) $(filter $(sourcefiles),$(assetfiles))) ; # Destroy buildfiles. clean: @@ -313,7 +339,7 @@ gone: $(silent)$(RM) -rf $(BUILDDIR)/ $(call compiled,$(recursivefiles) $(compilablefiles)) # Install the compiled files into `DESTDIR´. -install: $(call installed,$(recursivefiles) $(compilablefiles) $(assetfiles)) ; +install: $(call installed,$(recursivefiles) $(compilablefiles) $(filter $(sourcefiles),$(assetfiles))) ; # List all source files and includes and their computed types. list: @@ -394,14 +420,10 @@ $(BUILDDIR)/parser.xslt: $(BUILDDIR)/parser.catalog $(THISDIR)/lib/catalog2parse # Even plain X·M·L files are parsed, because they may contain X·H·T·M·L # `