gpt4 book ai didi

仅当文件不存在时,Makefile 才执行文件的 phonytargets

转载 作者:行者123 更新时间:2023-12-04 04:07:15 25 4
gpt4 key购买 nike

有什么办法我只能执行文件的虚假依赖
如果这个文件不存在?

如果文件没有虚假的依赖,它就可以工作并且只执行内容
这条规则的。但是,如果我添加一个虚假目标作为依赖项,它会继续执行依赖项规则和生成现有文件的规则。

我简化了我的 Makefile 以便您可以看到我的问题:


.PHONY: phonytarget all clean

all: $(CURDIR)/a.a
@echo done

$(CURDIR)/a.a: phonytarget
@touch $@

phonytarget:
@echo what the heck is wrong with you

最佳答案

使用 order-only prerequisites :

Occasionally, however, you have a situation where you want to impose a specific ordering on the rules to be invoked without forcing the target to be updated if one of those rules is executed. In that case, you want to define order-only prerequisites. Order-only prerequisites can be specified by placing a pipe symbol (|) in the prerequisites list: any prerequisites to the left of the pipe symbol are normal; any prerequisites to the right are order-only:

targets : normal-prerequisites | order-only-prerequisites

The normal prerequisites section may of course be empty. Also, you may still declare multiple lines of prerequisites for the same target: they are appended appropriately (normal prerequisites are appended to the list of normal prerequisites; order-only prerequisites are appended to the list of order-only prerequisites).

.PHONY: phonytarget all clean

all: $(CURDIR)/a.a
@echo done

$(CURDIR)/a.a: | phonytarget
@touch $@

phonytarget:
@echo what the hack is wrong with you

关于仅当文件不存在时,Makefile 才执行文件的 phonytargets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9007039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com