Disclaimer: this is not well tested by me. For example, I didn't read about defered and parse-time variable-evaluation yet.
Idea from http://stackoverflow.com/questions/1909188/define-make-variable-at-rule-execution-time.
Use an intermediate rule (or split up a rule in variable-init- and worker-parts):
.PHONY = use_2_vars
use_2_vars: FOO = foo
use_2_vars: BAR = $(shell echo bar)
use_2_vars: _use_2_vars
_use_2_vars:
@echo $(FOO)
@echo $(BAR)
print:
@echo $(FOO)
@echo $(BAR)
Things to note:
use_2_vars
) depends on a worker-rule (_use_2_vars
);
any actual work is done in the latterTesting this:
$ gmake use_2_vars
foo
bar
$ gmake print
$
I.o.w. both variables are set when the corresponding rule is executed, an are not set otherwise.