Making make print commands before executing when NOT using CMake

Makefile

Makefile Problem Overview


I see that this is the same question as

https://stackoverflow.com/questions/4808303/making-make-print-commands-before-executing

But that answer doesn't work for me. I'm guessing that answer only works with cmake. What options work without cmake?

Note tried these

make VERBOSE=1 target
make target VERBOSE=1
VERBOSE=1 make target
make V=1 target
make target V=1
V=1 make target
make -V target
make -v target

none of them worked.

make -v returns

GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu

Makefile Solutions


Solution 1 - Makefile

By default, make does print every command before executing it. This printing can be suppressed by one of the following mechanisms:

  • on a case-by-case basis, by adding @ at the beginning of the command
  • globally, by adding the .SILENT built-in target.
  • somewhere along the make process, by invoking sub-make(s) with one of the flags -s, --silent or --quiet, as in $(MAKE) --silent -C someDir, for example. From that moment on, command echoing is suppressed in the sub-make.

If your makefile does not print the commands, then it is probably using one of these three mechanisms, and you have to actually inspect the makefile(s) to figure out which.

As a workaround to avoid these echo-suppressing mechanisms, you could re-define the shell to be used to use a debug mode, for example like make SHELL="/bin/bash -x" target. Other shells have similar options. With that approach, it is not make printing the commands, but the shell itself.

If you use the flag -n or --just-print, the echo-suppressing mechanisms will be ignored and you will always see all commands that make thinks should be executed -- but they are not actually executed, just printed. That might be a good way to figure out what you can actually expect to see.

The VERBOSE variable has no standard meaning for make, but only if your makefile interprets it.

Solution 2 - Makefile

For my version of make, I found BOTH paramters -n and -d helped.

> GNU Make 3.80 Copyright (C) 2002 Free Software Foundation, Inc

  -d                          Print lots of debugging information.
  -n, --just-print, --dry-run, --recon
                              Don't actually run any commands; just print them.

When a bunch of makefile fragments are included, the line numbers don't make sense without this key debug flag.

CreateProcess(....exe,...)
Reading makefile `../../../../build/Makefile.options' (search path) (don't care) (no ~ expansion)...
Makefile:361: Extraneous text after `else' directive
Makefile:368: Extraneous text after `else' directive
Makefile:368: *** only one `else' per conditional.  Stop.

Solution 3 - Makefile

I think this is what you want: make MAKE_VERBOSE=1 target

Solution 4 - Makefile

in my case i was able to suppress commands in output by setting up below variable in top my make file

# Use `make V=1` to print commands.
$(V).SILENT:

add the above line in top of you make file and when you call any target it wont print

Before :

muhasan@admins-MacBook-Pro fx.identitymanagement % make dockerstatus
cd identity.API/ && docker-compose ps 
        Name                       Command              State           Ports         
--------------------------------------------------------------------------------------
identityapi_backend_1   dotnet Identity.API.dll         Up      0.0.0.0:5000->80/tcp  
identityapi_db_1        docker-entrypoint.sh postgres   Up      0.0.0.0:5432->5432/tcp
muhasan@admins-MacBook-Pro fx.identitymanagement % 

After :

muhasan@admins-MacBook-Pro fx.identitymanagement % make dockerstatus
        Name                       Command              State           Ports         
--------------------------------------------------------------------------------------
identityapi_backend_1   dotnet Identity.API.dll         Up      0.0.0.0:5000->80/tcp  
identityapi_db_1        docker-entrypoint.sh postgres   Up      0.0.0.0:5432->5432/tcp
muhasan@admins-MacBook-Pro fx.identitymanagement % 
 

My Makefile

# Use `make V=1` to print commands.
$(V).SILENT:
Path = identity.API
builddocker:
	cd devops && cp -rv Dockerfile docker-compose.yml ../${Path}/ && cd ..
installdocker:
	cd ${Path}/ && docker-compose up -d
dockerstatus:
	cd ${Path}/ && docker-compose ps 	

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongmanView Question on Stackoverflow
Solution 1 - MakefileReinier TorenbeekView Answer on Stackoverflow
Solution 2 - MakefileKevinView Answer on Stackoverflow
Solution 3 - Makefileuser2023183View Answer on Stackoverflow
Solution 4 - MakefileMansur Ul HasanView Answer on Stackoverflow