如何处理Makefile中动态检测到的未知依赖项? [英] How to handle unknown dependencies in Makefile that are dynamically detected?
问题描述
比方说我的Makefile正在建立一个网站.我写了一个包含资产的index.html
,如下所示:
Let's say my Makefile is building a website. I write a index.html
containing assets, like this:
<html>
<body><img src="asset/foo.img"/></body>
</html>
现在,我想编写一条规则来创建一个包含HTML及其资产的ZIP归档文件.
Now I want to write a rule to create a ZIP archive that contains the HTML as well as its assets.
我编写了一个脚本来解析src=
属性,但是该如何处理?
如果我将其放在配方中,但那时不能更改Makefile规则.
如果我将其放在$(shell ...)
命令中,那么即使用户正在执行clean
之类的命令,它也必须在每次Makefile解析时运行.
I write a script to parse out the src=
attributes, but what do I do with it?
If I put that in a recipe, but at that point the Makefile rules can't be changed.
If I put it in a $(shell ...)
command, then it will have to run every time the Makefile is parsed, even if the user is doing a clean
or something.
处理这种情况的正确方法是什么?
What is the proper way to handle such a scenario?
推荐答案
实际上,我认为自己已经知道了.解决方案是对$(MAKE)
的子调用-实际上,与include
相比,它的主要区别似乎是它在配方执行时而不是在解析时发生.
Actually I think I just figured it out myself. The solution is a sub-call to $(MAKE)
—in fact, its primary difference compared to include
seems to be the fact that it occurs at recipe execution time rather than at parse time.
这篇关于如何处理Makefile中动态检测到的未知依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!