source文件和makefile文件编写

CMake基础教程(2)在Linux下为一个最简单的工程写一个最简单的CMakeLists.txt生成Makefile 文章标题很长,但是交代了所有的要素: 指定平台是linux,事情是写个简单的CMakeLists.txt,目标是生成Makefile,完成编译,前提条件是准备一个最简单的工程。 入门案例1:单个源文件 strep 1: 对于简单的项目,只需要写几行代码就可以了。例如,假设现在我们的项目中只有一个源文件 main.cc ,该程序的用途是计算两个数相加。 #include <stdio.h> #include <stdlib.h> long long add(int para1, in 阅读详情


http://blog.csdn.net/kaylc/article/details/6263296


一. makefile (没有扩展名,它名字就叫makefile),内容如下:
  !INCLUDE $(NTMAKEENV)/makefile.def
  WDM程序使用的所有makefile都这样写,我们只需写一个,编译时把它拷贝到工作目录下就行了
  二. sources文件就需要我们根据不同的场合修改了,不过基本模板如下:

  TARGETNAME=驱动程序名 //(不含扩展名)

  TARGETPATH=obj // 固定不变

  TARGETTYPE=DRIVER // 固定不变(表明,连接成*.sys文件)

  DRIVERTYPE=WDM // 为 Win32 Driver Model 驱动

  INCLUDES=$(BASEDIR)/inc/ddk;$(BASEDIR)/inc // 源程序可能使用的DDK头文件所在的目录,多个目录用";" 隔开,多个文件用 '空格' 隔开

  其中"$(BASEDIR)"指DDK当前的安装目录,【windows通过添加系统环境变量即可】例如当前DDK安装在D:上,则$(BASEDIR) 就是 "D:/DDK",所以上面的INCLUDES可以翻译成D:/DDK/inc/ddk; D:/DDK/inc

  三. 注意:

  1. 编译时必须保证 makefile,sources和源程序在同一目录下

  2. 编写sources文件时,其中的"="两边不能有空格

  3. 工程的工作目录的绝对路径中不能出现空格,而且表面上看来DDK好像是完成的编译,实际上它什么都没做!

官方说明:

The sources file
This is where build gets most of its directives. Here are some of the more important ones — and note that the first four are required:

TARGETNAME: This required directive specifies the name of the intended binary. For example, you might give TARGETNAME=MyDriver (build will append .sys to the driver’s name).
TARGETTYPE: This required directive dictates the type of binary to be built. Most common are:
TARGETYPE=DRIVER for a plain-vanilla driver (a .sys file).
TARGETTYPE=EXPORT_DRIVER for a driver that exports entry points as a DLL does. (The resulting binary is a .sys file.) A kernel DLL is such a creature. See Tim Roberts’ article about kernel-mode DLLs for more information about this option.
TARGETTYPE=DRIVER_LIBRARY (or TARGETTYPE=LIBRARY) for a .lib binary that will be link-edited into an executable. This feature is typically used when there are two or more source directories (perhaps because each is owned by a different developer). The sources file in one directory could have TARGETTYPE=DRIVER (for a .sys file); the sources in the second (or third, etc.) directory would give TARGETTYPE=DRIVER_LIBRARY. A complete sources file has an example.
TARGETTYPE=PROGRAM for a user-space program (an .exe file), for example, a program to call the driver.
TARGETTYPE=DYNLINK for a user-space DLL, which an .exe file might use.
In case you’re wondering how names like ntoskrnl.exe and hal.dll are generated for kernel modules, the answer is that build has special-case logic. Don’t try to create kernel modules of your own with an extension of .exe or .dll.

TARGETPATH: This required directive says where to put the binary.
Note: The specific form TARGETPATH=lib$(BUILD_ALT_DIR) is often employed, and the resulting directory path is one beneath the one where the sources file is located; for a WinXP checked-build target, that path would be libchk_wxp_x86/i386. The path name comes from concatenating “lib” with the evaluated environmental variable BUILD_ALT_DIR (see environmental variables) and with “/i386,” which designates the platform type. If you’re using this form to produce a .lib file, you will specify the file’s path in TARGETPATH differently from the way you will specify the path for that same file in building an executable incorporating the .lib file (see TARGETLIBS).

SOURCES: This required directive names the source files. For example,
SOURCES= /
BozoStuff.cpp /
miniport.c /
passthru.c /
passthru.rc /
protocol.c /
UtilRtns.c

Notice the mixture of .c and .cpp files: The compiler’s default action is to apply C or C++ language rules according to file type.

Note: If a directive is to have more than one entry, you may specify all on a single line, or you may put them on several lines, but then you must end each line with a backslash and no following characters, not even blanks. This restriction applies to directives in sources files and in dirs files.

A further note: In SOURCES, names can take the form filename.ext, ./ filename.ext and ../ filename.ext, but not ../../ filename.ext and not a fully qualified name like c:/dir/ filename.ext. That is another quirk of build.

INCLUDES: This specifies the directories for any header files (other than the target OS’s standard directories). For example,
INCLUDES= /
./inc /
C:/JA.pgm/src/C/Drivers/JADriver/inc

Note: Unlike SOURCES, INCLUDES allows forms like ../../Dir and fully qualified directory paths. Do not, however, specify paths with imbedded blanks. Instead, use the 8.3 name (you can discover the 8.3 names of directories and files below a directory by issuing the command dir /x <directory> in a command window).

C_DEFINES: A directive to affect compilation. Its value is passed to the C compiler (and to the MIDL compiler). See compiler parameters for some possibilities.
USER_C_FLAGS: Another directive to affect compilation. Its value is passed to the C/C++ compiler. For example,
USER_C_FLAGS=$(USER_C_FLAGS) /FAsc

would pick up any value defined in the environmental variable USER_C_FLAGS in the command window and would append /FAsc to that value. See compiler parameters for other possibilities.

MSC_OPTIMIZATION: This overrides the default compiler optimization of build. A checked build will have /Od /Oi, to prevent optimization.
MSC_WARNING_LEVEL: This controls the compiler’s warning level. The default is /W3, but it is better practice to set it to /W3 /Wx so that warnings are considered errors.
TARGETLIBS: This names one or more libraries needed by link-edit to resolve references (APIs, sections of code, variables). Many OS libraries like ntoskrnl.lib are automatically searched, but you may need to specify some. If you were building an NDIS intermediate driver, for example, you would specify TARGETLIBS=$(DDK_LIB_PATH) /ndis.lib. And you would of course name any libraries of your own.
Note: TARGETLIBS does not have the quite same special handling that TARGETPATH does. If you created a .lib file with a path of TARGETPATH=lib$(BUILD_ALT_DIR), in the sources file for the .sys file you would designate the .lib file’s path more fully, by lib$(BUILD_ALT_DIR)/*/ (asterisk means implicit platform type).

To make the point above clear, let’s suppose you have this for the .lib file:

TARGETNAME=DriverPart2
TARGETTYPE=DRIVER_LIBRARY # output is a .lib file
TARGETPATH=lib$(BUILD_ALT_DIR) # where to put the .lib file.

For the .sys file, you would have:

TARGETNAME=MyDriver
TARGETTYPE=DRIVER # output is a .sys file
TARGETLIBS=lib$(BUILD_ALT_DIR)/*/DriverPart2 # where to find the .lib file.
TARGETPATH=lib$(BUILD_ALT_DIR) # where to put the .sys file.

LINKER_FLAGS: This is information supplied to the linker as a parameter. If you want the linker to produce a map, for example, specify "-MAP" as the value of this parameter.
Browser information: You specify this if you intend to use the Visual Studio browser to find definitions of APIs, symbols and variables (see browsable defintions); in a large project, especially in one to which you are new, this capability is a very handy one. You need two directives to get browser information: the first to make build create it, and the second to indicate the name of the browser database file.
BROWSER_INFO=1
BROWSERFILE=$(TARGETNAME).bsc -n

You can use conditional logic. For example:
!if !defined(DDK_TARGET_OS) || "$(DDK_TARGET_OS)"=="Win2K"
# The driver is for Win2K. Build with NDIS 4.0
C_DEFINES=$(C_DEFINES) -DNDIS40_MINIPORT=1
C_DEFINES=$(C_DEFINES) -DNDIS40=1
!else
# The driver is for WinXP or Win2003, so build# with NDIS 5.1.
C_DEFINES=$(C_DEFINES) -DNDIS51_MINIPORT=1
C_DEFINES=$(C_DEFINES) -DNDIS51=1
!endif

Putting it all together, you might have this in a complete sources file:

TARGETNAME=MyPassthru
TARGETYPE=DRIVER
TARGETPATH=lib$(BUILD_ALT_DIR)
TARGETLIBS=$(DDK_LIB_PATH)/ndis.lib

SOURCES= /
BozoStuff.cpp /
miniport.c /
passthru.c /
passthru.rc /
protocol.c /
UtilRtns.c

INCLUDES= /
./inc /
C:/JA.pgm/src/C/Drivers/JADriver/inc

USER_C_FLAGS=$(USER_C_FLAGS) /FAsc

!if !defined(DDK_TARGET_OS) || "$(DDK_TARGET_OS)"=="Win2K"
C_DEFINES=$(C_DEFINES) -DNDIS40_MINIPORT=1
C_DEFINES=$(C_DEFINES) -DNDIS40=1
!else
C_DEFINES=$(C_DEFINES) -DNDIS51_MINIPORT=1
C_DEFINES=$(C_DEFINES) -DNDIS51=1
!endif

BROWSER_INFO=1
BROWSERFILE=$(TARGETNAME).bsc -n

You can find a full list of build directives in the DDK documentation under the heading “Build Utility Macros.”

Note: After you make a change in a sources file, it is usually necessary to rebuild completely to pick up the changes.  

【C++之Makefile基础实践】MakeFile从入门到精通 makefile 阅读详情

相关推荐

Origin软件XRD全峰拟合保姆级教程:从数据导入到弱峰处理技巧

本文提供了一份Origin软件进行XRD全峰拟合的深度实战指南。文章重点解析了从数据导入预处理、基线锚点视觉化设置,到弱峰拟合的锁定策略与手动干预等核心技巧,旨在帮助用户避开常见错误,获得可靠、精确的拟合结果,从而有效服务于材料结构分析。

rgv2345678的博客 719

【转帖】解读makefile和source文件

 编译驱动 需要三个文件:源文件(假设只有一个), MAKEFILE, SOURCE总共三个文件。源文件是你的驱动程序了。MAKEFILE如下: ## DO NOT EDIT THIS FILE!!! Edit ./sources. if you want to add a new source# file to this component. This file merely indirec

floweronwarmbed的专栏 1089

ERA5数据批量下载

ERA5再分析数据的IDM接管下载

qq_38734327的博客 3045

makefile、source和INF文件

一般编译驱动需要3个文件,源文件,makefile文件,和SOURCE文件。       (1)makefile文件       !INCLUDE $(NTMAKEENV)/makefile.def,就一句话,不做特殊设置不用修改       最近编译codeproject上的《driver development part》上的例子,报了error C2220的错误,是说警告级别太高,不过

kuaixue1023的专栏 1199

ansys workbench 静力结构分析 高阶教程

ansys workbench 静力结构分析 高阶教程 目录ansys workbench 静力结构分析 高阶教程新建工程模型导入设置材料模型简化: 主要内容: 材料设置、模型简化、网格细化、约束分析、接触设置、求解设置、报错处理、结果分析 基础教程: ansys workbench 静力结构分析 基础操作流程(入门) ansys版本: 19.0(16.0及以上均可) 参考资料: 推荐教学视频《有限元分析 张晔》(超详细 ???? )、ansys workbench 超级学习手册(查阅用) 说明:一些基

weixin_43434624的博客 5万+

用AI从0开始量化交易-制定学习计划安装学习环境

量化小白,利用AI从零开始学量化

weixin_52285994的博客 2117

makefile和source文件的编写

在xp下使用window ddk里面的build对ndis程序进行编译得到ndis驱动程序时,在ndis程序包里面需要有 makefile文件和source文件,如果在ndis程序包里面还有子目录的话,那还需要有dirs文件source:TARGETNAME=passthru // 生成的驱动程序名为passthru.sysTARGETPATH=obj  //生

尘埃落定 2162

WinCC与施耐德PLC的Modbus TCP通信实战指南

本文详细解析了西门子WinCC与施耐德PLC通过Modbus TCP协议实现通信的完整实战流程。内容涵盖硬件网络配置、Modbus地址映射核心规则、WinCC驱动连接建立、变量创建及高级数据访问技巧,并提供了常见故障排查思路,帮助工程师高效解决跨品牌设备通信难题。

weixin_29194693的博客 1017

Makefile的编写

1生成可执行文件: #source file #源文件,自动找所有.c和.cpp文件,并将目标定义为同名.o文件 SOURCE := $(wildcard *.c) $(wildcard *.cpp) OBJS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE))) #target you can change test to w...

sinat_34080511的博客 325

基于Verilog的8位CPU设计及UART扩展实现方案,包含完整的架构设计、核心代码实现和仿真验证方法

基于Verilog的8位CPU设计及UART扩展实现方案,包含完整的架构设计、核心代码实现和仿真验证方法

a_zxswer的博客 197

【教程4>第8章>第10节】OFDM完整通信链路项目的FPGA开发4——插入导频

本文介绍了基于MATLAB和Verilog的导频插入设计与实现方法。首先回顾了MATLAB中导频插入的算法实现,展示了每32个数据插入一个导频的设计。接着详细说明了Verilog硬件实现方案,包括导频序列定义、计数器设计、FIFO模块等关键部分。通过仿真测试验证了设计的正确性,输出了插入导频后的序列、导频序列以及调整时序后的序列。最后提供了相关视频教程资源,帮助读者理解设计过程。该设计实现了数据与导频的精确插入,为OFDM等通信系统开发提供了实用参考。

FPGA/MATLAB学习教程/源码/项目合作开发 401

一个通用的makefile文件应该怎么写

目标文件名为demo#没有去掉符号表和调试信息的目标文件版本#map文件包含目标文件链接阶段的细节内容,通常包含全局符号,交叉引用和内存映射等信息#交叉编译工具链#C语言编译工具gcc#C++编译工具g++#GNU中用来将目标文件打包为静态链接库的工具#GNU链接器,用来将目标文件与库链接为可执行文件#GNU中的用来裁剪调试信息与符号表的工具#GNU中AR的子工具,用来为归档文件创建符号表索引,符号表文件可以让链#接器快速查找函数符号在相应对应文件的位置。

qq_40854508的博客 1162

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

解读makefile和source文件

 需要三个文件:源文件(假设只有一个), MAKEFILE, SOURCE总共三个文件。源文件是你的驱动程序了。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

313

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

linux拷贝带子文件夹命令,简单带子目录的makefile练习

开始学linux。我练习写的第一个带子目录的makefile文件。1。建立文件夹 wulongwulong中含 三个文件夹 include source pro 和makefile文件。include 中包含 hai.h头文件。source 中包含 hello.c文件。pro 中包含 haia.c haib.c文件。makefile文件内容有两种写法:makefile 第一种写法://**...

weixin_36484519的博客 544

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

将驱动编译进内核

将驱动编译进内核(Kconfig以及Makefile编写)

qq_43707773的博客 1076

环境搭建及工具、概念介始 (makefile)

一、安装 1,安装ubuntu 2,安装虚拟机,然后打开虚拟机,二、安装windows下的配套开发工具。 1,源码编辑查看源码工具:source insight 如何查看uboot源代码? 在uboot源代码新建一个目录si,这个目录用于source insight临时生成的文件;然后新建一个source insight工程,加入相应的文件到目录(可以先全部加入,然后删除不需要的单板对应

我的专栏 1052

各种执行方式

g++文件:先在文本里面编辑,记得调成c++,然后保存,命令:g++ “文本名”;./a.out;完成 shell脚本:source 一下或者bash一下 makefile:先编写各个组件,几个.cc文件,一个main,一个声明.h文件,一个makefile文件,名字必须叫做makefile,然后命令:make;./app 转载于:https://www.cnblogs.com...

apyasb2125的博客 153

2006 年6月23日

我为网上下载的一个TDI的源代码写了一个source文件,可是编译时却出现了如下问题。cant open include file "netpnp.h"以及cant open input file "wdm.lib"最后发现了问题所在,再次总结一下:      出的问题:makefile的问题,微软建议一般都用微软自带的makefile,不要改动,如果改动,就改动source文件,有些

勇敢的心的专栏 770

cmake 基本使用过程

cmake 的使用。aux_source_directory( ) 与set( target.cpp)的区别,include_directories(${PROJECT_SOURCE_DIR}/include) 与target_include_directories(sum11 PRIVATE ${PROJECT_SOURCE_DIR}/include)

JACKSONMHLK的博客 975

菜鸟之驱动开发1

在之前一篇文章里介绍驱动开发环境搭建过程,现在就开始写驱动了。我是照着郁金香的视频教程学习驱动开发的。那驱动有些课时比较多余,我在学习的过程当中会终合考虑合并一些课时。今天这一课是学着写一个驱动的helloworld,并用WDK环境编译成sys文件。为了对驱动开发有一个更深入的了解,我在此并没有用我之前搭建好的VS2010驱动便宜环境,而是直接用notepad++,它是一个记事本的扩展程序,支持语...

mmdev 199

CMake学习

简介 cmake 是一个跨平台的自动构建工具, 前面导语部分也已经给大家介绍了, cmake 的诞生主要是为了解 决直接使用 make+Makefile 这种方式无法实现跨平台的问题,所以 cmake 是可以实现跨平台的编译工具,这是它最大的特点。 cmake和Makefile区别 这是我刚开始模糊的原因,就是cmake和Makefile这两者间有什么区别,为什么要用cmake,他有什么优点么?为什么github上很多项目都用camke?他到底是作什么用的。现在我们来看一个图,这是我从正点原子的手册上看到的

qq_38956489的博客 5614
上一篇: 如何调用WebService
下一篇: C#解析HTML
令羽飞飞
博客等级 码龄14年 42粉丝 166原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值