有没有办法定义自定义隐式GNU制定规则?
我经常从dot
(GraphViz格式)文件中创建png
文件。这样做的命令如下:
$ dot my_graph.dot -o my_graph.png -Tpng
但是,我希望能够像$ make my_graph.dot.dot
一样,能够自动生成我的png文件。
目前,我正在使用一个我定义以下规则的makefile,但是该配方仅在包含makefile
%.eps: %.dot
dot $< -o $@ -Teps
的目录中可用,是否可以定义自定义隐式gnu制作配方?哪个将允许上述食谱在系统范围内可用
如果不是,您可以使用哪种解决方案来解决这些问题?
设置:
- 带有ZSH/bash的Fedora Linux
I'm often creating png
files out of dot
(graphviz format) files. The command to do so is the following:
$ dot my_graph.dot -o my_graph.png -Tpng
However, I would like to be able to have a shorter command format like $ make my_graph.dot
to automatically generate my png file.
For the moment, I'm using a Makefile in which I've defined the following rule, but the recipe is only available in the directory containing the Makefile
%.eps: %.dot
dot lt; -o $@ -Teps
Is it possible to define custom implicit GNU Make recipes ? Which would allow the above recipe to be available system-wide
If not, what solution do you use to solve those kind of problem ?
Setup:
- Fedora Linux with ZSH/Bash
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在Shell的启动文件中定义shell函数,例如
,可以称呼此功能,例如
或
代码
$ {1%.dot} .dot
strips.dot
。在文件名中,如果存在并将其附加(再次)允许my_graph.dot
和my_graph
作为函数参数。You could define shell functions in your shell's startup files, e.g.
This function can be called like
or
The code
${1%.dot}.dot
strips.dot
from the file name if present and appends it (again) to allow bothmy_graph.dot
andmy_graph
as function argument.并非不需要修改GNU制造的源代码。
我不会在全球范围内对系统进行Modyfyfy,但是您可以这样做:
使用内容
创建一个文件
创建一个文件
Use
include /usr/local/lib/make/myimplicitrules.make
in您的makefile。我宁愿使用git subsodule或类似的项目之间共享项目之间的共同配置,而不是根据全局配置。取决于全球环境,您的计划难以测试和不可支配。
我宁愿使用外壳功能,还有一些事情:
Not without modifying the source code of GNU Make.
I wouldn't be a fan o modyfying the system globally, but you could do:
Create a file
/usr/local/lib/make/myimplicitrules.make
with the contentUse
include /usr/local/lib/make/myimplicitrules.make
in your Makefile.I would rather use a git submodule or similar to share common configuration between projects, rather than depending on global configuration. Depending on global environment will make your program hard to test and non-portable.
I would rather go with a shell function, something along:
GNU使您可以使用
makefiles
指定额外的makefiles读取环境变量。引用
info'(make)makefiles变量'
:例如,当前目录中没有makefile,
以下
.mk
make
s include路径(例如,通过makeflags = - include-dir =“ $ home”/。local/lib/make/
)您可以创建subdir
gen/
和convertmy_graph.dot
或dot/my_graph.dot
by by运行:
为了进一步保存一些打字,它很容易添加
makefiles = dot.mk
在会话环境中,但在启动文件中定义
makefiles
可以使事情完全不透明。因此,我更喜欢
在命令行上查看
makefiles =…
。文件:
dot.mk
包括
common.mk
是您将常规定义存储到的位置管理目录创建,诊断等,例如
参考:
?=
=
:=
… -info'(make)读取makefiles'
vpath
-info'(make)选择性搜索'
| $(gendir)。
) - <代码> info'(make)先决条件类型'.precious
-info'(make)链式规则'
GNU Make lets you specify extra makefiles to read using the
MAKEFILES
environment variable. Quoting from
info '(make)MAKEFILES Variable'
:As an example, with no makefile in the current directory and the
following
.mk
files inmake
's include path (e.g. viaMAKEFLAGS=--include-dir="$HOME"/.local/lib/make/
) you can createsubdir
gen/
and convertmy_graph.dot
ordot/my_graph.dot
byrunning:
To further save some typing it's tempting to add
MAKEFILES=dot.mk
to a session environment but defining
MAKEFILES
in startup filescan make things completely nontransparent. For that reason I prefer
seeing
MAKEFILES=…
on the command line.File:
dot.mk
The included
common.mk
is where you'd store general definitions tomanage directory creation, diagnostics etc., e.g.
References:
?=
=
:=
… -info '(make)Reading Makefiles'
vpath
-info '(make)Selective Search'
| $(genDir).
) -info '(make)Prerequisite Types'
.PRECIOUS
-info '(make)Chained Rules'