Compiling Your Driver

Windows NT DDK drivers are built using the build utility, which uses a set of rules and project files which specify how drivers should be created.

The dirs file specifies which directories in the subtrees contain source code files which are to be built. The sources file specifies which source files are required to build the current driver.

If your driver will consist of multiple binaries, or the source will be kept in multiple directories, you may need to create a dirs file specifying which directories are to be built and in what order. Each separate binary will require a sources file describing which files are to be compiled/linked to create the driver.

Each driver directory also contains a makefile. As build spawns the nmake utility for each source file listed in sources, nmake uses the makefile to generate dependency and command lists. The standard makefile in a driver source code directory directs nmake to the master nmake macro definition file, makefile.def. This file defines the flags for the build tools such as the compiler and linker. makefile.def simplifies the creation of platform-independent driver projects and is similar to the ntwin32.mak file in the Win32 SDK.

Once you have your dirs, sources and makefile files created, the next step is to run build. Build will parse the sources file and spawn nmake for each source file. Nmake will evaluate the macros in makefile.def and spawn the C compiler with the proper switches. After the compile stages are completed, build will spawn nmake again to link the objects and complete the driver building phase.

If your sources file is correct, running build is all that is required to compile and link your driver. Using build and makefile.def removes the guesswork from such things as which compiler switches are required, and what arguments the linker requires. By adding the appropriate defines to the sources file, it is possible to control the build options in a platform-independent fashion.

During driver development you will need to build free and checked versions of your driver. This is controlled by environment variable settings which are interpreted by build and nmake. These variables are set by setenv.bat, as discussed previously. To build a free driver, run build from the free environment. To build a checked driver, run build from the checked environment.

Template files (.tpl) for dirs, sources, makefile, and other files can be found in the \<destination>\doc directory. Working versions of these files can be found in driver source subdirectories of the DDK. Examining these files along with makefile.def (located in the \<destination>\inc directory) will provide additional information.

For more information about the build utility, see the Windows NT DDK Programmer’s Guide .