Search code examples
visual-studiomakefilenmake

printing long compilation lines with MS NMAKE


I have a legacy MS NMAKE Makefile I need to fix a few bugs in.

There are some very long command lines I wish to debug that are being executed using the NMAKE trick of "inline files":

dep:
    cmd @<<tmpfilename
cmd_args..
<<

When changing the line to

dep:
    echo cmd @<<tmpfilename
cmd_args..
<<

NMAKE complains that the line is too long.

Is there any other trick I can apply in order to view the command line NMAKE is actually executing?


Solution

  • In order to keep the temporary file that keeps your command line append the KEEP keyword after the final <<. For example

    dep:
        echo cmd @<<tmpfilename
    cmd_args..
    <<KEEP
    

    In this case after issuing nmake dep a file named tmpfilename will remain, and hold the arguments list cmd_args.

    See sample makefile 2 in this MS KB article. This and this (warning:PDF) are explanation of the KEEP and NOKEEP keyword, but I'm not sure if they were written specifically for MS NMAKE.

    Edit: above links were replaced in 2019/08 since all of them were dead. The new links point to archived copies that seem to contain what the OP was referring to in this answer.

    The syntax is described in Inline Files in a Makefile and specifically Reusing inline files.