Makefile 模式规则有效,但后缀规则无效';T

Makefile 模式规则有效,但后缀规则无效';T,makefile,posix,gnu-make,Makefile,Posix,Gnu Make,模式规则起作用: $ ls Makefile hello.txt world.txt $ cat Makefile all: hello.out world.out %.out: %.txt cp $< $@ $ make cp hello.txt hello.out cp world.txt world.out $ls Makefile hello.txt world.txt $cat生成文件 大家好,我们的世界,我们的世界 %.out:%.txt cp$

模式规则起作用:

$ ls
Makefile   hello.txt  world.txt
$ cat Makefile
all: hello.out world.out

%.out: %.txt
        cp $< $@

$ make
cp hello.txt hello.out
cp world.txt world.out
$ls
Makefile hello.txt world.txt
$cat生成文件
大家好,我们的世界,我们的世界
%.out:%.txt
cp$<$@
$make
cp hello.txt hello.out
cp world.txt world.out
但是,当我试图用我认为完全等效的后缀规则替换它们时,它们不起作用:

$ ls
Makefile   hello.txt  world.txt
$ cat Makefile
.POSIX:
.SUFFIXES:
.SUFFIXES:.txt.out

all: hello.out world.out

.txt.out:
        cp $< $@

$ make
make: *** No rule to make target 'hello.out', needed by 'all'.  Stop.
$ls
Makefile hello.txt world.txt
$cat生成文件
.POSIX:
.后缀:
.后缀:.txt.out
大家好,我们的世界,我们的世界
.txt.out:
cp$<$@
$make
make:**没有规则将目标设置为“hello.out”,这是“all”所需的。停止

我不明白为什么。

这一行就是问题所在:

.SUFFIXES: .txt.out
它声明了一个后缀,
.txt.out
,而不是其中的两个。您可以将其更改为:

.SUFFIXES: .txt .out

旁注:除非您需要支持Make的古老版本,
后缀
已经过时,您可以只使用模式规则。@user657267:否。您应该始终使用解决问题的最小子集。