# ─ ¶ Phony Targets ───────────────────────────────────────────────────
# Provide help.
-help:
+help :
@$(PRINTF) '%b' '$(subst $(newline),\n,$(makefileinfo))'
# Compile all files, or error if any are recursive.
-all: $(call compiled,$(recursivefiles) $(compilablefiles));
+all : $(call compiled,$(recursivefiles) $(compilablefiles)) ;
# Destroy buildfiles.
-clean:
+clean :
$(if $(BUILDDIR),$(silent)$(RM) -rf $(call quote,$(BUILDDIR)/),)
# Destroy build directory and installed files.
-gone: clean uninstall;
+gone : clean uninstall ;
# Install the compiled files into `DESTDIR´, or error if any are recursive.
-install: $(call installed,$(recursivefiles) $(installablefiles));
+install : $(call installed,$(recursivefiles) $(installablefiles)) ;
# List all source files and includes and their computed types.
-list:
+list :
@$(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 '
# Destroy build directory and installed files.
-uninstall:
+uninstall :
$(foreach file,$(installablefiles),$(if $(wildcard $(call installed,$(file))),$(silent)$(PRINTF) '%s\n' $(call quote,Removing </$(patsubst $(DESTDIR)/%,%,$(call installed,$(file)))>…)$(newline)$(silent)$(RM) -f $(call quote,$(call installed,$(file)))$(newline),))
# Raise an error when attempting to build any files with recursive dependencies.
-$(call compiled,$(recursivefiles)):
+$(call compiled,$(recursivefiles)) :
@$(PRINTF) '%b\n' $(call quote,\0033[93;41mError:\0033[39;49m `$(call uncompiled,$@)´ has recursive dependencies:\n$(subst |, ,$(subst $(space),$(newline),$(foreach recursive,$(call recursives,$(call uncompiled,$@)),•|$(recursive))))) && false
# ─ ¶ Special Targets ─────────────────────────────────────────────────
# Perform secondary expansion; this enables pattern rules to determine their prerequisites based on the matched pattern.
-.SECONDEXPANSION: ;
+.SECONDEXPANSION : ;
# Don’t use any implicit rules.
-.SUFFIXES: ;
+.SUFFIXES : ;
# Phony rules; always consider these out·of·date.
-.PHONY: all default clean gone info install list uninstall $(call compiled,$(recursivefiles));
+.PHONY : all default clean gone info install list uninstall $(call compiled,$(recursivefiles)) ;
ifneq ($(wildcard $(BUILDDIR)/.update-types)$(wildcard $(BUILDDIR)/dependencies)$(wildcard $(BUILDDIR)/destinations),)
# Reload this make·file if the dependency graph or output destinations have changed.
# The dependency graph and output destinations are used to set the values of variables in this make·file, so it’s important to ensure that they are actually up·to·date prior to executing any later rules.
#
# This recipe only exists after types have been updated or when the dependency graph or destinations file already exists.
-$(THISDIR)/GNUmakefile:: $(BUILDDIR)/dependencies $(BUILDDIR)/destinations
+$(THISDIR)/GNUmakefile :: $(BUILDDIR)/dependencies $(BUILDDIR)/destinations
$(silent)$(TOUCH) $(THISDIR)/GNUmakefile
$(silent)$(RM) -f $(BUILDDIR)/.update-types
@$(PRINTF) '%b\n' '\0033[1mDependency graph and output destinations updated. Restarting…\0033[22m'
# These are used to classify source files, so if they have changed then the make·file must be reloaded.
#
# This recipe sleeps for one second to ensure that files built after the restart have a more current time·stamp.
-$(THISDIR)/GNUmakefile:: $(BUILDDIR)/magic.mgc $(BUILDDIR)/parser.xslt
+$(THISDIR)/GNUmakefile :: $(BUILDDIR)/magic.mgc $(BUILDDIR)/parser.xslt
$(silent)$(TOUCH) $(THISDIR)/GNUmakefile
$(silent)$(RM) -f $(call quote,$(BUILDDIR)/dependencies) $(call quote,$(BUILDDIR)/destinations)
@$(PRINTF) '%b\n' '\0033[1mMagic file or parsers have updated. Restarting…\0033[22m'
# Create symbolic links from the build directory’s store of magic files
# to their corresponding sources.
-$(call magicfile,$(MAGIC)): $(BUILDDIR)/magic/%: $$(call magicsource,$$@)
+$(call magicfile,$(MAGIC)) : $(BUILDDIR)/magic/%: $$(call magicsource,$$@)
$(silent)$(call ensuredirectory,$(dir $@))
$(silent)$(LN) -sf $(call quote,$(realpath $<)) $(call quote,$@)
#
# It must be updated if any of the files in the magic directory change.
# It ⁜also⁜ should be updated if any of the files in the magic directory are deleted, but this isn’t tracked presently.
-$(BUILDDIR)/magic.mgc: $(call magicfile,$(MAGIC))
+$(BUILDDIR)/magic.mgc : $(call magicfile,$(MAGIC))
$(foreach outdated,$(filter-out $^,$(wildcard $(BUILDDIR)/magic/*)),$(silent)$(RM) $(call quote,$(outdated))$(newline))
@$(ECHO) "Compiling new magic…"
$(silent)$(call ensuredirectory,$(dir $@))
$(silent)cd $(call quote,$(BUILDDIR)) && $(FILE) -C -m $(call quote,$(realpath $(BUILDDIR)/magic))
# Generate the main parser.
-$(BUILDDIR)/parser.catalog: $(PARSERS)
+$(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,file:///$(call pathenc,$(abspath $(parser)))) --noout $(call quote,$@)$(newline))
#
# Even plain X·M·L files are parsed, because they may contain X·H·T·M·L `<script>´ elements which contain other kinds of data.
# Asset files are turned into H·T·M·L embeds pointing to `data:´ U·R·I’s.
-$(call parsed,$(sourcefiles) $(sourceincludes)): %: $$(call unparsed,$$@) $(typeupdates)
+$(call parsed,$(sourcefiles) $(sourceincludes)) : % : $$(call unparsed,$$@) $(typeupdates)
@$(PRINTF) '%s\n' $(call quote,Processing `$<´…)
$(silent)$(call ensuredirectory,$(dir $@))
$(silent)$(if $(filter $<,$(assetfiles)),$(PRINTF) '%s\n' $(call quote,<object xmlns="http://www.w3.org/1999/xhtml" type="$(call typeoffile,$<)" data="$(call datauri,$<)"/>) > $(call quote,$@),$(if $(filter $<,$(plaintextfiles)),$(call wrapplaintext,$<),$(CAT) $(call quote,$<)) | $(XSLTPROC) -o $(call quote,$@) --stringparam BUILDTIME '$(shell TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ')' --stringparam SRCTIME '$(shell TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$(call unparsed,$@)))'$(if $(thisrev), --stringparam VERSION $(call quote,$(thisrev)),)$(if $(srcrev), --stringparam SRCREV $(call quote,$(srcrev)),) $(call quote,$(BUILDDIR)/parser.xslt) -)
# Generate a catalog of all parsed files, for use when processing includes.
#
# This does not depend on actually transforming the files.
-$(BUILDDIR)/catalog: $(sourcefiles) $(sourceincludes) $(typeupdates)
+$(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,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
+$(BUILDDIR)/dependencies : $(BUILDDIR)/catalog $(call parsed,$(plaintextfiles) $(xmlfiles)) $(THISDIR)/lib/catalog2dependencies.xslt
@$(ECHO) "Identifying dependencies…"
$(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2dependencies.xslt) $(call quote,$<)
#
# 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
+$(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)
+$(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,file:///$(call pathenc,$(abspath $(transform)))) --noout $(call quote,$@)$(newline))
-$(BUILDDIR)/transform.xslt: $(BUILDDIR)/transform.catalog $(THISDIR)/lib/catalog2transform.xslt
+$(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,$<)
# Generate the output files using the dependencies as necessary.
-$(call compiled,$(compilablefiles)): $(BUILDDIR)/public/%: $$(call parsed,$$(call uncompiled,$$@)) $(BUILDDIR)/transform.xslt $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@)))
+$(call compiled,$(compilablefiles)) : $(BUILDDIR)/public/% : $$(call parsed,$$(call uncompiled,$$@)) $(BUILDDIR)/transform.xslt $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@)))
$(silent)$(call ensuredirectory,$(dir $@))
@$(PRINTF) '%s\n' $(call quote,Compiling </$*>…)
$(silent)$(XSLTPROC) -o $(call quote,$@) --stringparam CATALOG 'catalog' --stringparam BUILDTIME '$(shell TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ')' --stringparam SRCTIME '$(shell TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$(call uncompiled,$@)))' --stringparam PATH $(call quote,/$*)$(if $(thisrev), --stringparam VERSION $(call quote,$(thisrev)),)$(if $(srcrev), --stringparam SRCREV $(call quote,$(srcrev)),) $(call quote,$(BUILDDIR)/transform.xslt) $(call quote,$<)
-$(call compiled,$(filter $(assetfiles),$(sourcefiles))): $(BUILDDIR)/public/%: $$(call uncompiled,$$@)
+$(call compiled,$(filter $(assetfiles),$(sourcefiles))) : $(BUILDDIR)/public/% : $$(call uncompiled,$$@)
@$(PRINTF) '%s\n' $(call quote,Compiling </$*>…)
$(silent)$(call ensuredirectory,$(dir $@))
$(silent)$(CP) $(call quote,$<) $(call quote,$@)
# Install compiled files (or error in the case of recursive ones).
-$(call installed,$(filter $(assetfiles),$(sourcefiles)) $(recursivefiles) $(compilablefiles)): $(DESTDIR)/%: $(BUILDDIR)/public/%
+$(call installed,$(filter $(assetfiles),$(sourcefiles)) $(recursivefiles) $(compilablefiles)) : $(DESTDIR)/% : $(BUILDDIR)/public/%
@$(PRINTF) '%s\n' $(call quote,Installing </$*>…)
$(silent)$(call ensuredirectory,$(dir $@))
$(silent)$(CP) $(call quote,$<) $(call quote,$@)