Compiling out-of-tree kernel module against any kernel source tree on the filesystem

泪湿孤枕 提交于 2019-11-29 02:33:41
vinay hunachyal

goal is to have it compile against any source tree

ya you can do it providing a compiled source-code path

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

with this

make -C <path-to-compiled-src-code> M=$(PWD) modules

make -C /home/vinay/linux-3.9 M=$(PWD) modules

try below 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

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

while building kernel modules why do we need /lib/modules?

A simple program on linux device driver

How to make a built-in device driver in linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!