Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backtrace for GNU make

Is there any way to get GNU make to print a "backtrace" of the targets that led to the command being executed when it fails? I regularly deal with heavily obfuscated makefiles while resolving portability issues building software on a new system, and it seems like this should be an extremely simple thing for make to do that would greatly aid in debugging, but I can't find any way to request it. What I'd like to see is something like:

gcc: error: ...
make[2]: error: gcc ...
make[2]: error building target bar
make[2]: error building dependency bar for target foo
make[1]: error: make -C subdir
make[1]: error building target subdir
make[1]: error building dependency subdir for target all
...

showing the entire dependency path for how the failed command ended up getting executed.

Is there any way to do this?

like image 748
R.. GitHub STOP HELPING ICE Avatar asked Feb 17 '11 17:02

R.. GitHub STOP HELPING ICE


People also ask

What is $@ and in Makefile?

The $@ and $< are called automatic variables. The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file. For example: hello.o: hello.c hello.h gcc -c $< -o $@ Here, hello.o is the output file.

How do I debug a Makefile?

Finally, you can also debug the Makefile by running Make with the debug flag: make -d . This will print all the rules (including built-in ones) that Make tries for each of the targets, and whether or not a rule needs to be run.

How do I backtrace on Linux?

backtrace() returns a backtrace for the calling program, in the array pointed to by buffer. A backtrace is the series of currently active function calls for the program. Each item in the array pointed to by buffer is of type void *, and is the return address from the corresponding stack frame.

How do you backtrace a program?

The usual way to inspect a backtrace of a program is to use an external debugger such as gdb. However, sometimes it is useful to obtain a backtrace programmatically from within a program, e.g., for the purposes of logging or diagnostics. The header file execinfo.


1 Answers

Use remake. It is a patched version of GNU Make that adds improved error reporting, the ability to trace execution in a comprehensible way, and a debugger.

like image 119
Eldar Abusalimov Avatar answered Sep 28 '22 13:09

Eldar Abusalimov