title: Makefile Variable Assignment Executes Early
body: <p>I have a Makefile rule that requires storing the results from shell commands into variables for later use.  For some reason, it seems that the <code>$(shell)</code> call executes as soon as my rule is match, as opposed to when it is encountered during execution.</p>
  
  <p>The file is as follows:</p>
  
  <pre><code>TMPDEV=/tmp/disk.img
  
  $(TMPDEV):
          fallocate -l 806354944 $(TMPDEV)
          sudo parted --script $(TMPDEV) unit s mklabel msdos \
            mkpart primary fat16 2048 526335 \
            mkpart primary fat32 526336 1050623 \
            mkpart primary NTFS 1050624 1574911 \
            quit
          $(eval TMPDISK := $(shell sudo partx --verbose -a $(TMPDEV) | tail -1 | cut -d':' -f1))
          echo $(TMPDISK)
          sudo mkfs.fat -F 16 -n FAT16 $(TMPDISK)p1
  </code></pre>
  
  <p>It is impossible to know what the value of <code>TMPDISK</code> will be until at least after the <code>fallocate</code> call; that is why the <code>$(eval)</code> statement is delayed until after the disk image is partitioned.</p>
  
  <p>The output I receive is:</p>
  
  <pre><code>$ make
  partx: stat failed /tmp/disk.img: No such file or directory
  fallocate -l 806354944 /tmp/disk.img || dd if=/dev/zero of=/tmp/disk.img bs=1b count=1574912
  sudo parted --script /tmp/disk.img unit s mklabel msdos \
    mkpart primary fat16 2048 526335 \
    mkpart primary fat32 526336 1050623 \
    mkpart primary NTFS 1050624 1574911 \
    quit
  echo
  </code></pre>
  
  <p>The fact that <code>partx</code> errors out (and thus <code>TMPDISK</code> is set to empty) before any of the other commands execute makes me think that <code>$(shell)</code> is called earlier than intended.  Is there anyway to delay the shell call and the assignment to <code>TMPDISK</code> until the appropriate line?</p>