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?
make -p
andmake -d
provide interesting information, but not precisely what you are asking for. See make's man page.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.
Yes, remake can give you a backtrace. Here is a run to using the remake's Makefile show this:
You could also set a breakpoint at a particular target (
break
), go there (continue
) andbacktrace
that. And on error, you will get a backtrace of where you were at when you crashed.