GNU make:执行目标,但从文件中获取依赖项 [英] GNU make: Execute target but take dependency from file

查看:104
本文介绍了GNU make:执行目标,但从文件中获取依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望执行目标的规则,但是所有从属目标都应将该目标视为已满足.

I want the rules of a target to be executed but all dependent targets shall regard this target as satisfied.

我该如何实现?

示例:

$(NETWORK_SHARE)/foo.log:
    @echo Warning: server offline, still continue ...
    @exit 0

foo.csv: $(NETWORK_SHARE)/foo.log
    @echo Long export from a (different) server
    @echo sleep 20
    @echo foo > $@

如果$(NETWORK_SHARE)/foo.log存在:如果$(NETWORK_SHARE)/foo.log比foo.csv更新,则应重建foo.csv.否则什么都不会发生(默认)

If $(NETWORK_SHARE)/foo.log exists: foo.csv shall be rebuilt if $(NETWORK_SHARE)/foo.log is newer than foo.csv; otherwise nothing should happen (default)

如果$(NETWORK_SHARE)/foo.log不存在(例如,服务器脱机,故障等),则仅打印一条指示问题的消息,而仅当foo.csv不存在时才构建foo.csv.存在.

If $(NETWORK_SHARE)/foo.log does not exist (e.g., server offline, failure, ...) only a message indicating a problem should be printed but foo.csv shall only be built if foo.csv does not exist.

我一直在玩.PHONY并返回不同的返回值,但是对于情况2,一旦我在$(NETWORK_SHARE)/foo.log上执行某些操作,就会发生昂贵的导出" ...

I played around with .PHONY and returning different return values but for case 2, the expensive "export" happens as soon as I execute something on $(NETWORK_SHARE)/foo.log ...

问候 divB

推荐答案

很好,多亏了与我相关的 Thiton的答案问题(强制进行查找过时的条件来自文件),我现在可以提供一个解决方法:

Great, thanks to Thiton's answer in my related question (Force make to find out-of-date condition from file) I can now provide a hack to solve this:

.PHONY: always-remake

NETWORK_SHARE = //server/dfs/common/logs

.PHONY: all
all: foo.csv

# file does not exist ...
ifeq "$(wildcard $(NETWORK_SHARE)/foo.log)" ""

old_file: always-remake
    @echo Warning: network is not available ....

foo.csv: old_file
    @echo Expensive export
    @sleep 10
    @echo $@ > $@
else
foo.csv: $(NETWORK_SHARE)/foo.log
    @echo Doing expensive export since log file changed ...
    @sleep 10
    @echo $@ > $@
endif

"old_file"是一个虚拟文件,该文件必须存在,并且永远不能比任何其他文件都要新(例如1/1/1971,00:00)

"old_file" is a dummy file which must exist and should never be newer than any other file (e.g. 1/1/1971, 00:00)

问候 divB

这篇关于GNU make:执行目标,但从文件中获取依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆