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 阅读详情

一. 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 阅读详情

相关推荐

医疗AI新思路:为什么Graph Neural Network能改善气道分割的漏检问题?

本文探讨了Graph Neural Network(GNN)在医疗AI领域改善气道分割漏检问题的创新应用。通过分析3D UNet等传统方法的局限性,揭示了GNN在图结构建模中的独特优势,特别是在捕捉细小末梢支气管方面的突破性表现。文章详细介绍了UNet-GNN混合架构的设计原理、实验性能对比及优化方向,为CT影像分析提供了新思路。

weixin_30379531的博客 226

MAKEFILE 中使用source

由于项目缘故,需要在Makefile中执行source操作,按照规则,执行 make build,但是提示找不到命令:Makefile文件:.PHONY: buildbuild:        cd ../ source my.shmy.sh    文件:#!/bin/sh.PHONY: buildbuild:        echo gnu经过自我探索,修改后可以执行:.PHONY: build...

u011494885的博客 7939

Stata中介效应分析实战:从sgmediation安装到Sobel检验结果解读

本文提供了Stata中进行中介效应分析的完整实战指南,重点介绍了第三方命令sgmediation的安装、配置与使用。通过详细案例演示了如何运用Sobel检验分析变量间的间接效应,并深入解读检验结果,帮助研究者厘清自变量影响因变量的具体路径。文章还探讨了Sobel检验的原理、优缺点及结果报告规范,是进行实证研究的实用参考。

weixin_29197051的博客 637

ubuntu:在makefile中source一个脚本

source 是一个 bash 内置命令,man bash 然后找到 SHELL BUILTIN COMMANDS 部分。而 Makefile 要执行的话必须是能 fork 出进程的,所以无法执行。 makefile的默认shell是/bin/sh,本身不支持source 可以将shell切换成/bin/csh来支持source

hhd1988的专栏 1569

从无序到结构化:HAC框架如何用哈希网格重构3D高斯压缩范式 | ECCV2024技术解读

本文深入解读了ECCV 2024提出的HAC框架,它通过引入二值哈希网格为无序的3D高斯锚点建立空间结构,并利用上下文模型进行自适应量化,从而实现了对3D Gaussian Splatting模型的高效压缩。该方法将压缩范式从单纯削减数据转向智能理解数据关系,在保持高质量渲染的同时,显著提升了压缩率,为移动端部署和实时应用提供了新方案。

yolo5detector的博客 463

openEuler在虚拟机的网络配置

ethernet0.virtualDev 可以配置成其他类型的虚拟网络适配器。常见的选项包括:vlance - 用于模拟 AMD PCnet32 LANCE 网络适配器,支持10Mbps。e1000 - 用于模拟 Intel E1000 千兆网络适配器,支持1Gbps。e1000e - 用于模拟更现代的 Intel E1000e 千兆网络适配器。vmxnet - 用于 VMware 的自定义网络适配器,性能更好但需要安装 VMware Tools。

FHY1221的博客 2938

【转帖】解读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

【计算机视觉学习03】全景图像拼接

文章目录一、基本原理1.1 图像拼接的几何原理1.2 直线,圆,复杂曲线方程拟合1.3 RANSAC算法1.4 APAP算法1.5 寻找最佳拼接缝(Seam Finding)1.5.1 最大流问题1.5.2 最大流问题的增广链算法1.5.3 最大流最小割定理二、 图像拼接具体实现2.1 代码2.2 运行结果 一、基本原理 将两幅或多幅具有重叠区域的图像,通过特征匹配将具有相同的特征点(SIFT特征点)的图像拼接在一起,将来自多个不同视角拍摄的图像变换到同一视角下,拼接成一张宽视野图像。 图像拼接基础流程

一个正在努力学习的iter 7792

在makefile中source一个脚本

makefile的默认shell是/bin/sh,本身不支持source 可以将shell切换成/bin/csh来支持source 如下所示: #Makefile SHELL := /bin/csh rule: source env.sh && YourCommand

u011614141的博客 4059

Linkage Mapper 工具参数详解——Building Network and Map Linkages

此文档用于解析使用LinkageMapper各输入输出参数详情以及可能的影响,并介绍了如何解释模型输出结果和输出参数,适合刚入手的人。篇幅很长很啰嗦,是因为每个参数都解释的万分细致。

sumuses的博客 6128

Oracle EBS Interface/API(42) -AP发票客制化付款申请

背景 在OA系统上,选择Oracle EBS的某张AP发票做付款申请,需要类似于锁定该发票以便付款,其他用户或者下次用户不能再次选择该发票做付款申请。 快速参考 参考点 内容 功能导航 N: AP->Invoices->Entry>Invoices 并发请求 None 基表 AP.AP_INV_SELECTION_CRITERIA_ALLAP.AP_SELECTED_INVOICES_ALL API 参考下面介绍 错误信息表 None 接口Form

陈显平的专栏-Oracle EBS 1201

makefile-2

工作作用,将头文件放在include文件夹,cpp文件放在source文件夹,test.cc为可执行文件。方式一:$(shell shell_command)打印用info,Makefile提供了三个命令。结果输出当前工作目录:home/sc/test。三、简提Makefile中打印日志信息。表示比目标还要新的依赖文件列表。Makefile中,格式为这样的。一、理解$@、$^、$<的含义。$^ 表示所有的依赖文件。$< 表示第一个依赖文件。Makefile文件为。目标:需要依赖的条件。

wmzjzwlzs的专栏 276

Codex入门24-效率倍增秘籍(终极总结:10个让你开发速度翻倍的Codex高级技巧)

专栏收官之作!经过前23篇的系统学习,你已经掌握了 Codex CLI 的核心用法。本文浓缩10个实战验证的高级技巧:管道化提示词将复杂任务拆成递进指令链,模板化 SKILL.md 打造个人技能库,Shell 别名让操作快如闪电,多模型切换省钱又高效……这不是理论课,每个技巧都配有可直接运行的代码。掌握全部10招,构建你的 AI 开发工作流闭环,让开发速度真正翻倍!

yueyeguzhuo的专栏 193

makefile和source文件的编写

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

尘埃落定 2162

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

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

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

qq_40854508的博客 1162

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

解读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

312

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

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

将驱动编译进内核

将驱动编译进内核(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的博客 152

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
上一篇: 网络数据包拦截通用技术(协议驱动hook)
下一篇: DDK Sources文件语法处理
kaylc
博客等级 码龄16年 29粉丝 7原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值