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.
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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With