Rewrite the Mage basics, temporarily removing the dependency-logging command
[mgear/mgear.git] / experiments / prereq-predict.mk
diff --git a/experiments/prereq-predict.mk b/experiments/prereq-predict.mk
new file mode 100644 (file)
index 0000000..8ea4514
--- /dev/null
@@ -0,0 +1,32 @@
+.SECONDEXPANSION:
+
+#dir/x.foo:
+
+#ding=$(@:.foo=.bar)
+#
+#%.foo: $$(info got here) /./proc/self/cwd/$$(ding)
+#      echo "Prerequisites: $^"
+#
+#%.bar:
+#      echo "We want $@"
+
+# $(call save-and-use,/,prereqs)
+#save-and-use=$(eval $@=$(if $1,$2,$(foreach p,$2,$(dir $@)$p)))$2
+
+pr1=$(info in pr1, $$@ is $@)$(eval $@@gdeps:=$(subst %,$*,$1))$1
+pr2=$(info in pr2, $$@ is $@)$(eval $@@gdeps:=$(addprefix $(dir $@),$(subst %,$*,$1)))$1
+
+FORCE:
+
+define define-rule
+$(eval 
+$1: $(if $(findstring /,$1),$$$$(call pr1,$2),$$$$(call pr2,$2)) FORCE
+       $$(info +++ $$$$^ is $$^, gdeps is $$($$@@gdeps))
+)
+endef
+
+$(call define-rule,%.foo,%.bar)
+
+x/%.bar:
+       $(info +++ Making $@)
+