Using Macros

To use a macro (defined or not), enclose its name in parentheses preceded by a dollar sign ($), as follows:

$(macroname)

No spaces are allowed. For example, you can use the LINKCMD macro defined as

LINKCMD = LINK /map

by specifying

$(LINKCMD)

NMAKE replaces the specification $(LINKCMD) with LINK /map.

Summary: An undefined macro is replaced by a null string.

If the name you use as a macro has never been defined, or was previously defined but is now undefined, NMAKE treats that name as a null string. No error occurs.

The parentheses are optional if macroname is a single character. For example, $L is equivalent to $(L). However, parentheses are recommended for consistency and to avoid possible errors.

Example

The following makefile defines and uses three macros:

program = sample

L = LINK

OPTIONS =

$(program).exe : $(program).obj

$(L) $(OPTIONS) $(program).obj;

NMAKE interprets the description block as

sample.exe : sample.obj

LINK sample.obj;

NMAKE replaces every occurrence of $(program) with sample, every instance of $(L) with LINK, and every instance of $(OPTIONS) with a null string.