利用ddk自带的工具build.exe编译windows驱动

1、在开始菜单中选择合适的Build Environments(选择的Build Environment一定要和编译好的驱动运行的平台相同),这一步就会在打开的cmd窗口中设置好环境变量。
2、 从DDK示例源代码目录拷贝makefile文件到你的驱动源文件目录中,并建立sources文件(可根据msdn帮助文件中的sources模板文件 修改),其中makefile文件模板一般不用修改,修改sources文件为自己所需要的,如何修改sources文件可参考msdn帮助文件。
3、在1中打开的cmd窗口中cd到源代码目录,执行build -ceZ命令即可。

 

附:makefile及sources标准模板

 

1)makefile:

#
# DO NOT EDIT THIS FILE!!!  Edit ./sources. if you want to add a new source
# file to this component.  This file merely indirects to the real make file
# that is shared by all the components of Windows NT
#
!INCLUDE $(NTMAKEENV)/makefile.def


2)sources:

/*****************************************************************
* Using this sources template
* 1、Copy the contents of this topic to the Clipboard.
* 2、Paste this topic into a file using a text editor.
* 3、Replace the xxxxx in the TARGETNAME macro with your target name. For example:
*     TARGETNAME=myprogram
* 4、Edit the TARGETPATH and TARGETTYPE macros to specify the location and type of the target.
* 5、Edit the INCLUDES macro if you have a private include directory to search.
* 6、Carefully edit the SOURCES macro so that it defines all the source files for the component that you are building.
* 7、Remove these instructions and all comments.
* 8、Save this file under the name "sources" (not "source.txt"), and quit the text editor.
* 9、Run the Build utility from the command line by typing build and pressing ENTER.
* 10、After you have completed these steps, you can run either the Build utility or NMAKE to build the component.
******************************************************************/

#
# The developer defines the TARGETNAME variable. It is the name of
# the target (component) that is being built by this makefile.
# It should not include any path or filename extension.
#
TARGETNAME=xxxxx
#
# The developer defines the TARGETPATH and TARGETTYPE variables.
# The first variable specifies where the target will be built. The second specifies
# the type of target (either PROGRAM, DYNLINK, LIBRARY, UMAPPL_NOLIB or
# BOOTPGM). Use UMAPPL_NOLIB when you are only building user-mode
# programs and do not need to build a library.
#
TARGETPATH=obj
# Select one of the following, and delete the others:
TARGETTYPE=PROGRAM
TARGETTYPE=DYNLINK
TARGETTYPE=LIBRARY
TARGETTYPE=UMAPPL_NOLIB
TARGETTYPE=BOOTPGM
TARGETTYPE=DRIVER
TARGETTYPE=DRIVER_LIBRARY
TARGETTYPE=EXPORT_DRIVER
TARGETTYPE=GDI_DRIVER
TARGETTYPE=MINIPORT
TARGETTYPE=NOTARGET
TARGETTYPE=PROGLIB#
# If your TARGETTYPE is DRIVER, you can optionally specify DRIVERTYPE.
# If you are building a WDM Driver, use DRIVERTYPE=WDM, if you are building
# a VxD use DRIVERTYPE=VXD. Otherwise, delete the following two lines.
#
DRIVERTYPE=WDM
DRIVERTYPE=VXD
#
# The TARGETLIBS macro specifies additional libraries to link against your target
# image. Each library path specification should contain an asterisk (*)
# where the machine-specific subdirectory name should go.
#
TARGETLIBS=
#
# The INCLUDES variable specifies any include paths that are specific to
# this source directory. Separate multiple paths with single
# semicolons. Relative path specifications are okay.
#
INCLUDES=../inc
#
# The developer defines the SOURCES macro. It contains a list of all the
# source files for this component. Specify each source file on a separate
# line using the line-continuation character. This minimizes merge
# conflicts if two developers are adding source files to the same component.
#
SOURCES=source1.c /
source2.c /
source3.c /
source4.c
i386_SOURCES=i386/source1.asm
IA64_SOURCES=ia64/source1.s
#
# Next, specify options for the compiler using C_DEFINES.
# All parameters specified here will be passed to both the C
# compiler and the resource compiler.
C_DEFINES=
#
# Next, specify one or more user-mode test programs and their type.
# Use UMTEST for optional test programs. Use UMAPPL for
# programs that are always built when the directory is built. See also
# UMTYPE, UMBASE, and UMLIBS. If you are building a driver, the next
# 5 lines should be deleted.
#
UMTYPE=nt
UMTEST=bunny*baz
UMAPPL=bunny*baz
UMBASE=0x1000000
UMLIBS=obj/*/bunny.lib
#
# Defining either (or both) the variables NTTARGETFILE0 and/or NTTARGETFILES
# causes makefile.def to include ./makefile.inc immediately after it
# specifies the top level targets (all, clean and loc) and their dependencies.
# The makefile.def file expands NTTARGETFILE0 as the first dependent for the
# "all" target and NTTARGETFILES as the last dependent for the "all" target.
# This is useful for specifying additional targets and dependencies that do not fit the
# general case covered by makefile.def.
#
# NTTARGETFILE0=
# NTTARGETFILES=

你可能感兴趣的:(windows,Build,工具,include,makefile,DDK)