Building Multiple Targets from One Subdirectory

If your driver must run on more than one Microsoft Windows operating system, or support more than one hardware architecture, you can organize your builds in any of the following ways:

  • Use a single set of source files and create a single binary.

  • Use a single set of source files and create more than one binary.

  • Use more than one set of source files and create more than one binary.

In the simplest scenario, you can use a single source directory with a single Sources file to build a single executable file or driver.

However, the Build utility allows you to have a single subdirectory where you can build multiple executable output files.

It is easiest to use a single set of source files, regardless of the number of binaries to be created. If at all possible, avoid using more than one set of sources. Instead, use preprocessor symbols to isolate system-specific and architecture-specific code, and conditionally compile. Maintenance and debugging are significantly simplified when you use a single set of sources.

Building Multiple Drivers from a Single Set of Source Files

To develop a driver that will run on multiple Windows operating systems, use a single set of source files and create a single binary. However, sometimes it is not possible to generate a single binary that supports all target operating systems. Nevertheless, in such a case you should use the same source code and build the drivers as follows:

  1. Surround any system-dependent features with conditional compilation directives.

  2. Put all source files in one directory. For example, mydriver.

  3. Create a subdirectory for each target operating system. For example:

    mydriver\Vistamydriver\XP

  4. In each system-specific subdirectory, put the Makefile, Makefile.inc, and other system-dependent build files:

    mydriver\Vista\Makefilemydriver\Vista\Makefile.inc

    mydriver\XP\Makefilemydriver\XP\Makefile.inc

    Note  Starting with the WDK for Windows Vista, Makefile is optional. In this example, it is not necessary to have Makefile in the mydriver\Vista folder.

  5. In each system-specific subdirectory, create a Sources file that refers to the source files in the parent directory, as in the following example:

    TARGETNAME=MYDRIVER
    TARGETTYPE=DRIVER
    DRIVERTYPE=WDM
    
    C_DEFINES=-DDRIVER
    
    INCLUDES=..\..\inc;
    
    SOURCES= \
            ..\main.c \
            ..\vars.c \
    

    This Sources file creates a WDM driver named MYDRIVER, using source files from the parent directory and header files from an inc directory at the same level as the parent directory. Output files are put in a subdirectory whose name is based on the build environment type, the platform, and the Windows version for which they are built. Log files use a similar naming convention. For more information, see Specifying the Location of Created Files.

Note   To do this in Visual Studio, you must create a project file (.dsp) for each target operating system. Each project file should specify the preprocessor options that are required to build the driver on the target operating system. In addition, create a subdirectory for each target operating system. Direct the output object (.obj) and dynamic-link library (.dll) files for each target system to the corresponding subdirectory.

 

 

Send comments about this topic to Microsoft

Build date: 5/3/2011