[英]Makefile Target Dependency on Whether Target Already Exists
I am trying to write a Makefile whose targets depend on the existence of a disk file. 我正在尝试编写一个Makefile,其目标取决于磁盘文件的存在。 The disk file itself merely needs to be created;
磁盘文件本身仅需要创建; it does not depend on any other actions that may update it.
它不依赖于可能会更新它的任何其他操作。 If I do not give it any dependencies, the file is re-created every time I run make on one of the targets.
如果我不给它任何依赖关系,则每次在其中一个目标上运行make时都会重新创建该文件。
Is there a way to have a target depend on whether it exists? 有没有一种方法可以使目标取决于目标是否存在?
This is part of the Makefile I have. 这是我拥有的Makefile的一部分。 The
$(TMPDEV)
file only needs to be created if it doesn't exist, otherwise it should be considered up-to-date. 仅当
$(TMPDEV)
文件不存在时才需要创建它,否则应将其视为最新文件。
TMPDEV="/tmp/disk.img"
$(TMPDEV):
fallocate -l 806354944 $(TMPDEV) || dd if=/dev/zero of=$(TMPDEV) bs=1b count=1574912
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))
sudo mkfs.fat -F 16 -n FAT16 $(TMPDISK)p1
sudo mkfs.fat -F 32 -n FAT32 $(TMPDISK)p2
sudo mkfs.ntfs -L NTFS $(TMPDISK)p3
sudo partx -d $(TMPDISK)
sudo losetup -d $(TMPDISK)
testresults: $(TMPDEV)
touch testresults
analytics: $(TMPDEV)
touch analytics
Remove the quotes: 删除引号:
TMPDEV="/tmp/disk.img"
Make doesn't use/need quotes. Make不使用/不需要引号。 You are saying that the target here:
您是在说目标:
$(TMPDEV):
is, literally, this file including the quotes: 从字面上看,该文件包括引号:
"/tmp/disk.img":
that file never exists, so the rule is always re-run. 该文件永远不存在,因此该规则始终会重新运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.