编译驱动模块所需的Makefile
目标定义:就是用来定义哪些内容作为模块编译,哪些内容要编译并链接进内核。
obj-y += foo.o 表示要由foo.c或者foo.s文件编译得到foo.o并链接进内核;
obj-m则表示该文件要作为模块编译。
简洁版
#General Purpose Makefile for Linux Kernel module by guoqingbo KERN_DIR = /home/gaoxingpeng/dm365/dvsdk_dm365_4_02_00_06/psp/linux-2.6.32.17-psp03.01.01.39
#KERN_DIR = /usr/src/$(shell uname -r)
#KERN_DIR = /lib/modules/$(shell uname -r)/build all:
make -C $(KERN_DIR) M=$(shell pwd) modules ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-
clean:
make -C $(KERN_DIR) M=$(shell pwd) modules clean
rm -rf modules.order obj-m += xxx.o
第3行KERN_DIR表示内核源码目录,这种方式适用于嵌入式开发的交叉编译,KERN_DIR目录中包含了内核驱动模块所需要的各种头文件及依赖。若在PC机开发内核模块则应使用第4、5行的写法。
第8行中-C表示 指定进入指定的目录即KERN_DIR,是内核源代码目录,调用该目录顶层下的Makefile,目标为modules。
M=$(shell pwd)选项让该Makefile在构造modules目标之前返回到模块源代码目录并在当前目录生成obj-m指定的xxx.o目标模块。
clean这个目标表示将模块清理掉
obj-m += xxx.o即指定当前目录要生成的目标模块,然后modules目标指向obj-m变量中设定的模块
通用规范版
# Makefile2.
ifneq ($(KERNELRELEASE),)
#kbuild syntax. dependency relationshsip of files and target modules are listed here. mymodule-objs := hello.o
obj-m := hello.o else
PWD := $(shell pwd) KVER ?= $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build #KDIR目录其实是链接到上面那个Makefile中的那个
/usr/src/linux-source-2.6./*中
all:
$(MAKE) -C $(KDIR) M=$(PWD) clean:
rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions endif
编译驱动模块所需的Makefile的更多相关文章
- 编译驱动模块时,出现“stack protector enabled but no compiler support”[解决办法]【转】
转自:http://blog.chinaunix.net/uid-26847859-id-3297170.html 原文地址:编译驱动模块时,出现“stack protector enabled bu ...
- mooon编译系统介绍(可复用Makefile)
mooon编译系统介绍(可复用Makefile).pdf(ChinaUnix下载) CSDN下载:http://download.csdn.net/detail/aquester/5626929 mo ...
- 批量编译目录下文件的Makefile
1.多C文件生成各自可执行文件的Makefile如果一个目录下有很多C文件,且每个C文件都能生成一个独立的可执行文件,那么想全编译这些C文件并生成各作的可执行文件,在该目录下编写一个Makefile文 ...
- Linux 内核源码外编译 linux模块--编译驱动模块的基本方法
1.先编写一个简单的hello模块,hello.c 源码如下: #ifndef __KERNEL__ # define __KERNEL__ #endif #ifndef MODULE # defin ...
- 使用itop4412开发板单独编译驱动模块
上面我们的驱动是放在了内核源码的目录下来实现的编译成驱动模块,很多时候我们都是拿到一个驱动源码,不需要把他放到内核源码里面,而是直接把他编译成驱动模块,下面我们来讲下实现方法,我们还是以蜂鸣器的驱动为 ...
- [编译] 1、第一个makefile简单例子
前言 本篇用一个最简单的例子引入makefile,教你编写第一个makefile 正文 在Download/aa文件夹下有a.c和makefile文件 litao@litao:~/Downloads/ ...
- gcc编译, gdb调试, makefile写法
//test.c: #include <stdio.h> int main(void) { printf("hello world!"); return 0; } == ...
- 三、编译第一步 make xxx_defconfig——Makefile.build 脚本
3.1 上章分析回顾 3.1 上章分析出的参数 3.1.1 变量 MAKECMDGOALS = xxx_defconfig KBUILD_EXTMOD = version_h := include/g ...
- Python在Linux下编译安装报错:Makefile:1141:install
正常情况下执行:./configuremake && make install可以直接安装python,但是在在更新了乌版图后居然报错了!!!检查了一圈,发现乌版图安装了python3 ...
随机推荐
- Errors occurred during the build. Errors running builder 'Integrated External Tool Builder' on proje
Errors occurred during the build. Errors running builder 'Integrated External Tool Builder' on proje ...
- ActionFilterAttribute
https://msdn.microsoft.com/en-us/library/system.web.mvc.actionfilterattribute.onactionexecuting(v=vs ...
- Swift3.0 split函数切割字符串
我们先看函数的原型: public func split(separator: Self.Iterator.Element, maxSplits: Int = default, omittingEmp ...
- 【POI 2007】 山峰和山谷
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1102 [算法] 广度优先搜索 [代码] #include<bits/stdc+ ...
- Nginx实战系列之功能篇----后端节点健康检查
目前,nginx对后端节点健康检查的方式主要有3种,这里列出: 1.ngx_http_proxy_module 模块和ngx_http_upstream_module模块(自带) 官网地址: ...
- [转载]RouteOS安装设置
原文地址:RouteOS安装设置作者:抟鹏追梦 RouteOS2.7.4可以将一台普通的PC机变成一台专业的路由器,高到ISP的核心路器/认证网关-因为它功能强大稳定,低到家庭网关防火墙-因为它免费. ...
- firewalld使用
1.firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status f ...
- hiho一下 第172周
题目1 : Matrix Sum 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You are given an N × N matrix. At the beginn ...
- express jade ejs 为什么要用这些?
express是快速构建web应用的一个框架 线上文档 http://www.expressjs.com.cn/ 不用express行不行呢? 看了网上的回答:不用express直接搭,等你 ...
- poj1111 Image Perimeters 广搜
题目大意: 输入一个矩阵,再输入其中一个“X”的位置(从1开始).从该位置向八个方向扩展,如果是“X”就可以并在一起.问最后得到的模块的周长是多少. 解题思路: 按照广搜的思路来做.用一个二维的数组标 ...