Define make variable at rule execution time
In your example, the TMP variable is set (and the temporary directory created) whenever the rules for out.tar are evaluated. In order to create the directory only when out.tar is actually fired, you need to move the directory creation down into the steps: out.tar : $(eval TMP := $(shell mktemp -d)) @echo hi $(TMP)/hi.txt tar … Read more