如何在 Makefile 中使模式规则依赖项成为可选? [英] How can I make a pattern rule dependency optional in a Makefile?

查看:22
本文介绍了如何在 Makefile 中使模式规则依赖项成为可选?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想引用依赖项的时间戳当且仅当文件已经存在.我有这样的模式规则:

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 make 你可以使用:

With a sufficiently new version of GNU make you can use:

.SECONDEXPANSION:
%.pdf: %.sil $$(wildcard $$*.lua)
        sile $< -o $@

请参阅SECONDEPANSION 目标的手册部分和通配符函数.

这篇关于如何在 Makefile 中使模式规则依赖项成为可选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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