当前位置:网站首页>makefile模板
makefile模板
2022-07-27 10:53:00 【对我好两点】
1.模板
1.1 编译驱动模块
# -C $(KDIR) 指明跳转到内核源码目录下读取那里的Makefile
# M=$(PWD) 表明然后返回到当前目录继续读入、执行当前的Makefile
#要生成的模块名
obj-m := GobiNet.o
#生成这个模块所需要的目标文件
GobiNet-objs := GobiUSBNet.o QMIDevice.o QMI.o MPQMUX.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
OUTPUTDIR=/lib/modules/`uname -r`/kernel/drivers/net/usb/
all: clean
make -C $(KDIR) M=$(PWD) modules
#若是交叉编译,则:
#make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=/mnt/external/wangtao/8953/8953_APP_P/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-
install: all
mkdir -p $(OUTPUTDIR)
cp -f GobiNet.ko $(OUTPUTDIR)
depmod
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions Module.* modules.order
1.2 编译应用程序
CC=gcc
CFLAGS_WARN= -Wall
DEFINE=
INCLUDE= -I.
SOURCES=$(wildcard *.c)
OBJS=$(patsubst %.c,%.o,$(SOURCES))
TARGET= test
All:$(OBJS)
$(CC) -o $(TARGET)$(OBJS)
rm -f *.o
%.o:%.c
$(CC) -c $(CFLAGS_WARN)$(DEFINE)$(INCLUDE) $< -o [email protected]
clean:
rm -f $(OBJS)
2 . 开发板增加驱动
2.1 编译成模块
(1)在源代码下新建一个工作文件夹hello;
(2)新建c文件,并编辑:
#include <linux/module.h>
#include <linux/init.h>
static int __init test_init(void)
{
printk("hello\n");
return 0;
}
static void __exit test_exit(void)
{
printk("bye\n");
}
module_init(test_init);
module_exit(test_exit);
(3) 新建makefile,并编辑:
obj-m := hello.o
modules-objs := hello.o
KERNELDIR := /mnt/external/wangtao/MDM9X07_LE11_MODEM/apps_proc/oe-core/build/tmp-glibc/work/mdm9607_perf-oe-linux-gnueabi/linux-quic/git-e3802ce3ddb62ec1c6b0484515a0523b8db30e2f-r3/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) ARCH=arm CROSS_COMPILE=/mnt/external/wangtao/MDM9X07_LE11_MODEM/apps_proc/oe-core/build/tmp-glibc/sysroots/x86_64-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi- M=$(PWD) modules
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
(4) 编译make,生成ko文件;
(5) 利用FTP将ko文件传送至PC机;
(6) 利用adb将ko文件下载至开发板并修改文件权限:
adb push C:\Users\20190712125\Desktop\hello.ko /data
adb shell chmod 755 /data/hello.ko
(7) 加载模块:
insmod hello.ko
(8) 查看模块:
lsmod

注意:makefile中的all:后面为tab缩进,而不是空格缩进(会报错)。
2.2 编译进内核
(1)在源代码下新建一个工作文件夹hello;
(2)新建c文件并编辑,同上;
(3)新建Makefile并编辑:
obj-$(CONFIG_nwy_HELLO)+=hello.o
(4)新建Kconfig并编辑:
config HELLO
tristate"First Driver"
default n
help
This is the first driver.
(5)修改kernel/drivers/kconfig文件,在menu "Device Drivers"和endmenu之间添加一行:
$ source "drivers/hello/Kconfig"
这样,执行make menuconfig时,就可以配置hello模块的编译选项了。
(6)修改kernel/drivers/Makefile文件,添加一行:
obj-$(CONFIG_HELLO)+=hello/
(7)修改总的config文件
在kernel/arch/arm/configs/目录中存有指定项目的defconfig文件,如msm9607_defconfig文件,在此文件中添加一行:
CONFIG_HELLO=y
(9) 编译内核:make
(10) 利用adb单烧内核镜像。
边栏推荐
- 多家银行调整现金管理类理财产品申赎规则:申赎确认时效“T+0”变“T+1”
- Game theory acwing 894. Split Nim game
- [shader realizes shake random shaking effect _shader effect Chapter 10]
- 第10章 枚举类与注解
- 深析C语言的灵魂 -- 指针
- 局域网SDN技术硬核内幕 13 从局域网到互联网
- The article will not keep VIP charges all the time. It will be open for a period of time
- 最长上升子序列模型 AcWing 1014. 登山
- 树形DP AcWing 285. 没有上司的舞会
- ACM warm-up Exercise 1 in 2022 summer vacation (summary)
猜你喜欢
随机推荐
Kepserver configuration
求组合数 AcWing 885. 求组合数 I
C programming language (2nd Edition) -- Reading Notes -- 1.5.1
Game theory acwing 892. Step Nim game
Instructions for mock platform
Caused by:org.gradle.api.internal. plugins . PluginApplicationException: Failed to apply plugin
C programming language (2nd Edition) -- Reading Notes -- 1.5.3
Luogu p1441 weight weighing
Inclusion exclusion principle acwing 890. divisible numbers
Moveit2 - 4. robot model and robot state
Knapsack model acwing 1024. Packing problem
最长上升子序列模型 AcWing 1012. 友好城市
最长上升子序列模型 AcWing 272. 最长公共上升子序列
局域网SDN技术硬核内幕 13 从局域网到互联网
Backpack model acwing 1022. Collection of pet elves
The longest ascending subsequence model acwing 1016. The sum of the largest ascending subsequence
Smart pointer (shared_ptr, unique_ptr, weak_ptr)
Longest ascending subsequence model acwing 482. Chorus formation
Longest ascending subsequence model acwing 1014. mountaineering
[special topic] summary of RMQ question brushing with ST table









