针对文件系统上的任何内核源代码树编译树外内核模块 [英] Compiling out-of-tree kernel module against any kernel source tree on the filesystem

查看:19
本文介绍了针对文件系统上的任何内核源代码树编译树外内核模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试针对文件系统上的任何源代码树编译模块,但是我在 Makefile 上遇到了问题.这是我针对指定内核的原始 Makefile:

I am trying to compile a module against any source tree on the file system but I am having trouble with the Makefile. This was the original Makefile I had against the kernel specified:

obj-m += new-mod.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

这个 Makefile 可以正确编译,但目标是让它针对任何源代码树进行编译.我试过:

This Makefile would compile correctly, but goal is to have it compile against any source tree. I have tried just:

obj-m += new-mod.o

我认为所有:"是假设的,但我收到错误:

I thought that "all:" is assumed but I get error:

make: *** No targets.  Stop.

我还添加了:

all: 

除了错误信息外没有区别的Makefile:

to the Makefile with no difference except for error message:

make: Nothing to be done for `all'

我尝试了很多文档,但没有成功.如有任何帮助,我将不胜感激.

I have tried a lot of documentation but no luck. I would greatly appreciate any help.

推荐答案

目标是让它针对任何源代码树进行编译

你可以提供一个编译的源代码路径

只需替换make -C/lib/modules/$(shell uname -r)/build M=$PWD modules

有了这个

make -C M=$PWD 模块

make -C/home/vinay/linux-3.9 M=$PWD 模块

试试下面的makefile

try below makefile

Makefile –

Makefile –

# if KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq (${KERNELRELEASE},)
obj-m := new-mod.o
# Otherwise we were called directly from the command line.
# Invoke the kernel build system.
  else
    KERNEL_SOURCE := /usr/src/linux
    PWD := $(shell pwd)
default:
      ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules

clean:
      ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
endif

在上面你可以改变 KERNEL_SOURCE :=/usr/src/linux-->to.--> 你的 sr-code KERNEL_SOURCE :=

In above you can change KERNEL_SOURCE := /usr/src/linux-->to.--> your sr-code KERNEL_SOURCE := <path to compiled-src-code>

欲了解更多信息,请在下面找到喜欢

for further info find below liks

在构建内核模块时为什么我们需要/lib/modules 吗?

一个简单的linux设备驱动程序

如何构建-in linux中的设备驱动

这篇关于针对文件系统上的任何内核源代码树编译树外内核模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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