[转]VC的DDK编译环境构建
http://blog.csdn.net/skdev/article/details/1336935
1 环境状况
Windows XP SP1 NTDDK(win2kddk) VC++6.0
NTDDK所在路径:D:/NTDDK
DDK 编译所需的文件:SetEnvCallBuild.bat BuildDriver.bat makefile makefile.mk source
SetEnvCallBuild.bat 是命令行(msdos)执行文件,参数:checked WXP或free WXP 两种
BuildDriver.bat是SetEnvCallBuild.bat调用的文件。
Makefile makefile.mk source 是build –cZ 用到的文件;makefile和makefile.mk不用修改,souce包含要编译的文件,用记事本编辑。
以下用NTDDK/src/wdm/usb/usbview为例
2 各文件的代码
文件名 SetEnvCallBuild.bat
//-----------------------------------
@echo on
REM %1
REM %2
set DDKPATH=D:/NTDDK
set PRJDRV=E:
set PRJPATH=driver
echo s1 %1
echo s2 %2
call BuildDriver.bat %DDKPATH% %PRJDRV% %PRJPATH% %1 %2
set DDKPATH=
set PRJDRV=
set PRJPATH=
----------------------------------------//
注:DDKPATH=D:/NTDDK为NTDDK安装的路径,PRJDRV=E E表示要编译文件所在盘符即E盘,PRJPATH=driver driver表示要编译文件所在的文件夹。
文件名 BuildDriver.bat
//------------------------------------
@echo off
REM %1
REM %2
REM %3
REM %4
REM %5
echo n1 %1
echo n2 %2
echo n3 %3
echo n4 %4
echo n5 %5
if %1=="" goto usage
if %3=="" goto usage
if not exist %1/bin/setenv.bat goto usage
call %1/bin/setenv.bat %1 %4 %5
%2
cd %3
build –cZ
goto exit
:usage
echo usage Make sure your DDK path is valid!
:exit
---------------------------------------------//
文件名 makefile
//--------------------------------------------
#############################################################################
#
# Copyright (C) Microsoft Corporation 1992-1997
# All Rights Reserved.
#
# makefile for USBVIEW
#
#############################################################################
# Paths are relative to the directory containing this file.
!IFDEF WIN95_BUILD
# Root of the SLM tree (i.e. the directory containing the DEV project).
!IFNDEF ROOT
ROOT = ../../../..
!ENDIF
DEFAULTVERDIR = retail
VERSIONLIST = retail debug
IS_32 = TRUE
COMMONMKFILE = makefile.mk
!include $(ROOT)/DEV/MASTER.MK
!ELSE
!include $(NTMAKEENV)/makefile.def
!ENDIF
--------------------------------------//
文件名 makefile.mk
//-----------------------------------------
#############################################################################
#
# Copyright (C) Microsoft Corporation 1996-1998
# All Rights Reserved.
#
# makefile.mk for USBVIEW
#
#############################################################################
ROOT = ../../../../..
NAME = USBVIEW
SRCDIR = ..
IS_32 = TRUE
WANT_C1132 = TRUE
WANT_WDMDDK = TRUE
IS_DDK = TRUE
L32EXE = $(NAME).exe
L32RES = ./$(NAME).res
L32LIBSNODEP = kernel32.lib user32.lib gdi32.lib comctl32.lib libc.lib cfgmgr32.lib
TARGETS = $(L32EXE)
DEPENDNAME = $(SRCDIR)/depend.mk
RCFLAGS = -I$(ROOT)/DEV/INC
# Enable read-only string pooling to coalesce all the redundant strings
#
CFLAGS = -GF
L32OBJS = usbview.obj /
enum.obj /
display.obj /
debug.obj /
devnode.obj /
dispaud.obj
!INCLUDE $(ROOT)/DEV/MASTER.MK
----------------------------------------//
文件名 source
//--------------------------------------------
TARGETNAME=usbview
TARGETTYPE=PROGRAM
TARGETPATH=obj
UMTYPE=windows
UMENTRY=winmain
UMBASE=0x1000000
TARGETLIBS=/
$(SDK_LIB_PATH)/kernel32.lib /
$(SDK_LIB_PATH)/user32.lib /
$(SDK_LIB_PATH)/gdi32.lib /
$(SDK_LIB_PATH)/comctl32.lib /
$(SDK_LIB_PATH)/cfgmgr32.lib
INCLUDES=../inc;../../inc
SOURCES=usbview.c /
display.c /
enum.c /
debug.c /
devnode.c /
dispaud.c /
usbview.rc
-------------------------------------------//
SOURCES 所列的文件为需编译的。
3 创建工程
1) 新建工程
选择makefile
2) 在Debug中创建check版的驱动
注:WXP 为Windows XP
3) 在Release中创建free版驱动
4) 导入文件
5) 编译工程
6) 生成结果
生成objchk/i386中的usbview.exe
说白了原理与在dos编译一样
如下为dos编译方法
setenv即为setenv.bat 其参数为ntddk所在路径
表示环境创建成功
然后到要编译的目录下运行build –cZ 注意:该目录下必需的makefile makefile.mk source文件
运行结果
完成。
参考:啊良的”使用VC6编译Driver”