我正在与Linux内核构建系统(Kbuild,内核≥2.6.28)以及一个更大项目的目录结构和构建系统进行对抗。我们的项目包含一个非内置的Linux内核模块,我们的目录结构看起来像这样(显然是简化过的):
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
目录下(或者在构建时选择的其他架构和调试版本)。
我已经阅读了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
不同的目录中。现在我如何指定foo_common.o
需要从…/checkout/src/common/foo_common.c
编译,以及foo_linux.o
需要从…/checkout/src/linux-driver/foo_linux.c
编译?
obj-m += my_driver.o
。 - GShaikifneq ($(KERNELRELEASE),)
测试来简化Makefile。参见:http://www.makelinux.net/ldd3/chp-2-sect-4.shtml - Sandeep DattaMakefile
在src
目录中,而这对我来说并不是这种情况(它是由 autoconf 构建的,因此Makefile.in
在源代码中,而Makefile
在 build/M 目录中,Kbuild 文件也是如此)。 - Miralmodules.txt
中记录了src=
,我会感觉更好 :-( - Ciro Santilli OurBigBook.com