10.10 Differences between NMAKE and MAKE

NMAKE replaces the Microsoft MAKE program. NMAKE differs from MAKE in the following ways:

NMAKE does not evaluate targets sequentially. Instead, NMAKE updates the targets you specify when you invoke it, regardless of their positions in the description file. If no targets are specified, NMAKE updates only the first target in the file.

NMAKE requires a special syntax when specifying a target in more than one dependency line. (See Section 10.3.1.8, “Specifying a Target in Multiple Description Blocks.”)

NMAKE accepts command-line arguments from a file.

NMAKE provides more command-line options.

NMAKE provides more predefined macros.

NMAKE permits substitutions within macros.

NMAKE supports directives placed in the description file.

NMAKE allows you to specify include files in the description file.

The first item in the list deserves special emphasis. While MAKE updates every target, working from beginning to end of the description file, NMAKE expects you to specify targets on the command line. If you do not, NMAKE builds only the first target in the description file.

This difference is clear if you run NMAKE using a typical MAKE description file, which lists a series of subordinate targets followed by a higher-level target that depends on the following subordinates:

pmapp.obj : pmapp.c

CL /c /G2sw /W3 pmapp.c

pmapp.exe : pmapp.obj pmapp.def

LINK pmapp, /align:16, NUL, os2, pmapp

MAKE builds both targets (PMAPP.OBJ and PMAPP.EXE), but NMAKE builds only the first target (PMAPP.OBJ).

Because of these performance differences, you may want to convert MAKE files to NMAKE files. MAKE description files are easy to convert. One way is to create a new description block at the beginning of the file. Give this block a pseudotarget named all and list the top-level target as a dependent of all. To build all, NMAKE must update every file upon which the target all depends:

all : pmapp.exe

pmapp.obj : pmapp.c

CL /c /G2sw /W3 pmapp.c

pmapp.exe : pmapp.obj pmapp.def

LINK pmapp, /align:16, NUL, os2, pmapp

If the above file is named MAKEFILE, you can update the target PMAPP.EXE with the command

NMAKE

or the command

NMAKE all

It is not necessary to list PMAPP.OBJ as a dependent of all. NMAKE builds a dependency tree for the entire description file and builds whatever files are needed to update PMAPP.EXE. If PMAPP.C has a later modification time than PMAPP.OBJ, NMAKE compiles PMAPP.C to create PMAPP.OBJ, then links PMAPP.OBJ to create PMAPP.EXE.

The same technique is suitable for description files with more than one top-level target. List all the top-level targets as dependents of all:

all : pmapp.exe second.exe another.exe

The example updates the targets PMAPP.EXE, SECOND.EXE, and ANOTHER.EXE.

If the description file lists a single, top-level target, you can use an even simpler technique. Move the top-level block to the beginning of the file:

pmapp.exe : pmapp.obj pmapp.def

LINK pmapp, /align:16, NUL, os2, pmapp

pmapp.obj : pmapp.c

CL /c /G2sw /W3 pmapp.c

NMAKE updates the second target (PMAPP.OBJ) whenever needed to keep the first target (PMAPP.EXE) current.