makefile配置文件

Makefile Kconfig .config

makefile:编译源文件的方法。
Kconfig:配置。
.config:编译内核所依据的配置。

makefile

(1)直接编译

obj -y +=xxx.o

表示由xxx.c或xxx.s编译得到xxx.o并直接编进内核。

(2)条件编译

obj -$(CONFIG_HELLO) +=xxx.o

根据.config文件的CONFIG_XXX来决定文件是否编进内核。

(3)模块编译

obj-m +=xxx.o

表示xxx作为模块编译,即执行make modules时才会被编译。

Kconfig

bool布尔类型、 tristate三态(内建、模块、移除)、string字符串、 hex十六进制、integer整型。

作用:决定make menuconfig时展示的配置。
select:反向依赖关系,该选项选中时,同时选中select后面定义的那一项。

.config

配置内核方式有3种:
(1)make menuconfig
(2)make xxx_defconfig
(3)直接修改.config

写一个简单的入口函数输出hello world的驱动并编译进内核。
步骤:
(1)在drivers目录下新建hello文件夹,里面实现hello.c、Makefile、Kconfig。
hello.c:

#include <linux/module.h>  
#include <linux/kernel.h> 
#include <linux/init.h>  
static int first_drv_init(void)  
{ 
  printk("------------------hello world !--------------------"); 
   return 0;  
} 
static void first_drv_exit(void) 
{  
   printk("------------------exit hello world!--------------------"); 
}  
module_init(first_drv_init); 
module_exit(first_drv_exit); 

Makefile:

obj-$(CONFIG_HELLO) += hello.o

Kconfig:

config HELLO
tristate “Hello Worldfor fengyuwuzu”
help
Hello forfengyuwuzu

config HELLO决定名字:CONFIG_HELLO。
Hello World for fengyuwuzu:决定了在make menuconfig时显示的名字

修改上一级的Makefile、Kconfig。

Makefile:

obj-y += hello/

Kconfig:

source “drivers/hello/Kconfig”

原文链接:https://blog.csdn.net/thisway_diy/article/details/76981113

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值