Module 包括Linux内核

Module 包括Linux内核,module,linux-kernel,makefile,Module,Linux Kernel,Makefile,我为构建内核模块编写了以下内容: KDIR=/lib/modules/$(shell uname -r)/build obj-m=hello.o PWD= $(shell pwd) default: make -C $(KDIR) SUBDIRS=$(PWD) modules 很好。我正在尝试使用include指令重写此make文件: KDIR=/lib/modules/$(shell uname -r)/build obj-m=hello.o PWD= $(shell pwd) SU

我为构建内核模块编写了以下内容:

KDIR=/lib/modules/$(shell uname -r)/build
obj-m=hello.o
PWD= $(shell pwd)
default:
    make -C $(KDIR) SUBDIRS=$(PWD) modules
很好。我正在尝试使用
include
指令重写此make文件:

KDIR=/lib/modules/$(shell uname -r)/build
obj-m=hello.o
PWD= $(shell pwd)
SUBDIRS=$(PWD)
include $(KDIR)/Makefile
但会导致以下错误:

/lib/modules/3.5.0-17-generic/build/Makefile:323: /home/toker/bundocode/gettingstart/kernel/superhello/scripts/Kbuild.include: No such file or directory
/lib/modules/3.5.0-17-generic/build/Makefile:573: /home/toker/bundocode/gettingstart/kernel/superhello/arch/x86/Makefile: No such file or directory
/bin/bash: /home/toker/bundocode/gettingstart/kernel/superhello/scripts/gcc-goto.sh: No such file or directory

为什么?

内核makefiles旨在从父makefile中包含,该父makefile包含构建和链接所需的所有信息,包括您希望从include中获得的信息。这允许主kbuild进程根据用户通过menuconfig配置的内容来决定它构建的编译器、体系结构等。从树外生成文件中获取这些定义将破坏这一点(并降低代码的可移植性)

您应该阅读以下信息:


John

因为这不是构建模块的方式。内核源代码makefile是一个复杂的beast,如果您不按自己的想法使用它