Seeing what commands nmake is issuing

1.2k views Asked by At

Taking an nmake project, specifically Ruby, and trying to see exactly what commands are used to build it. nmake says what files it is compiling, but not what commandline it is using to compile each file. The closest thing to an obviously relevant option is /D, but that doesn't shed much light on it.

Is there a way, by supplying some option to nmake or otherwise, to see exactly what commands it is issuing?

2

There are 2 answers

0
sffc On

I use /N to display the command lines and /A to run all targets (not just out-of-date targets).

> nmake /F example.mak /A /N

Docs: https://msdn.microsoft.com/en-us/library/afyyse50.aspx

0
Brian Tompsett - 汤莱恩 On

There is no general way of causing all the commands to be echoed, such as using a command option. However it is possible to build such an option by yourself, but it does involve making global edits to the Makefile. However, with clever use of an editor (such as one that matches regular expressions) you can quickly make the changes and get what you desire.

The technique is described in this Blog article: Writing Portable Makefiles, Section §5.

Every makefile implementation allows a command to be proceeded by an @ symbol which causes the echo to be disabled. The technique is to use a macro in place of the @ symbol, such as in this example Makefile:

!MESSAGE Makeflags=$(MAKEFLAGS)

!IFNDEF LOG
L=@
!ELSE
!  IF  [ IF /I $(LOG) == yes ( EXIT 1 ) ELSE ( EXIT 0 ) ] == 0
L=@
!ELSE
L=
!ENDIF
!ENDIF
# To be a valid makefile it must have some rules to perform
all:
    $(L)echo;This is a command being executed

This can be demonstrated thus:

C:\Users\Brian>nmake /NOLOGO
Makeflags=L
This is a command being executed

C:\Users\Brian>nmake /NOLOGO LOG=yes
Makeflags=L
        echo;This is a command being executed
This is a command being executed

C:\Users\Brian>nmake /NOLOGO LOG=no
Makeflags=L
This is a command being executed

Then, all that remains is to change every @ at the beginning of a command to '$(L)' (leaving all the other @ symbols unchanged of course!).