Running the Build Utility
When you open a build environment window, the directory in the window is set to the default directory for the Windows Driver Kit (WDK). For more information about how to set up the build environment, see Setting Up the Build Environment.
Before you run the Build utility, you must first create a number of data files. The Build utility requires the files shown in the following table to build a driver.
File | Location |
---|---|
Source files |
Typically are located in a subdirectory of the WDK install directory, but can be anywhere. |
The Sources file lists the source files to be compiled and linked, and specifies values for certain macros. This file is required in each directory that contains source files. |
|
The Makefile file specifies dependency relationships, compiler and linker options, and various other build-related settings. Starting with the WDK for Windows Vista, this file is optional, In previous versions of the WDK, this file is required. If used, this file must be in each directory that contains a Sources file. |
|
Optional file that is used to compile source code in multiple subdirectories automatically. This file contains macros called DIRS and OPTIONAL_DIRS that specify the directories to open recursively and the order in which they should be opened. |
Build Utility Command Line
The Build utility (Build.exe) is invoked from the command line of your build environment window.
For a description of the command-line syntax, see Build Utility Command-Line Parameters. You can also use the command build -? to display the command-line syntax.
Build Utility Algorithm
The Build utility searches the Dirs file for the macros DIRS and OPTIONAL_DIRS. It then recurses to each directory listed in the Dirs file, searching for another Dirs file or a Sources file. Each additional Dirs file indicates another directory to recurse into. Each Sources file indicates a job to be built.
If Sources files are found, the Build utility searches for the macros, SOURCES, INCLUDES, TARGETNAME, and TARGETPATH. The values assigned to these macros are parsed to determine the dependencies, the list of files to build, and the end result. Generally, this information is then stored by the Build utility in a file called build.dat for future reference.
Depending on the options you pass to it, the Build utility performs the appropriate actions and then calls a make program. This program will be NMAKE, unless a different make program has been specified in BUILD_MAKE_PROGRAM.
Caution Specifying any other make program besides NMAKE is not recommended.
NMAKE uses the Makefile files to generate dependency and command lists. A standard Makefile located in the source code directory of every sample driver directs NMAKE to the master macro definition file, Makefile.def, that is included in the Windows Driver Kit (WDK). The Makefile you supply for your own source code should do the same.
Note Starting with the WDK for Windows Vista, Makefile is optional.
After locating the relevant make files, the Build utility might search for other files (Makefil0 and Makefile.inc). This occurs under the following conditions:
The Build utility is performing a clean build. To perform a clean build, run the Build utility and use the /clean or /c command-line arguments.
The NTTARGETFILE0, NTTARGETFILE1 or NTTARGETFILE2 macros are specified in the Sources file.
After the NMAKE utility evaluates the macros in all the relevant make files, it starts the C compiler (cl.exe) with the proper switches. After the compilation is complete, the Build utility again starts NMAKE, this time to link the compiled object files.
When the entire directory tree is built, the Build utility halts.
Send comments about this topic to Microsoft
Build date: 5/3/2011