To define a macro, use the following syntax:
macroname=string
The macroname can be any combination of letters, digits, and the underscore (_) character, up to 1024 characters. Macro names are case sensitive; NMAKE interprets MyMacro and MYMACRO as different macro names. The macroname can contain a macro invocation. If macroname consists entirely of an invoked macro, the macro being invoked cannot be null or undefined.
The string can be any sequence of zero or more characters up to 64K–25 (65,510 bytes). A string of zero characters is called a “null string.” A string consisting only of spaces, tabs, or both is also considered a null string.
Other syntax rules, such as the use of spaces, apply depending on where you specify the macro; see “Where to Define Macros”. The string can contain a macro invocation.
Example
The following specification defines a macro named DIR and assigns to it a string that represents a directory.
DIR=c:\objects
Certain characters have special meaning within a macro definition. You use these characters to perform specific tasks. If you want one of these characters to have a literal meaning, you must specify it using a special syntax.
To specify a comment with a macro definition, place a number sign (#) and the comment after the definition, as in:
LINKCMD = link /CO # Prepare for debugging
NMAKE ignores the number sign and all characters up to the next newline character. To specify a literal number sign in a macro, use a caret (^), as in ^#.
To extend a macro definition to a new line, end the line with a backslash (\). The newline character that follows the backslash is replaced with a space when the macro is expanded, as in the following example:
LINKCMD = link myapp\
another, , NUL, mylib, myapp
When this macro is expanded, a space separates myapp and another.
To specify a literal backslash at the end of the line, precede it with a caret (^), as in:
exepath = c:\bin^\
You can also make a backslash literal by following it with a comment speci-fier (#). NMAKE interprets a backslash as literal if it is followed by any other character.
To insert a literal newline character into a macro, end the line with a caret (^). The caret tells NMAKE to interpret the newline character as part of the macro, not as a line break ending the macro definition. The following example defines a macro composed of two operating-system commands separated by a newline character:
CMDS = cls^
dir
For an illustration of how this macro can be used, see the first example under “Inline Files”.
To specify a literal dollar sign ($) in a macro definition, use two dollar signs ($$). NMAKE interprets a single dollar sign as the specifier for invoking a macro; see “Using Macros”.
For information on how to handle other special characters literally, regardless of whether they appear in a macro, see “Using Special Characters as Literals”.
You can define macros in the makefile, on the command line, in a command file, or in TOOLS.INI. (For more information, see “Precedence among Macro Definitions” on page 680.) Each macro defined in the makefile or in TOOLS.INI must appear on a separate line. The line cannot start with a space or tab.
Summary: Spaces in the makefile and in TOOLS.INI...
When you define a macro in the makefile or in TOOLS.INI, NMAKE ignores any spaces or tabs on either side of the equal sign. The string itself can contain embedded spaces. You do not need to enclose string in quotation marks (if you do, they become part of the string). The macro name being defined must appear at the beginning of the line. Only one macro can be defined per line. For example, the following macro definition can appear in a makefile or TOOLS.INI:
LINKCMD = LINK /MAP
Summary: ...are not the same as spaces on the command line.
Slightly different rules apply when you define a macro on the NMAKE command line or in a command file. The command-line parser treats spaces and tabs as argument delimiters. Therefore, spaces must not precede or follow the equal sign. If string contains embedded spaces or tabs, either the string itself or the entire macro must be enclosed in double quotation marks ("). For example, either form of the following command-line macro is allowed:
NMAKE "LINKCMD = LINK /MAP"
NMAKE LINKCMD="LINK /MAP"
However, the following form of the same macro is not permitted. It contains spaces that are not enclosed by quotation marks:
NMAKE LINKCMD = "LINK /MAP"
Null Macros and Undefined Macros
An undefined macro is not the same thing as a macro defined to be null. Both kinds of macros expand to a null string. However, a macro defined to be null is still considered to be defined when used with preprocessing directives such as !IFDEF. (See “Preprocessing Directives”). A macro name can be “undefined” in a makefile by using the !UNDEF preprocessing directive.
To define a macro to be null:
In a makefile or TOOLS.INI, specify zero or more spaces between the equal sign (=) and the end of the line, as in the following:
LINKOPTIONS =
On the command line or in a command file, specify zero or more spaces enclosed in double quotation marks (""), or specify the entire null definition enclosed in double quotation marks, as in either of the following:
LINKOPTIONS=""
"LINKOPTIONS ="
To undefine a macro, use !UNDEF, as in:
!UNDEF LINKOPTIONS