为.SUFFIXES 定义先决条件会添加到已知后缀列表中。它不会删除已知的后缀。作为一种例外,如果您为 .SUFFIXES 定义一个没有任何先决条件的规则,您将取消所有隐式规则:
$ cat Makefile
.SUFFIXES:
foo.c:
touch $@
$ rm -f foo.* ; make foo.o
make: *** No rule to make target `foo.o'. Stop.
注意:要仅取消使.o 从.c 的隐式规则,还可以添加不带配方的模式规则:
%.o: %.c
关于MAKEFLAGS,根据文档,它的主要用途似乎是将选项传递给子制作。但是,文档还指出:
您还可以在 makefile 中设置 MAKEFLAGS,以指定也应该对该 makefile 有效的其他标志
因此,从逻辑上讲,在 makefile 中定义 MAKEFLAGS = -r 应该与调用 make -r 具有相同的效果。这是您预期的行为。显然,情况并非如此(使用 GNU make 版本 3.81 和 3.82):
$ cat Makefile
MAKEFLAGS += -r
foo.c:
touch $@
$ rm -f foo.* ; make --version ; make foo.o
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 i686-pc-linux-gnu
touch foo.c
cc -c -o foo.o foo.c
和:
$ rm -f foo.* ; make --version ; make foo.o
GNU Make 3.82
Built for i686-pc-linux-gnu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
touch foo.c
cc -c -o foo.o foo.c
但它适用于 GNU make 4.0 和 4.1:
$ rm -f foo.* ; make --version ; make foo.o
GNU Make 4.0
Built for i686-pc-linux-gnu
Copyright (C) 1988-2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
make: *** No rule to make target 'foo.o'. Stop.
和:
$ rm -f foo.* ; make --version ; make foo.o
GNU Make 4.1
Built for i686-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
make: *** No rule to make target 'foo.o'. Stop.
显然,该错误已修复。