我有一个软件堆栈,可以创建一些中间文件作为构建过程的一部分.出现了一些问题,构建中断了.我想看看那些中间生成的文件.令我惊讶的是,这些文件正在作为构建过程的一部分被删除.
Removing intermediate files...
rm fact_test_without_proxies.c fact_test_main.c fact_test_without_proxies.o
Run Code Online (Sandbox Code Playgroud)
我浏览了Makefiles我没有看到删除它们的任何明确规则.可以有任何隐式规则来删除中间文件.如果是,我如何禁用这些隐式规则?
Removing intermediate files...只有在使用--debug选项执行make时才会看到打印.
skmt@tux:~/coding/factorial/ut$ make --debug
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 x86_64-pc-linux-gnu
Reading makefiles...
Updating goal targets....
File `check' does not exist.
File `test_dept_run' does not exist.
File `fact_test' does not exist.
File `fact_using_proxies.o' does not exist.
File `fact_test_without_proxies' does not exist.
File `fact_test_without_proxies.o' does not exist.
File `fact_test_without_proxies.c' does not exist.
File `fact_test_main.c' does not exist.
Must remake target `fact_test_main.c'.
nm -p fact_test.o | build_main_from_symbols >fact_test_main.c
Successfully remade target file `fact_test_main.c'.
Must remake target `fact_test_without_proxies.c'.
cp fact_test_main.c fact_test_without_proxies.c
Successfully remade target file `fact_test_without_proxies.c'.
Must remake target `fact_test_without_proxies.o'.
gcc -I../src -c -o fact_test_without_proxies.o fact_test_without_proxies.c
Successfully remade target file `fact_test_without_proxies.o'.
Must remake target `fact_test_without_proxies'.
gcc fact_test_without_proxies.o fact.o fact_test.o -o fact_test_without_proxies
fact.o: In function `unknown':
fact.c:(.text+0x67): undefined reference to `do_update'
collect2: ld returned 1 exit status
make: *** [fact_test_without_proxies] Error 1
Removing intermediate files...
rm fact_test_without_proxies.c fact_test_main.c fact_test_without_proxies.o
Run Code Online (Sandbox Code Playgroud)
Bet*_*eta 43
如果您使用的是GNUMake,则可以使用特殊目标.PRECIOUS:
.PRECIOUS: fact_test_without_proxies.c fact_test_main.c fact_test_without_proxies.o
Run Code Online (Sandbox Code Playgroud)
要不就
.PRECIOUS: %.c %.o
Run Code Online (Sandbox Code Playgroud)
它的唯一作用是,如果Make被杀死或中断,这些文件将不会被删除.
Mic*_*ael 42
您也可以使用.SECONDARY,它将保留指定的文件,即使构建没有中断.
例如
.SECONDARY:
Run Code Online (Sandbox Code Playgroud)
小智 7
目标的使用受到限制,这会影响.PRECIOUS的行为:
我有目标A /%.foo:和B /%.foo :,所以我设置了:
.PRECIOUS: %.foo
Run Code Online (Sandbox Code Playgroud)
这没用; 我不明白为什么,但扩张不这样做; 我必须完全按照它们的写法明确列出目标:
.PRECIOUS: A/%.foo B/%.foo
Run Code Online (Sandbox Code Playgroud)
但即使在阅读https://www.gnu.org/software/make/manual/html_node/Special-Targets.html之后,我也不明白.PRECIOUS:和.SECONDARY:之间的区别.
可以接受使用那些没有依赖的特殊目标,但我认为这将是非常脏的编码并且会产生副作用.有些人只是把.PRECIOUS:或.SECONDARY:没有dep,后来,他们抱怨说他们必须在破坏构建后运行make clean ...