Special NMAKE Macros

NMAKE provides several special macros to represent various filenames and commands. One use for some of these macros is in the predefined inference rules. Like all macros, the macros provided by NMAKE are case sensitive.

This section discusses:

Filename Macros

Filename macros are predefined as filenames specified in the dependency (not full filename specifications on disk). These macros do not need to be enclosed in parentheses when invoked; specify only a $ as shown.

Macro Meaning
$@ Current target's full name (path, base name, extension), as currently specified.
$$@ Current target's full name (path, base name, extension), as currently specified. Valid only as a dependent in a dependency.
$* Current target's path and base name minus file extension.
$** All dependents of the current target.
$? All dependents with a later timestamp than the current target.
$< Dependent file with a later timestamp than the current target. Valid only in commands in inference rules.

To specify part of a predefined filename macro, append a macro modifier and enclose the modified macro in parentheses.

Modifier Resulting Filename Part
D Drive plus directory
B Base name
F Base name plus extension
R Drive plus directory plus base name

Recursion Macros

Use recursion macros to call NMAKE recursively. Recursive sessions inherit command-line and environment-variable macros. They do not inherit makefile-defined inference rules or .SUFFIXES and .PRECIOUS specifications. To pass macros to a recursive NMAKE session, either set an environment variable with the SET command before the recursive call or define a macro in the command for the recursive call.

Macro Definition
MAKE Command used originally to invoke NMAKE.
MAKEDIR Current directory when NMAKE was invoked.
MAKEFLAGS Options currently in effect. Use as /$(MAKEFLAGS).

Command Macros, Options Macros

Command macros are predefined for Microsoft products. Options macros represent options to these products and are undefined by default. Both are used in predefined inference rules and can be used in description blocks or user-defined inference rules. Command macros can be redefined to represent part or all of a command line, including options. Options macros generate a null string if left undefined.

Product Command Macro Defined as: Options Macro
Macro Assembler AS ml AFLAGS
Basic Compiler BC bc BFLAGS
C Compiler CC cl CFLAGS
COBOL Compiler COBOL cobol COBFLAGS
C++ Compiler CPP cl CPPFLAGS
C++ Compiler CXX cl CXXFLAGS
Compaq Visual Fortran Compiler FOR df FFLAGS
Pascal Compiler PASCAL pl PFLAGS
Resource Compiler RC rc RFLAGS

Environment-Variable Macros

NMAKE inherits macro definitions for environment variables that exist before the start of the session. If a variable was set in the operating-system environment, it is available as an NMAKE macro. Use the /E option to cause macros inherited from environment variables to override any macros with the same name in the makefile.

Environment-variable macros can be redefined in the session, and this changes the corresponding environment variable. You can also change environment variables with the SET command. Using the SET command to change an environment variable in a session does not change the corresponding macro, however.

For example:

PATH=$(PATH);\nonesuch

all:
    echo %PATH%

In this example, changing PATH changes the corresponding environment variable PATH; it appends \nonesuch to your path.

If an environment variable is defined as a string that would be syntactically incorrect in a makefile, no macro is created and no warning is generated. If a variable's value contains a dollar sign ($), NMAKE interprets it as the beginning of a macro invocation. Using the macro can cause unexpected behavior.