在单独的对象目录中构建树外Linux内核模块 [英] Building an out-of-tree Linux kernel module in a separate object directory

查看:152
本文介绍了在单独的对象目录中构建树外Linux内核模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面对的是Linux内核构建系统(Kbuild,内核≥2.6.28),它具有目录结构和大型项目的构建系统.我们的项目包含一个树外Linux内核模块,我们的目录结构如下所示(显然是简化的):

I'm confronting the Linux kernel build system (Kbuild, kernel ≥2.6.28) with the directory structure and build system for a larger project. Our project contains an out-of-tree Linux kernel module, and our directory structure looks like this (simplified, obviously):

checkout/src/common/*.c           source files (common to Linux and other platforms)
checkout/src/linux-driver/*.c     source files (for the Linux kernel driver)
checkout/build/linux/Kbuild       Kbuild
tmp/linux-2.6.xx/                 where the Linux kernel is unpacked and configured
output/linux-arm-debug/           where object files must end up

构建过程不得修改checkout下的任何内容,并且构建模块不得修改tmp/linux-2.6.xx下的任何内容.所有输出文件都必须以output/linux-arm-debug结尾(或在构建时选择了任何体系结构和调试版本).

The build process must not modify anything under checkout, and building the module must not modify anything under tmp/linux-2.6.xx. All output files must end up under output/linux-arm-debug (or whatever architecture and debug variant was selected at build time).

我已阅读 kbuild/modules.txt ,并开始写我的Kbuild文件:

MOD_OUTPUT_DIR = ../../../output/linux-$(ARCH)-$(DEBUG)
obj-m += $(MOD_OUTPUT_DIR)/foo_mod.o
$(MOD_OUTPUT_DIR)/our_module-objs := $(MOD_OUTPUT_DIR)/foo_common.o $(MOD_OUTPUT_DIR)/foo_linux.o

这用于将目标文件存储在与Kbuild所在的目录不同的目录中.现在如何指定需要从…/checkout/src/common/foo_common.c编译foo_common.o和从…/checkout/src/linux-driver/foo_linux.c编译foo_linux.o?

This handles storing the object files in a different directory from where Kbuild lives. Now how can I specify that foo_common.o needs to be compiled from …/checkout/src/common/foo_common.c and foo_linux.o from …/checkout/src/linux-driver/foo_linux.c?

推荐答案

这里是一个Makefile,它针对内核树模块之外的源树进行构建(改编自@Mark的注释)...

Here is a Makefile which does out of source-tree builds for out of kernel-tree modules (adapted from @Mark's comment)...

KDIR ?= /lib/modules/$(shell uname -r)/build
BUILD_DIR ?= $(PWD)/build
BUILD_DIR_MAKEFILE ?= $(PWD)/build/Makefile

default: $(BUILD_DIR_MAKEFILE)
    make -C $(KDIR) M=$(BUILD_DIR) src=$(PWD) modules

$(BUILD_DIR):
    mkdir -p "$@"

$(BUILD_DIR_MAKEFILE): $(BUILD_DIR)
    touch "$@"

clean:
    make -C $(KDIR) M=$(BUILD_DIR) src=$(PWD) clean

注意:您仍然需要一个Kbuild文件...

Note: You still need a Kbuild file...

obj-m += my_driver.o

这篇关于在单独的对象目录中构建树外Linux内核模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆