将 glob 模式指定为 Makefile 目标

Specifying glob patterns as Makefile targets

我在 macOS High Sierra 版本 10.13.6 上的 make 版本如下所示:

$ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0

我的当前目录如下所示:

$ ls -1
Makefile
a.txt
b.txt
c.txt

我的 Makefile 看起来像这样:

*.txt: FORCE
        echo Target $@ invoked

FORCE:

我可以这样使用 Makefile

$ make a.txt
echo Target a.txt invoked
Target a.txt invoked
$ make b.txt
echo Target b.txt invoked
Target b.txt invoked
$ make c.txt
echo Target c.txt invoked
Target c.txt invoked

*.txt 扩展到当前目录中的匹配目标的这种行为记录在哪里?我尝试搜索手册页和文档,但找不到任何指定我们可以使用 glob 模式作为目标的内容。我可以在我的 Makefile 中依赖这种行为吗?

参见规则语法介绍中的GNU make manual

The targets are file names, separated by spaces. Wildcard characters may be used (see Using Wildcard Characters in File Names)

和整个部分 Using Wildcard Characters in File Names

您不能只看手册页:手册页仅描述了命令行界面和 makefile 语法的最简单摘要。他们不会试图描述有关如何编写 makefile 的所有内容。

如果您查看了 GNU make 手册但没有找到这个,我很想了解您搜索的内容以及您希望在哪里找到这些信息,以便我们考虑改进文档。