Build system independent method
make SHELL='sh -x'
is another option. Sample Makefile
:
a:
@echo a
Output:
+ echo a
a
This sets the special SHELL
variable for make
, and -x
tells sh
to print the expanded line before executing it.
One advantage over -n
is that is actually runs the commands. I have found that for some projects (e.g. Linux kernel) that -n
may stop running much earlier than usual probably because of dependency problems.
One downside of this method is that you have to ensure that the shell that will be used is sh
, which is the default one used by Make as they are POSIX, but could be changed with the SHELL
make variable.
Doing sh -v
would be cool as well, but Dash 0.5.7 (Ubuntu 14.04 sh
) ignores for -c
commands (which seems to be how make
uses it) so it doesn't do anything.
make -p
will also interest you, which prints the values of set variables.
CMake generated Makefiles always support VERBOSE=1
As in:
mkdir build
cd build
cmake ..
make VERBOSE=1
Dedicated question at: Using CMake with GNU Make: How can I see the exact commands?