How can I make a pattern rule dependency optional in a Makefile?

≡放荡痞女 提交于 2019-12-01 16:16:45

问题


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 $@

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?

This:

%.pdf: %.sil %.lua
    sile $< -o $@

…only works for cases where the file exists and causes an error if it doesn't.


回答1:


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

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

See the manual section for SECONDEXPANSION targets and the wildcard function.



来源:https://stackoverflow.com/questions/34105205/how-can-i-make-a-pattern-rule-dependency-optional-in-a-makefile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!