我有一个使用自动依赖项生成的C++程序的Makefile.%.d配方取自GNU Make手册.
问题是以某种方式将"Makefile"添加为目标,然后隐式规则使其假定它是可执行文件并使用我的src /%.cpp规则来尝试编译src/Makefile.cpp.查看调试信息时,这总是在执行include之后发生.
No need to remake target `build/Sprite.d'.
Considering target file `Makefile'.
Looking for an implicit rule for `Makefile'.
...
Trying pattern rule with stem `Makefile'.
Trying implicit prerequisite `Makefile.o'.
Looking for a rule with intermediate file `Makefile.o'.
Run Code Online (Sandbox Code Playgroud)
我知道包含原因如果需要,可以重建给定的Makefile.它是否也尝试重建当前的Makefile?如果是这样,我如何阻止它,如果没有,那么为什么"Makefile"被添加为目标呢?
此外,执行include,即使我在命令行上指定目标,也会重新生成.d文件,例如make clean.有没有办法阻止这种情况发生?
# $(call setsuffix,newsuffix,files)
# Replaces all the suffixes of the given list of files.
setsuffix = $(foreach file,$2,$(subst $(suffix $(file)),$1,$(file)))
# $(call twinfile,newdir,newsuffix,oldfile)
# Turns a path to one file into a path to a …Run Code Online (Sandbox Code Playgroud)