我正试图对文件系统上的任何源树编译模块,但我遇到了Makefile的麻烦。这是我针对内核指定的原始Makefile:
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可以正确编译,但目标是让它可以针对任何源代码树进行编译。我已经试过了:
obj-m += new-mod.o
我认为"all:"是假定的,但我得到错误:
make: *** No targets. Stop.
我还添加了:
all:
到Makefile,除了错误信息:
make: Nothing to be done for `all'
我已经尝试了很多文档,但没有运气。我将非常感谢您的帮助。
goal is to have it compile against any source tree
你可以提供一个compiled source-code path
替换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
在上面你可以改变KERNEL_SOURCE := /usr/src/linux
->为。-->你的sr-code KERNEL_SOURCE := <path to compiled-src-code>
更多信息请参见下面的链接
当构建内核模块时,为什么我们需要/lib/modules?一个简单的linux设备驱动程序
如何在linux中制作内置设备驱动程序
根据您的自定义内核源代码(而不是已安装的内核源代码)构建,您可以使用以下步骤:
1。从kernel.org (tar)下载内核
2。提取
3。使x86_64_defconfig
4。让准备
5。使modules_prepare
现在您必须更改Makefile以指向已下载并提取的内核源代码。Vinay Answer在例子中提到了类似的东西。