-# Mage Build Tool by Matt McCutchen
-# http://www.kepreon.com/~matt/mage/
+# Mgear Build Tool by Matt McCutchen
+# http://www.kepreon.com/~matt/mgear/
-# Remember the original default goal so we can restore it at the end of mage.mk.
+# Remember the original default goal so we can restore it at the end of mgear.mk.
mg-orig-default-goal:=$(.DEFAULT_GOAL)
# We use second-expansion heavily to dynamically compute prerequisites when they
# TARGET OBFUSCATION
-# Mage uses two kinds of "obfuscated targets" (those that are not the simple
+# Mgear uses two kinds of "obfuscated targets" (those that are not the simple
# names of real files):
# - An always-exists target like /.//. is used as a prerequisite of an implicit
# rule. Since it exists, make doesn't second-expand its own prerequisites
# information about how bar was generated, including the command (for rebuild on
# command change) and the warnings (for replay).
#
-# - bar.g's mtime is the last time Mage verified that bar was up to date. bar
+# - bar.g's mtime is the last time mgear verified that bar was up to date. bar
# needs to be regenerated iff a prerequisite is newer than *bar.g* (not bar).
# If a prerequisite changes but the command gives the same contents for bar,
# bar.g is touched but bar itself is not touched because files that depend on it
# - If bar is newer than bar.g, the user has overridden it, and we should leave
# the override in place but warn the user about it.
#
-# - The user's Makefile defines Mage rules by calling mg-define-rule. Each Mage
-# rule becomes one underlying make rule with the same target and a little extra
-# magic. This is important so that all implicit rule competition takes place at
-# the same target. Additionally, the prerequisites are passed to an obfuscated
-# target for bar.g to see if any are newer than bar.g. This is done by the
-# single obfuscated implicit rule, keeping the number of implicit rules low.
-# Then the command script for bar checks for overrides, command change,
+# - The user's Makefile defines mgear rules by calling mg-define-rule. Each
+# mgear rule becomes one underlying make rule with the same target and a little
+# extra magic. This is important so that all implicit rule competition takes
+# place at the same target. Additionally, the prerequisites are passed to an
+# obfuscated target for bar.g to see if any are newer than bar.g. This is done
+# by the single obfuscated implicit rule, keeping the number of implicit rules
+# low. Then the command script for bar checks for overrides, command change,
# prerequisite change, etc. and acts accordingly.
#
# Target metadata variables for bar: (* means stored in bar.g)
# 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.
+# 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.
# $? from the rule for bar.g; used by the rule for bar.
#
# bar@checked:=1
-# Set when Mage determines that a file is up to date or depends on it being
+# Set when mgear determines that a file is up to date or depends on it being
# so determined. Used to decide which prerequisite to check next for a
# dependency-logging command.
#
# bar@dlc-ran:=1
-# Indicates that Mage is in the middle of building bar using a dependency-
+# Indicates that mgear is in the middle of building bar using a dependency-
# logging command. Means that bar.g.tmp, not bar.g, is the most current
# genfile.
#
## 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. -- Not currently needed
#
-# Some make features with which Mage's compatibility has not been investigated:
+# Some make features with which mgear's compatibility has not been investigated:
# - Command-line options (especially --dry-run, --question, --touch,
# --always-make, --keep-going, --jobs, --assume-old, and --assume-new)
# - Static pattern rules
$(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:=$?)
-# Mage-ized automatic variables.
+# Mgear-ized automatic variables.
# $@: needs no translation
# NOTE: $(mg@) is *eventual* target. Commands must write to temp file, $t .
# $%: haven't thought about it much, but probably needs no translation
# $*: needs no translation
# $(call mg-translate-cmd,cat $$< >$$t)
-# Replaces references to automatic variables with references to their Mage-ized
+# Replaces references to automatic variables with references to their mgear-ized
# counterparts. There might be false matches, e.g., $$@ => $$(mg@) ;
# to prevent that, write $$$(empty)@ instead. (c.f. autoconf empty quadrigraph)
mg-translate-cmd=$(subst $$t,$$@.tmp,$(subst $$?,$$(mg?),$(subst $$<,$$(mg<),$(subst $$^,$$(mg^),$(subst $$+,$$(mg+),$1)))))
# $(call mg-define-rule,target,prerequisites,cmd)
# Defines a rule. cmd is expanded again when it is run, at which time
-# Mage-ized automatic variables are available.
+# Mgear-ized automatic variables are available.
#
# I eradicated the target-specific variables because they fail when there are
# multiple implicit rules with the same target pattern.
# HMMM .tmp in displayed command looks ugly
define mg-rule-cmd
$(if $(filter $(mg-scout-oid)$(aname)$@,$($@@gq)),\
- $(info Mage: warning: Manually created/modified file at $@ overrides rule.)\
+ $(info mgear: warning: Manually created/modified file at $@ overrides rule.)\
,$(call gload,$@)$(if $($@@gq)$(if $(wildcard $@),,TARGET-DNE)$(mg-check-cmd),\
$(eval $@@gloaded:=)$(info $1)\
@trap 'rm -f $@.tmp $@.g.tmp' EXIT &&\
$(mg-maybe-move-target) &&\
mv -f $@.g.tmp $@.g\
,$(if $($@@warnings),\
- $(info $($@@cmd) # Mage warning replay$(nl)$($@@warnings))\
+ $(info $($@@cmd) # mgear warning replay$(nl)$($@@warnings))\
)))
endef
# 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-run-cmd={ ($1) 2>&1 && { [ -r $@.tmp ] || { echo 'Mage: error: Command for $@ succeeded without creating it!'; false; }; }; }
+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)/'
# Drat bash's lack of precedence between || and &&. Extra braces necessary.
mg-maybe-move-target={ cmp -s $@ $@.tmp || { echo >$@.g && mv -f $@.tmp $@; }; }
# Just add additional prerequisites. This cannot add prerequisite patterns to
# an implicit rule, but it can add specific prerequisites to an individual use
-# of an implicit rule. Currently, Mage picks up the target's prerequisites from
-# make, so this just attaches the given prerequisites to the target, but the
-# implementation might change in the future.
+# of an implicit rule. Currently, mgear picks up the target's prerequisites
+# from make, so this just attaches the given prerequisites to the target, but
+# the implementation might change in the future.
mg-define-prereq=$(eval $1: $2)
#!/bin/bash
-# Test suite for Mage.
+# Test suite for mgear.
-echo "Test suite for Mage"
+echo "Test suite for mgear"
cd "$(dirname "$0")"
Z=test-zone
trap 'echo; echo "TEST SUITE FAILED in section $section!" >&2' ERR
#set -x
-ln -s ../mage.mk mage.mk
+ln -s ../mgear.mk .
function fail {
false
echo "SECTION: $1"
}
-function do_mage {
+function do_mgear {
echo "Running: make $*"
- make "$@" 2>&1 | tee mage.log
+ make "$@" 2>&1 | tee mgear.log
}
function assert_contents {
# Options can be passed to grep: assert_saw -i override
function assert_saw {
- if grep -q "$@" mage.log; then
+ 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 mage.log
+ cat mgear.log
fail
fi
}
function assert_not_saw {
- if ! grep -q "$@" mage.log; then
+ 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 mage.log
+ cat mgear.log
fail
fi
}
# Tests an implicit rule and two competing explicit rules.
# Watch those dollar signs!
cat >Makefile <<'EOF'
-include mage.mk
+include mgear.mk
.SECONDARY:
include hc-rule.mk
$(call mg-define-rule,%,%.ssc,sleep 1 && grep 'warn' $$< && sed -e 's_//.*$$$$__' $$< >$$t)
# Run and make sure the files were compiled correctly.
start_section "Initial full build"
-do_mage foo bar index
+do_mgear foo bar index
assert_contents foo <<'EOF'
This is the foo file.
# to bar.g accidentally being too old.
start_section "Replay bar warning"
-do_mage foo bar index
+do_mgear foo bar index
assert_uptodate foo
assert_uptodate bar
start_section "Override bar"
sleep 1 # No racy cleanliness
echo NEWCONTENT >bar
-do_mage bar
+do_mgear bar
assert_saw -i overrid
assert_contents bar <<<NEWCONTENT
start_section "Change foo.hc"
sleep 1 # No racy cleanliness
echo 'look: # Last-minute addition.' >>foo.hc
-do_mage index foo
+do_mgear index foo
assert_uptodate index
assert_generated foo
cat >hc-rule.mk <<'EOF'
$(call mg-define-rule,%,%.hc,sed -e 's_ *#.*$$$$__' $$< >$$t)
EOF
-do_mage foo
+do_mgear foo
assert_generated foo
assert_contents foo <<'EOF'
sleep 1 # No racy cleanliness
remember_mtime foo foo.g
sed -e '$s/look: /look:/' -i foo.hc
-do_mage foo
+do_mgear foo
assert_generated foo
assert_touched foo.g