GNU make:无论失败如何,都在所有其他目标之后运行目标?
我有一个包含一些生成一些数据的目标(例如 data1
到 dataN
,alldata
所依赖的目标)的 makefile,以及一个 prettify
目标迭代输出并创建漂亮的报告。 (注意:有很多 dataN
目标,并且 makefile 是机器生成的)
一些 dataX
目标偶尔会失败,但我想运行 prettify< /code> 无论如何,所以
pretify
不依赖于 alldata
。
有没有办法运行与 make -k alldata || 等效的方法在一次 make 调用中进行 prettify ,以便 make 尽最大努力构建所有数据,然后根据生成的内容构建我的报告?
I have a makefile with some targets (say data1
through dataN
, on which alldata
depends) that generate some data, and a prettify
target which iterates over the output and creates a pretty report. (note: there are lots of dataN
targets and the makefile is machine-generated)
Some of the dataX
targets occasionally fail, but I would like to run prettify
anyway, so prettify
doesn't depend on alldata
.
Is there a way to run the equivalent of make -k alldata || make prettify
in a single invocation of make such that make does a best-effort at building all the data, and then builds my report on whatever got made?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在 dataX 目标的配方前面加上“-”,
或者您可以列出 dataX 目标作为特殊目标的先决条件
.忽略
。You can prepend the recipes for the dataX targets with a ‘-’,
or you can list the dataX targets as prerequisites of the special target
.IGNORE
.您可以使用您喜欢的任何控制逻辑编写递归目标。这不会阻止某人从命令行运行目标,因此您无法强制执行您的逻辑,但这对于方便目标来说是很好的。也许是这样的:
You can write a recursive target with any control logic you like. This doesn't prevent someone from running a target from the command line, so you cannot enforce your logic, but it's nice for a convenience target. Something like this, maybe:
当命令失败时,Make 通常会退出。如果你在失败的命令后面加上“|| true”,make将继续执行,这意味着你的prettify也会被执行。
Make normally bails out when a command fails. If you put "|| true" behind the command that fails make will continue to execute, which means your prettify will also be executed.