问题描述
仅当文件已经存在时,我想引用依赖项的时间戳.我有一个这样的模式规则:
I would like make to reference the timestamp of a dependency if and only if the file already exists. I have a pattern rule like this:
%.pdf: %.sil
sile $< -o $@
这在正常情况下效果很好,但是.sil文件在外部引用了具有相同名称的lua文件(如果存在).我该如何意识到这一点,如果lua文件较新,它将检查时间戳并重新生成PDF,但是如果该文件根本不存在,它将忽略依赖关系?
This works great in normal situations, but the .sil file makes an external reference to a lua file of the same name if it exists. How do I make make aware of this so it checks the timestamps and regenerates the PDF if the lua file is newer but ignores the dependency if the file doesn't exist at all?
此:
%.pdf: %.sil %.lua
sile $< -o $@
…仅适用于文件存在的情况,如果不存在则导致错误.
…only works for cases where the file exists and causes an error if it doesn't.
推荐答案
有了足够新的GNU版本,您可以使用:
With a sufficiently new version of GNU make you can use:
.SECONDEXPANSION:
%.pdf: %.sil $$(wildcard $$*.lua)
sile $< -o $@
有关 SECONDEXPANSION目标,请参见手册部分通配符功能.
See the manual section for SECONDEXPANSION targets and the wildcard function.
这篇关于如何在Makefile中将模式规则依赖项设为可选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!