Predefined Inference Rules

NMAKE provides predefined inference rules containing commands for creating object, executable, and resource files. Table 18.1 describes the predefined inference rules.

Table 18.1 Predefined Inference Rules

Rule Command Default Action

.asm.exe $(AS) $(AFLAGS) $*.asm ML $*.ASM
.asm.obj $(AS) $(AFLAGS) /c $*.asm ML /c $*.ASM
.c.exe $(CC) $(CFLAGS) $*.c CL $*.C
.c.obj $(CC) $(CFLAGS) /c $*.c CL /c $*.C
.cpp.exe $(CPP) $(CPPFLAGS) $*.cpp CL $*.CPP
.cpp.obj $(CPP) $(CPPFLAGS) /c $*.cpp CL /c $*.CPP
.cxx.exe $(CXX) $(CXXFLAGS) $*.cxx CL $*.CXX
.cxx.obj $(CXX) $(CXXFLAGS) /c $*.cxx CL /c $*.CXX
.bas.obj $(BC) $(BFLAGS) $*.bas; BC $*.BAS;
.cbl.exe $(COBOL) $(COBFLAGS) $*.cbl, $*.exe; COBOL $*.CBL, $*.EXE;
.cbl.obj $(COBOL) $(COBFLAGS) $*.cbl; COBOL $*.CBL;
.for.exe $(FOR) $(FFLAGS) $*.for FL $*.FOR
.for.obj $(FOR) /c $(FFLAGS) $*.for FL /c $*.FOR
.pas.exe $(PASCAL) $(PFLAGS) $*.pas PL $*.PAS
.pas.obj $(PASCAL) /c $(PFLAGS) $*.pas PL /c $*.PAS
.rc.res $(RC) $(RFLAGS) /r $* RC /r $*

For example, assume you have the following makefile:

sample.exe :

This description block lists a target without any dependents or commands. NMAKE looks at the target's extension (.EXE) and searches for an inference rule that describes how to create an .EXE file. Table 18.1 shows that more than one inference rule exists for building an .EXE file. NMAKE uses the order of the extensions appearing in the .SUFFIXES list to determine which rule to invoke. It then looks in the current or specified directory for a file that has the same base name as the target sample and one of the extensions in the .SUFFIXES list; it checks the extensions one by one until it finds a matching dependent file in the directory.

For example, if a file called SAMPLE.FOR exists, NMAKE applies the .for.exe inference rule. If both SAMPLE.C and SAMPLE.FOR exist, and if .c appears before .for in the .SUFFIXES list, NMAKE instead uses the .c.exe inference rule to compile SAMPLE.C and links the resulting file SAMPLE.OBJ to create SAMPLE.EXE.

Note:

By default, the options macros such as CFLAGS are undefined. As explained in “Using Macros”, this causes no problem; NMAKE replaces an undefined macro with a null string. Because the predefined options macros are included in the inference rules, you can define these macros and have their assigned values passed automatically to the predefined inference rules.