Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
466 views
in Technique[技术] by (71.8m points)

makefile - How to undo intermediate file deletion

I have a software stack that creates some intermediate files as a part of build process. There is some problem come up and the build breaks. I want to have a look at those intermediate generated files. To my surprise those files are being deleted as a part of build process.

Removing intermediate files...
rm fact_test_without_proxies.c fact_test_main.c fact_test_without_proxies.o

I went through the Makefiles I don't see any explicit rules deleting them. Can there be any implicit rules to delete intermediate files. If yes how can I disable those implicit rules ?

I see the print Removing intermediate files... only if make is executed with --debug option.

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you're using GNUMake, you can use the special target .PRECIOUS:

.PRECIOUS: fact_test_without_proxies.c fact_test_main.c fact_test_without_proxies.o

or just

.PRECIOUS: %.c %.o

Its only effect is that these files will not be deleted if Make is killed or interrupted.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...