为什么 gnu make 删除这个文件?
Why does gnu make delete this file?
考虑这个 Makefile
:
.PHONY: all
all: main.txt
main.txt: build/main.txt
cp build/main.txt .
%/main.txt: %/data.txt
cp $*/data.txt $*/main.txt
%/data.txt:
touch $*/data.txt
运行make
后,build/data.txt
自动删除。为什么会这样?
我尝试将 .PRECIOUS: build/%
添加到文件中,但没有用,文件仍然被删除。我怎样才能避免这种情况?
You can also list the target pattern of an implicit rule (such as ‘%.o’) as a prerequisite file of the special target .PRECIOUS to preserve intermediate files created by rules whose target patterns match that file’s name.
.PRECIOUS
的先决条件需要是现有隐式规则的(准确)目标模式。
在你的情况下,这将是 %/data.txt
。
文档对此有暗示,但不是特别清楚。
附带说明:据我所知,build/main.txt
不会自动删除,因为它被明确命名为 main.txt
目标的先决条件,并且 build/data.txt
会自动删除因为它从未明确命名。
考虑这个 Makefile
:
.PHONY: all
all: main.txt
main.txt: build/main.txt
cp build/main.txt .
%/main.txt: %/data.txt
cp $*/data.txt $*/main.txt
%/data.txt:
touch $*/data.txt
运行make
后,build/data.txt
自动删除。为什么会这样?
我尝试将 .PRECIOUS: build/%
添加到文件中,但没有用,文件仍然被删除。我怎样才能避免这种情况?
You can also list the target pattern of an implicit rule (such as ‘%.o’) as a prerequisite file of the special target .PRECIOUS to preserve intermediate files created by rules whose target patterns match that file’s name.
.PRECIOUS
的先决条件需要是现有隐式规则的(准确)目标模式。
在你的情况下,这将是 %/data.txt
。
文档对此有暗示,但不是特别清楚。
附带说明:据我所知,build/main.txt
不会自动删除,因为它被明确命名为 main.txt
目标的先决条件,并且 build/data.txt
会自动删除因为它从未明确命名。