title: Define make variable at rule execution time
body: <p>In my GNUmakefile, I would like to have a rule that uses a temporary directory.  For example:</p>
  
  <pre><code>out.tar: TMP := $(shell mktemp -d)
          echo hi $(TMP)/hi.txt
          tar -C $(TMP) cf $@ .
          rm -rf $(TMP)
  </code></pre>
  
  <p>As written, the above rule creates the temporary directory at the time that the rule is <em>parsed</em>.  This means that, even I don't make out.tar all the time, many temporary directories get created.  I would like to avoid my /tmp being littered with unused temporary directories.</p>
  
  <p>Is there a way to cause the variable to only be defined when the rule is fired, as opposed to whenever it is defined?</p>
  
  <p>My main thought is to dump the mktemp and tar into a shell script but that seems somewhat unsightly.</p>