Prevent GNU make from always removing files. It says things like “rm …” or “Removing intermediate files…”.

By neokrates, written on August 18, 2012

howto

  • Join date: 11-30-99
  • Posts: 224
View Counter:
  • 2,646 views
Rate it
Ad
Poll
  • Which tool is used for SCM/VCS in your enterprise?

    View Results

    Loading ... Loading ...
Feeds:
  • bodytext bodytext bodytext

After the make build some files are missing. There is no rule in your make files which tells Make to remove the files. In the build logfile you find lines like “rm …” and “Removing intermediate files…”. These are often last entries in the log, after the last target is finished (Successfully remade target file `all’.). Why make keeps removing the files? How to preserve them?

Woks for:

✔ windows xp or Linux

✔ GNU Make 3.*

Should also work for:

✔ most current GNU Make versions

✔ Os linke windows, Linux or Mac OS

In short :
Gnu make tracks some files which it calls "intermediate" and will remove them in the end of the build. You can verify that that is the reason your files are missing using make --debug and then you can preserve the files using special .SECONDARY: make target.

1

Run your build again, use --debug option

So, can this howto solve your problem? Let us check … Open dos shell in the your make directory, do

> make  --debug

Does the Make output contain (likely in the end) something like ? :

Successfully remade target file `$(smth like all)'.
Removing intermediate files...
rm $(YOUR_MISSING_FILES_HERE)

If yes, this howto is for you. If no, your problem is something else.

2

Add .SECONDARY: line in your make file

Go ahead and add .SECONDARY: line into make file, like

.SECONDARY:
... your code goes here
all: 
your_other_target:

3

Run make again

> make  --debug

verify that Removing intermediate files... entry has disappeared and that your files are no longer being removed .

4

Refine, optimize the solution

Mind that we just forced the make to preserve all intermediate files by adding .SECONDARY: line. Now you might get many temporary files cerated by make executions and just lying around. No cleanup.

You normally would not want that.

To improve the dirty fix, you may try to specify which files should be preserved by naming the make targets which .SECONDARY applies to

.SECONDARY: preserveme1.src preserveme2.src

(I didn’t try that out, but manual says that should work)

5

Why files are being removed, what is the problem, simple explanation and links to learn more

GNU make does track some files, which are created during the build, and it will remove such files after the build.
The files are called "intermediate files" . They are supposed to be created by the make’s "chain of Implicit Rules" . Because they where created to facilitate something else, makes considers them useless after the build and removes them.

http://www.gnu.org/software/make/manual/html_node/Chained-Rules.html#Chained-Rules :
“… if make does create b in order to update something else, it deletes b later on after it is no longer needed. ”

So, what does the
".SECONDARY"
do?

http://www.gnu.org/software/make/manual/html_node/Special-Targets.html
“.SECONDARY with no prerequisites causes all targets to be treated as secondary (i.e., no target is removed because it is considered intermediate). ”

Here is also a nice discussion on that subject :
http://stackoverflow.com/questions/3046117/gnu-makefile-multiple-outputs-from-single-rule-preventing-intermediate-files

hope I could help you, have fun :)

Be Sociable, Share!
 
Does that help to solve your problem?
VN:F [1.8.5_1061]
Rating: +11 (from 11 votes)
11 votes 'YES'  0 votes 'NO'

LEARN MORE (amazon bookstore)

TAGS

SOCIAL
Be Sociable, Share!

INCOMING SEARCH TERMS


Leave a Reply