LiMar
LiMar

Reputation: 2962

Makefile(s) debug: which file/line calls to a command?

I'm facing a bug in a makefile build system (Android built under Linux) - some files are removed by an 'rm' command, and I can see that command in the build log.

How can I find the exact line in the makefiles which calls the 'rm' ? Is there any automated method?

Upvotes: 3

Views: 1282

Answers (3)

Eldar Abusalimov
Eldar Abusalimov

Reputation: 25513

For GNU Make you can do the following trick:

__shell := $(SHELL)
SHELL = \
    $(warning making '$@'$(if $^, from '$^')$(if $?, because of '$?'))$(__shell)

SHELL variable is expanded each time when Make invokes a sub-shell to execute a recipe. In these lines it is replaced so that on each expansion it will print a target, its prerequisites and prerequisites that are newer than the target. Also each debug message is prepended with the file and line number of the rule being executed.

The same technique is used in GMD to set breakpoints to certain targets.

Upvotes: 4

Assuming your make is a Gnu make, you can also pass some debugging options, like --debug=b (basic debugging messages, very often enough) or --debug=all which is the same as -d

Some files may be removed because they are intermediate. Read also about secondary files and precious files in make

Upvotes: 1

pinxue
pinxue

Reputation: 1746

You may try make -d -w and then grep your file from huge amount of output lines.

Upvotes: 0

Related Questions