如何使“%”通配符匹配包含等号的目标?

How to make "%" wildcard match targets containing the equal sign?

makefile 通配符系统似乎无法匹配包含等号的目标。有没有办法解决这个缺陷?一些标志或设置或规则来逃避等号?我知道我不能使用等号,但如果可能的话,我更愿意修复 make 的这种特性。

这是我的意思的一个例子

$ cat Makefile
all:
    echo Dummy target
b_%:
    echo $@

$ make b_c=1
  echo Dummy Target
$ make b_c1
  echo b_c1       

第一个 make 命令不匹配 b_%,尽管它应该匹配。我也无法找到 % 通配符应该匹配的确切内容的文档。任何指针?我的制作版本是

$ make --version                                               
GNU Make 3.81         
Copyright (C) 2006  Free Software Foundation, Inc.                                                                                                             
This program built for i386-apple-darwin10.0                         

这里的问题不在于 % 语法,而在于 any command-line argument with an equals sign in it is interpreted as a variable assignment.

你应该会发现,如果你添加依赖项 all: b_c=1,那么 make all 将生成文件。

可用于 make 的文件名有限制——它们不能包含空格或换行符,例如反斜杠也有问题(尽管对于简单的用例来说并非完全不可能)。

如果您绝对需要一个这样命名的文件,我建议的解决方法是在内部使用不同的名称,然后将其符号链接到外部名称作为 make 方法的最后一步。