60

I see that this is the same question as

Making cmake 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
Community
  • 1
  • 1
gman
  • 100,619
  • 31
  • 269
  • 393
  • We already had some discussion about this, but I just discovered another question that looks very similar: [Is there any way for “make” to echo commands](http://stackoverflow.com/q/4396107/1380680). – Reinier Torenbeek Jun 20 '12 at 19:33
  • possible duplicate of [How do I force make/gcc to show me the commands?](http://stackoverflow.com/questions/5820303/how-do-i-force-make-gcc-to-show-me-the-commands) – Ciro Santilli OurBigBook.com Aug 14 '15 at 13:12

4 Answers4

145

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.

Reinier Torenbeek
  • 16,669
  • 7
  • 46
  • 69
  • 1
    SO there's no way to make make print what it is executing? -n doesn't work because I need to so see it fail in context and for whatever reason executing the output of -n is not the same as without it. – gman Jun 13 '12 at 17:31
  • By default, `make` *will* print what it is executing. What I said is that your makefile(s) probably use a mechanism to suppress that echo-ing, either by means of the `@` sign in front of the command, or by means of the built-in target `.SILENT`. You have to look in the makefile to see if that is indeed the case. – Reinier Torenbeek Jun 13 '12 at 20:52
  • Thanks, I guess I was hoping there was an override like --verbose-level=10000000 or --ignore-silent I don't have control of my makefiles. I'm on a project with > 500 programmers. – gman Jun 14 '12 at 22:22
  • 4
    Aha... well, as a last resort, you could do a workaround by defining `SHELL=/bin/bash -x` when running make -- assuming that you can use bash. Since `make` uses the value found in `$SHELL` to execute commands, this will result in every command being echoed first due to the `-x` flag. I will add it to the answer, let me know if this works for you. – Reinier Torenbeek Jun 14 '12 at 23:45
  • no luck. maybe I can write a script to modify my makefiles whenever I need to do this and just not check them in. – gman Jun 17 '12 at 00:43
  • 3
    That is strange. For me, `make SHELL="/bin/bash -x" target` shows all executed shell commands, independent of what the makefile looks like. When you say 'no luck', does that mean you see nothing different at all, or does it print something but not your desired commands? What if you do a `make clean` first, and then the `make SHELL="/bin/bash -x" target`? – Reinier Torenbeek Jun 17 '12 at 01:57
  • Maybe your makefiles explicitly divert the output of the commands. I have seen that happen in large projects, where a filter application is used for that purpose to avoid distraction for the developers. In that case, the output showed up in some file that most people were not aware of. Just a thought... – Reinier Torenbeek Jun 17 '12 at 12:55
  • strange, so `make SHELL="/bin/bash -x" target` is now working for me. I don't know what I mis-typed or got wrong the first time I tried it – gman Jun 23 '12 at 16:30
  • Good, and now hope that this actually helps you to analyse the problem you were trying to resolve in the first place :-) – Reinier Torenbeek Jun 23 '12 at 21:07
  • More precisely `VERBOSE`, it seems to be used in Makefiles generated by CMake and Autotools – Ciro Santilli OurBigBook.com Aug 14 '15 at 13:24
  • I like the SHELL= printing, but is there any way to pipe THAT output to a file? – RufusVS Jan 25 '22 at 22:04
3

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.
Kevin
  • 2,761
  • 1
  • 27
  • 31
3

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    
Mansur Ul Hasan
  • 2,898
  • 27
  • 24
1

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

  • 3
    The "MAKE_VERBOSE" make variable has no special meaning to make itself, unless your makefiles define it and use it. – qneill Mar 16 '21 at 14:49