我的Makefile,如下所示:
.SUFFIXES:foo
# Disable "default" suffix-rules.
MAKEFLAGS=-r
# A rule without a recipe!
all.o::
# File 'all.c' is "ought to exist".
all.c:
touch '$@'正在执行,我得到:
# Gnu-make still applies the "default" suffix-rule '.c.o'. Wrong?
$ make
cc -c -o all.o all.c为什么我不能禁用后缀规则?
发布于 2015-09-13 13:26:10
问题是,添加-r标志只会删除默认后缀规则设置。使用.SUFFIXES: foo时,您将向现有设置添加一个新的后缀规则。完成此操作后,.SUFFIXES的值不再与默认值相同,因此添加-r标志不会更改它。如果您想将它提交到萨凡纳上,这可以被认为是一个有用的增强请求。
如果您想使用新的后缀规则,但不使用任何预定义的规则,则可以使用POSIX标准所要求的永久可用的方法;首先删除所有现有的规则,然后添加新的:
.SUFFIXES:
.SUFFIXES: foo发布于 2015-09-13 05:09:30
定义.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应该具有与invoquing 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 make4.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.很明显,窃听器已经修好了。
https://stackoverflow.com/questions/32546232
复制相似问题