# MAIN BUILD LOGIC
-# bar.g file format:
-# bar@cmd:=cat foo >bar.tmp
-# bar@warnings:=$(empty)yikes!
-# And if dependency-logging:
-# List of filename@revision, revision is x for exists and empty for doesn't
-# exist. Later perhaps x will be the mtime.
-# bar@deps:=included@x oops@
-# If bar is overridden, we clear all three variables.
+# Target metadata variables for bar: (*: stored in bar.g)
+#
+# bar@cmd:=cat foo >bar.tmp
+# Generation command as given to the shell.*
+# bar@warnings:=$(empty)yikes!
+# Stuff the command printed to stdout or stderr.*
+# bar@deps:=included@x oops@
+# If dependency-logging, list of filename@revision used. Revision is x for
+# exists and empty for doesn't exist. Later perhaps x will be the mtime.*
+# bar@gloaded:=1
+# Set if Mage has loaded bar.g and hasn't changed it since then.
+# bar@uptodate:=1
+# Set when Mage makes a file or depends on it being made. Used to determine
+# the next prerequisite to check for a dependency-logging command.
+# bar@generated:=1
+# Set when Mage generates a file; suppresses warning replay.
+#
+# If the rule for bar is overridden, we clear the information from bar.g so that
+# it is as if bar.g didn't exist.
# $(call gload,foo.o)
# Make sure foo.o's genfile, if any, has been loaded.
# HMMM Maybe errors should go to stderr???
$1: MG-FORCE | $1.g
$$(call gload,$$@)
- $$(if $$($$@@warnings),$$(if $$($$@@built),,$$(info $$($$@@cmd) # warning replay)$$(info $$($$@@warnings))),)
+ $$(eval $$@@uptodate:=1)
+ $$(if $$($$@@warnings),$$(if $$($$@@changed),,$$(info $$($$@@cmd) # warning replay)$$(info $$($$@@warnings))),)
endef
# If the target is unmanaged, we must run the rule; we'll see that the
# Just add additional prerequisites.
# 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.
+# TODO Make this work for dependency-logging commands if desired.
define mg-define-prereq
$(eval
$1.g: $2
$(eval $(target)@cmd:=)$(eval $(target)@warnings:=)$(eval $(target)@deps:=)\
,\
$(if $?$(if $(wildcard $(target)),,x)$(mg-check-cmd),\
- $(eval $(target)@gloaded:=)$(eval $(target)@built:=1)$(info $(cmd))\
+ $(eval $(target)@gloaded:=)$(eval $(target)@changed:=1)$(info $(cmd))\
@trap 'rm -f $(target).tmp $@.tmp' EXIT &&\
exec 3>$@.tmp && $(mg-assign-cmd) >&3 &&\
set -o pipefail && { $(mg-run-cmd) | tee /dev/fd/4 | $(mg-wrap-warnings) >&3; } 4>&1 &&\
mg-wrap-warnings=sed -re '1s/^/$(target)@warnings:=$$(empty)/; 1!s/^/$(target)@warnings+=$$(nl)/'
mg-maybe-move-target={ cmp -s $(target) $(target).tmp || echo >$@ && mv -f $(target).tmp $(target); }
+# $(call mg-rule,target,static prerequisites,cmd,[dep converter])
+# Defines a rule with a dependency-logging command.
+# I haven't decided on the format for the dep converter yet.
+dlc-static-run-oid:=$(newoid)
+define mg-define-rule-dlc
+$(eval
+
+# Copied stuff from mg-define-rule to modify as necessary
+
+## Define some target-specific variables.
+## It might look like we could use $*, but $1 most likely isn't %.
+#$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< = $$(firstword $$(mg^))
+
+#
+$1.g: MG-FORCE | $$$$(dlc-first-run-oid)$$$$(aname)$1.g $$$$(call dlc-setup-tgt,$(newoid))
+
+## Rule for the genfile. Evidently all the prerequisites we want second-expanded
+## have to go on the same rule.
+#$1.g: $2 $$$$(mg-scout-target) MG-FORCE
+# $$(mg-generate)
+
+
+$(mg-file-from-genfile)
+)
+endef
+
+define dlc-setup-tgt
+$(eval
+
+)$1
+endef
+
# END
# We don't want anything we defined to become the default goal.