如何通过通配子目录自动生成make目标列表?
我想使用一个 Makefile 在数百个子目录中生成目标。每个子目录都是一个日期/时间戳,如下所示:20120119_153957
,它与以下模式?????????_??????
匹配。没有其他子目录与此模式匹配。
我想生成的一个目标名为 ??????_??????/graph.pdf
。我有一个名为 make_graph
的脚本,它将根据给定的子目录名称生成图表。但我不确定如何编写一个 Makefile 来自动全局所有子目录并以编程方式生成这些目标。
例如,代码 SUBDIRS:=?????????_??????
似乎正确地全局显示了所有子目录。我可以检查这个规则:
.PHONY: print
print:
echo $(SUBDIRS)
但是这个变量分配
TARGETS:=$(SUBDIRS:%=%/graph.pdf)
似乎没有达到我的预期并分配了很多很多的目标。相反,以下规则仅打印一个目标。
.PHONY: print
print:
echo $(TARGETS)
令人困惑的是,SUBDIRS
应该具有正确的子目录,但 TARGET
只有一个文件。
I would like to use a single Makefile to generate targets in hundreds of subdirectories. Each subdirectory is a date/time stamp like this: 20120119_153957
, which matches the following pattern ????????_??????
. There are no other subdirectories that match this pattern.
One target I would like to generate is called ????????_??????/graph.pdf
. I have a script called make_graph
that will make the graph given the subdirectory name. But I'm not sure how to write a Makefile that will automatically glob all of the subdirectores and generate these targets programmatically.
For example, the code SUBDIRS:=????????_??????
seems to correctly glob all of the subdirectories. I can check with this rule:
.PHONY: print
print:
echo $(SUBDIRS)
However this variable assignment
TARGETS:=$(SUBDIRS:%=%/graph.pdf)
does not seem to do what I expect and assign lots and lots of targets. Instead the following rule just prints one target.
.PHONY: print
print:
echo $(TARGETS)
It is very confusing that SUBDIRS
should have the correct subdirectories but TARGET
only has one file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的示例中,全局匹配由 shell 执行。
GNU Make 具有内置的
通配符
函数 ,您可以按如下方式使用它:现在您可以使用此变量来构造目标列表:
另请参阅: 模式规则, 自动变量。
In your example glob matching is performed by the shell.
GNU Make has the built-in
wildcard
function, which you can use as follows:Now you can use this variable to construct a list of targets:
See also: pattern rules, automatic variables.