$(subst $$@,$$(mg@),$(subst $$<,$$(mg<),$(subst $$^,$$(mg^),$(subst $$+,$$(mg+),$1))))
endef
-# $(call mg-rule,target,prerequisite,cmd)
+# $(call mg-define-rule,target,prerequisite,cmd)
# Defines a rule.
# If cmd uses $@, quote if necessary so this function sees $@, etc.
#
# - bar is unmanaged => warn about override
MG-FORCE:
.PHONY: MG-FORCE
-scout-oid:=$(newoid)
+mg-scout-oid:=$(newoid)
define mg-define-rule
$(eval
$1.g: target = $$(@:.g=)
$1.g: cmd = $(call mg-translate-cmd,$3)
$1.g: mg@ = $$(target).tmp
-$1.g: mg^ = $$(filter-out MG-% /./%,$$^)
-$1.g: mg+ = $$(filter-out MG-% /./%,$$+)
+$1.g: mg^ = $$(filter-out MG-% $$(opfx)%,$$^)
+$1.g: mg+ = $$(filter-out MG-% $$(opfx)%,$$+)
$1.g: mg< = $$(firstword $$(mg^))
# Rule for the genfile. Evidently all the prerequisites we want second-expanded
$1.g: $2 $$$$(mg-scout-target) MG-FORCE
$$(mg-generate)
+$(mg-file-from-genfile)
+)
+endef
+
+define mg-file-from-genfile
# If the file was regenerated, load the new genfile.
# If not, replay any warnings.
-## We don't have to worry about .DELETE_ON_ERROR deleting the target because
-## it is only touched if we *successfully* regenerate it.
-# - No longer applies because we don't remember errors.
# HMMM Maybe errors should go to stderr???
$1: MG-FORCE | $1.g
$$(call gload,$$@)
$$(if $$($$@@warnings),$$(if $$($$@@built),,$$(info $$($$@@cmd) # warning replay)$$(info $$($$@@warnings))),)
-)
endef
# If the target is unmanaged, we must run the rule; we'll see that the
# obfuscated target is in $? and complain.
-mg-scout-target=$(if $(wildcard $(target)),$(scout-oid)$(aname)$(target),)
+mg-scout-target=$(if $(wildcard $(target)),$(mg-scout-oid)$(aname)$(target),)
# If the command changed, we must regenerate.
mg-check-cmd=$(if $(call streq,$(cmd),$($(target)@cmd)),,x)
# Just add additional prerequisites.
-# I don't think this works for implicit rules.
+# I don't think this can add patterns to implicit rules, but it should be able
+# to add specific prerequisites to uses of implicit rules.
define mg-define-prereq
$(eval
$1.g: $2
# from before the removal. (trap EXIT)
define mg-generate
$(call gload,$(target))\
- $(if $(filter $(scout-oid)$(aname)$(target),$?),\
+ $(if $(filter $(mg-scout-oid)$(aname)$(target),$?),\
$(info mage: warning: Manually created/modified file at $(target) overrides rule.)\
$(eval $(target)@cmd:=)$(eval $(target)@warnings:=)$(eval $(target)@deps:=)\
,\