- Reuse $(@cmd) instead of accumulating $(foo@cmd). Reduces memory and may help
authorMatt McCutchen <hashproduct@gmail.com>
Thu, 14 Jun 2007 01:10:50 +0000 (21:10 -0400)
committerMatt McCutchen <hashproduct@gmail.com>
Thu, 14 Jun 2007 01:10:50 +0000 (21:10 -0400)
  when multiple files have the same basename.
- Get tough on undefined variables.
- Remove redundant build log printing in the test suite.

demo/Makefile
mgear.mk
testsuite

index 41f7ef1..7eb0502 100644 (file)
@@ -16,6 +16,7 @@ $(call mg-define-rule,%.h,%,$(value cmd-addheader))
 mainoid := $(newoid)
 all: $(mainoid)
 $(mainoid)@opr:=foo.x.h
+$(mainoid)@ocmd:=
 
 clean:
        $(call mg-clean-cmd,.)
index d456fd5..7eb2877 100644 (file)
--- a/mgear.mk
+++ b/mgear.mk
@@ -105,20 +105,21 @@ $(opfx)%: $$(empty) $$($$(oid)@opr)
 # prerequisite change, etc. and acts accordingly.
 #
 # Target metadata variables for bar: (* means stored in bar.g)
+# Now some variables are reused instead of remembered for every target.
 #
-# bar@cmd:=cat foo >bar.tmp
+# @name:=bar
+#     Name of the target to which @cmd, @warnings, @deps refer.
+#
+# @cmd:=cat foo >bar.tmp
 #     Generation command as given to the shell.*
 #
-# bar@warnings:=$(empty)yikes!
+# @warnings:=$(empty)yikes!
 #     Data that the command printed to stdout or stderr, presumably warnings.*
 #
-# bar@deps:=included@x oops@
+# @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 mgear has loaded bar.g and hasn't changed it since then.
-#
 # bar@gdeps:=foo
 #     Static dependencies of bar, for checking by bar.g.
 #
@@ -145,24 +146,29 @@ $(opfx)%: $$(empty) $$($$(oid)@opr)
 # - Vpath
 
 # $(call gload,foo.o)
-# Make sure foo.o's genfile, if any, has been loaded.
+# Load foo.o's genfile, if any, into $(@cmd), etc.
 define gload
-$(if $($1@gloaded),,$(eval 
-$1@cmd:=
-$1@warnings:=
-$1@deps:=
+$(if $(filter $(@name),$1),,$(eval 
+# TODO: Store and check the version of mgear that wrote the genfile. 
+#@mgear-version:=
+@cmd:=
+@warnings:=
+@deps:=
 -include $1.g
-$1@gloaded:=1
+@name:=$1
 ))
 endef
+@name:=
 
 # bar.g: scout bar and its dependencies and store $?.  When implicit rules
 # compete for bar, we depend on the rule make uses being the last one it
 # second-expands so that $(bar@gdeps) is still correct.
 mg-genfile-oid:=$(newoid)
 mg-scout-oid:=$(newoid)
-$(mg-genfile-oid)@opr=$($(otgt:.g=)@gdeps) $(if $(wildcard $(otgt:.g=)),$(mg-scout-oid)$(aname)$(otgt:.g=),)
-$(mg-genfile-oid)@ocmd=$(eval $(otgt:.g=)@gq:=$?)
+$(mg-genfile-oid)@opr=$($(otgt:.g=)@gdeps) $(if $(wildcard $(otgt:.g=)),$(mg-scout-oid)$(aname)$(otgt:.g=),) MG-FORCE
+$(mg-genfile-oid)@ocmd=$(eval $(otgt:.g=)@gq:=$(filter-out MG-%,$?))
+$(mg-scout-oid)@opr:=
+$(mg-scout-oid)@ocmd:=
 
 # Mgear-ized automatic variables.
 # $@: needs no translation
@@ -249,18 +255,20 @@ define mg-rule-cmd
                $(mg-assign-cmd) >&3 &&\
                $(mg-maybe-move-target) &&\
                mv -f $@.g.tmp $@.g\
-       ,$(if $($@@warnings),\
-               $(info $($@@cmd) # mgear warning replay$(nl)$($@@warnings))\
+       ,$(if $(@warnings),\
+               $(info $1 # mgear warning replay$(nl)$(@warnings))\
        )))
 endef
 
 # If the command changed, we must regenerate.
-mg-check-cmd=$(if $(call streq,$1,$($@@cmd)),,COMMAND-CHANGED)
+# HMMM What if the working directory changes?  Most likely, the command will
+# also change and mgear will do the right thing. 
+mg-check-cmd=$(if $(call streq,$1,$(@cmd)),,COMMAND-CHANGED)
 
 # Pieces of mg-generate that I factored out to make mg-generate more readable.
-mg-assign-cmd=echo $(call sq,$(call fmt-make-assignment,$@@cmd,$1))
+mg-assign-cmd=echo $(call sq,$(call fmt-make-assignment,@cmd,$1))
 mg-run-cmd={ ($1) 2>&1 && { [ -r $@.tmp ] || { echo 'mgear: error: Command for $@ succeeded without creating it!'; false; }; }; }
-mg-wrap-warnings=sed -re '1s/^/$@@warnings:=$$(empty)/; 1!s/^/$@@warnings+=$$(nl)/'
+mg-wrap-warnings=sed -re '1s/^/@warnings:=$$(empty)/; 1!s/^/@warnings+=$$(nl)/'
 # Drat bash's lack of precedence between || and &&.  Extra braces necessary.
 mg-maybe-move-target={ cmp -s $@ $@.tmp || { echo >$@.g && mv -f $@.tmp $@; }; }
 
index a0dc8aa..8cb46a0 100755 (executable)
--- a/testsuite
+++ b/testsuite
@@ -32,7 +32,8 @@ function start_section {
 
 function do_mgear {
        echo "Running: make $*"
-       make "$@" 2>&1 | tee mgear.log
+       make --warn-undefined-variables "$@" 2>&1 | tee mgear.log
+       assert_not_saw 'warning: undefined variable'
 }
 
 function assert_contents {
@@ -49,8 +50,7 @@ function assert_saw {
        if grep -q "$@" mgear.log; then
                echo "Good, saw '${@:$#}' in build log."
        else
-               echo "Expected '${@:$#}' in build log but didn't see it!  Log:"
-               cat mgear.log
+               echo "Expected '${@:$#}' in build log but didn't see it!"
                fail
        fi
 }
@@ -58,8 +58,7 @@ function assert_not_saw {
        if ! grep -q "$@" mgear.log; then
                echo "Good, saw '${@:$#}' in build log."
        else
-               echo "Did not expect '${@:$#}' in build log but saw it!  Log:"
-               cat mgear.log
+               echo "Did not expect '${@:$#}' in build log but saw it!"
                fail
        fi
 }