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 $(shell)
call executes as soon as my rule is match, as opposed to when it is encountered during execution.
The file is as follows:
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
It is impossible to know what the value of TMPDISK
will be until at least after the fallocate
call; that is why the $(eval)
statement is delayed until after the disk image is partitioned.
The output I receive is:
$ 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
The fact that partx
errors out (and thus TMPDISK
is set to empty) before any of the other commands execute makes me think that $(shell)
is called earlier than intended. Is there anyway to delay the shell call and the assignment to TMPDISK
until the appropriate line?