Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log invoked commands of make

Tags:

makefile

Is there a way to log the commands, make invokes to compile a program? I know of the parameters -n and -p, but they either don't resolve if-conditions but just print them out. Or they don't work, when there are calls to 'make' itself in the Makefile.

like image 405
Customizer Avatar asked Mar 10 '10 08:03

Customizer


People also ask

What is the use of make commands?

The make command assists in maintaining a set of programs, usually pertaining to a particular software project, by building up-to-date versions of programs. The make command is most useful for medium-sized programming projects.

What is $$ in Makefile?

Commands and executionIf you want a string to have a dollar sign, you can use $$ . This is how to use a shell variable in bash or sh . Note the differences between Makefile variables and Shell variables in this next example.

How do I run with Makefile?

Before running a Makefile in Windows, it is required to install the make command first by using the “Mingw-get install mingw32-make” command on the Command Prompt. Then, create a Makefile, remove the “. txt” extension, and use the “make” command to run the specified Makefile in Windows.


1 Answers

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.

like image 62
olooney Avatar answered Sep 28 '22 05:09

olooney