有没有办法定义全局 Makefile(隐式)规则?

Is there a way to define global Makefile (implicit) rules?

即使目录中没有 Makefile,我也可以通过 运行 make test 编译一个 c 程序 test.c。那是因为 make 有 built-in implicit rules.

我想对 LaTeX 文件做同样的事情。我想在目录中没有 Makefile 的情况下键入 make test.pdf,make 将搜索 test.tex 并构建 pdf。

我已经知道如何定义pattern rules。我想知道是否可以定义全局模式规则,这样我就不需要将 Makefile 复制到任何有 Tex 文件的地方。

您可以定义名为 MAKEFILES 的环境变量,它将列出隐式包含的 Makefile。那会做你想要的,例如:

$ ls
foo.tex  implicit.mk

$ make foo.pdf
make: *** No rule to make target 'foo.pdf'.  Stop.

$ cat implicit.mk
%.pdf: %.tex
        echo Make $@ from $<

$ export MAKEFILES=implicit.mk
$ make -s foo.pdf
Make foo.pdf from foo.tex