Log invoked commands of make

This

make SHELL="sh -x -e"

will cause the shell (which make invokes to evaluate shell constructs) to print information about what it's doing, letting you see how any conditionals in shell commands are being evaluated.

The -e is necessary to ensure that errors in a Makefile target will be properly detected and a non-zero process exit code will be returned.


Make writes each command it executes to the console, so

make 2>&1 | tee build.log

will create a log file named build.log as a side effect which contains the same stuff written to the screen. (man tee for more details.)

2>&1 combines standard output and errors into one stream. If you didn't include that, regular output would go into the log file but errors would only go to the console. (make only writes to stderr when a command returns an error code.)

If you want to suppress output entirely in favor of logging to a file, it's even simpler:

make 2>&1 > build.log

Because these just capture console output they work just fine with recursive make.


You could try to log execve calls with strace

strace -f -e execve make ...

Tags:

Makefile