make:为多个文件的多个目标调用命令? [英] make: invoke command for multiple targets of multiple files?

查看:134
本文介绍了make:为多个文件的多个目标调用命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望优化现有的Makefile.它用于为给定目录中的每个日志文件创建一个脚本(使用Octave),并为每个脚本创建一个脚本文件,该脚本文件将日志文件名作为参数.在当下,我对每种可用图使用一条规则,并手写调用Octave,并给出特定的脚本文件/日志文件作为参数.

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.

由于我不想输入太多内容,所以我想知道如何仅使用一条通用规则来构建"a"图来简化这一点?

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?

更清晰地说:

  • 日志文件:"$(LOGNAME).log"
  • 脚本文件:"plot $(PLOTNAME).m"创建了"$(LOGNAME)_ $(PLOTNAME).png"

我想到的第一件事:

%1_%2.png: %1.log
    $(OCTAVE) --eval "plot$<2('$<1')"

但这似乎是不允许的.有人可以给我一个提示吗?

But this seems not to be allowed. Could someone give me a hint?

推荐答案

make不直接支持它非常疯狂,我一直都需要它.

It's pretty crazy that make doesn't support this directly, I need it all the time.

我目前使用的技术(与GNU make一起使用)(以Didier Trosset的示例为基础):

The technique I use at the moment (with GNU make) (building on Didier Trosset's example):

define OCT_template

all: %_$(1).png

%_$(1).png: %.log
    $$(OCTAVE) --eval "plot$(1)('$$*')"

endef

PLOT_NAMES = plot1 plot2 plot3

$(foreach p, $(PLOT_NAMES), \
  $(eval $(call OCT_template,$(p))) \
)

这是GNU make文档中的 .

This is in the GNU make documentation.

这篇关于make:为多个文件的多个目标调用命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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