嘻嘻嘻嘻嘻嘻嘻

这篇文章描述了如何在Linux内核源码树外构建模块。通过运行make命令,内核的Makefile会包含指定的Makefile来编译模块。它定义了对象模块,设置了CROSS_COMPILE和CC编译器,并假设源代码树是在运行内核相同的目录下。KERNELDIR变量用于指向内核头文件的位置,执行makemodules进行编译,makeclean用于清理目标文件。
摘要由CSDN通过智能技术生成

# To build modules outside of the kernel tree, we run "make"
# in the kernel source tree; the Makefile these then includes this
# Makefile once again.
# This conditional selects whether we are being included from the
# kernel Makefile or not.

# called from kernel build system: just declare what our modules are
obj-m := hello.o

CROSS_COMPILE = 

CC            = gcc

    # Assume the source tree is where the running kernel was built
    # You should set KERNELDIR in the environment if it's elsewhere
    KERNELDIR ?= /usr/src/linux-headers-$(shell uname -r)
    # The current directory is passed to sub-makes as argument
    PWD := $(shell pwd)

all:     modules


modules:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules


clean:
    rm -rf *.o *~ core .depend *.symvers .*.cmd *.ko *.mod.c .tmp_versions $(TARGET)
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值