以下文件执行make main
,将自动生成g++ -c -o hhh.mk.o hhh.mk.cc
命令。为什么是这样,我如何禁用它?
Makefile
pre:
sh touch.sh
-include hhh.mk
%.cc:
echo $*
main: pre test.cc
echo main
# touch.sh
touch hhh.mk
一些变量保存在hhh中。Mk,这是由于没有创建文件造成的。和终极战士。Mk是由脚本在make过程中创建的。
GNU make知道如何从内部规则构建东西,包括递归调用这些规则。如果你运行make -d
,你会看到它在做什么,就像这样:
Considering target file 'hhh.mk'.
File 'hhh.mk' does not exist.
Looking for an implicit rule for 'hhh.mk'.
...
Trying pattern rule with stem 'hhh.mk'.
Trying implicit prerequisite 'hhh.mk.cc'.
Looking for a rule with intermediate file 'hhh.mk.cc'.
Avoiding implicit rule recursion.
Avoiding implicit rule recursion.
Trying pattern rule with stem 'hhh.mk'.
Found an implicit rule for 'hhh.mk'.
Considering target file 'hhh.mk.o'.
File 'hhh.mk.o' does not exist.
Considering target file 'hhh.mk.cc'.
File 'hhh.mk.cc' does not exist.
Finished prerequisites of target file 'hhh.mk.cc'.
Must remake target 'hhh.mk.cc'.
echo hhh.mk
有很多方法可以解决这个问题。一个简单的方法是:
MAKEFLAGS += -r
,它将删除所有默认规则。另一种方法是创建一个显式规则来构建包含的makefile:
hhh.mk: ; touch $@
由于它是显式的,make不会寻找隐式规则来构建它。
如果不了解你的需求,就不可能提供最好的解决方案。