Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 537
LiMar Avatar asked Jul 26 '26 17:07

LiMar


2 Answers

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.

like image 56
Eldar Abusalimov Avatar answered Jul 28 '26 07:07

Eldar Abusalimov


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

like image 33
Basile Starynkevitch Avatar answered Jul 28 '26 05:07

Basile Starynkevitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!