Share via


Using Macros and Environment Variables

The Build utility uses many environment variables and macros:

  • Environment variables are set by the SetEnv.bat batch file when you open a Windows Driver Kit (WDK) build environment window. From within the build environment window, you can also set your own environment variables along with the WDK environment variables that are not set by the batch file, such as BUILD_ALT_DIR and BUILD_DEFAULT_TARGETS.

    Note  You can also set these environment variables before you start the SetEnv.bat batch file. By doing this, they are present in the WDK build environment.

  • Macros are specified in the Sources, Makefile, and Makefile.incfiles. These files must exist in each source code subdirectory. Each of these files contains a series of macro definitions in the following format:

    MACRONAME=MacroValue
    

    Here, MacroValue represents a text string that the Build utility uses to replace MACRONAME in its internal scripts.

    To specify a MacroValue string that is longer than one line, each line (except the last line) must end with a backslash (\) character. The last line must be formatted in one of the following ways:

    • It must not end with a backslash (\) character.
    • It must be followed by a blank line.

    The Build utility macros follow all of the rules for NMAKE macros. For more information about NMAKE macros, refer to the Macros and NMAKE topic in the MSDN documentation.

    Important   Macros are also used within the Makefile.def file. However, you should not change any macro settings within this file.

Important Points about Setting Environment Variables

Environment variables set by the SetEnv.bat batch file provide parameters to the Build and NMAKE utilities. As a result, these variables control the build environment.

You should be aware of the following points about how to set environment variables within a WDK build environment:

  • Most of the environment variables set by the SetEnv.bat batch file must not be changed from within a build environment window.

    However, the environment variables that affect the operation of the Build utility can be changed, such as the following:

    Note  You must set these environment variables before you start the Build utility from the command-line in the build environment window.

  • When the NMAKE utility is started, it creates macros for every environment variable that was set in the build environment window. Macros are created for environment variables either set by the SetEnv.bat batch file or your own scripts.

    If you have to change a build environment setting, it is highly recommended that you change the setting through a macro and not the environment variable itself. If you change the setting for a macro, it will not change the setting of the related environment variable. For example, a macro that was changed within a Sources file only affects the build of the project defined by that file and does not change the overall environment for building other projects.

For more information, see Build Utility Environment Variables.

Controlling Environment Variables and Macros

To see the value of all Build utility environment variables, type set in a build environment command window. The set command can also be used to change a variable's value.

To reference an environment variable or macro in a Sources file, use the following syntax:

$(VariableName)

where VariableName is the name of the environment variable or macro. An example is as follows:

TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib \
           $(SDK_LIB_PATH)\advapi32.lib \
           $(SDK_LIB_PATH)\user32.lib   \
           $(SDK_LIB_PATH)\spoolss.lib

For a complete list of the required and optional environment variables and macros, see Build Utility Environment Variables and Build Utility Macros.

Note   Except for the DIRS and OPTIONAL_DIRS macros, which are used by the Build utility, these macros are all used by NMAKE. All that the Build utility does is open all the files, figure out the dependencies, and then call NMAKE. The other macros used in the build process are all used by NMAKE. For information about the DIRS and OPTIONAL_DIRS macros, see the Dirs file.

 

 

Send comments about this topic to Microsoft

Build date: 5/3/2011