我希望优化现有的 Makefile。它用于为给定目录中的每个日志文件创建多个图(使用 Octave),使用脚本文件为每个以日志文件名作为参数的图创建多个图。目前,我对每种可用的绘图使用一个规则,并手写调用 Octave,将特定的脚本文件/日志文件作为参数。
如果每个图都有“他的”八度脚本作为依赖项(当然还有日志文件),那就太好了,这样如果他的脚本发生更改,则只重新生成一个图。
因为我不想输入那么多,所以我想知道如何通过仅使用一个一般规则来构建“a”图来简化这一点?
为了更清楚:
- 日志文件:“$(LOGNAME).log”
- 脚本文件:“plot$(PLOTNAME).m”创建“$(LOGNAME)_$(PLOTNAME).png”
我想到的第一件事是:
%1_%2.png: %1.log
$(OCTAVE) --eval "plot$<2('$<1')"
但是这个似乎不允许。有人可以给我提示吗?
I looking to optimize an existing Makefile. It's used to create multiple plots (using Octave) for every logfile in a given directory using an scriptfile for every plot which takes a logfilename as an argument. In the Moment, I use one single rule for every kind of plot available, with a handwritten call to Octave, giving the specific scriptfile/logfile as an argument.
It would be nice, if every plot has "his" octave-script as a dependency (plus the logfile, of course), so only one plot is regenerated if his script is changed.
Since I don't want to type that much, I wonder how I can simplifiy this by using only one general rule to build "a" plot?
To make it clearer:
- Logfile: "$(LOGNAME).log"
- Scriptfile: "plot$(PLOTNAME).m" creates "$(LOGNAME)_$(PLOTNAME).png"
The first thing I had in mind:
%1_%2.png: %1.log
$(OCTAVE) --eval "plotlt;2('lt;1')"
But this seems not to be allowed. Could someone give me a hint?
发布评论
评论(2)
make 不直接支持这个真是太疯狂了,我一直需要它。
我目前使用的技术(使用 GNU make)(基于 Didier Trosset 的示例):
这是 GNU make 文档。
It's pretty crazy that make doesn't support this directly, I need it all the time.
The technique I use at the moment (with GNU make) (building on Didier Trosset's example):
This is in the GNU make documentation.
模式规则只能使用 1 个模式(即不能使用
%1
和%2
,只能使用%
)。因此,根据您拥有的
PLOTNAME
和LOGNAME
的数量,选择最小的并根据需要编写尽可能多的模式规则。如果您不想编写与不同绘图(或日志)一样多的规则,则可以使用双 Makefile 机制。在子 Makefile 中,使用上述命令,但使用绘图名称参数。在主 Makefile 中,使用所需的绘图名称的各种值来调用它。
Makefile.sub:
Makefile:
它可以节省多次编写规则的时间(并节省在需要时多次更新规则的时间),但随后需要对
all
之外的其他目标进行特殊处理,例如clean< /代码>。
Pattern rules can use only 1 pattern (i.e. you cannot have
%1
and%2
, just%
).Therefore, depending on the number of
PLOTNAME
andLOGNAME
you have, choose the smallest and write as many pattern rules as needed.If you do not want to write as many rules as you have different plots (or logs), you can use a double Makefile mechanism. In the sub-Makefile, use the above command, but use a parameter for the plot name. In a master Makefile, call it with the various values of the plotname you want.
Makefile.sub:
Makefile:
It saves writing the rule many times (and saves updating it as many times when needed), but then requires special handling for other targets than
all
, such asclean
.