【发布时间】:2016-10-12 19:26:14
【问题描述】:
我有一个内核模块(通常使用 CONFIG_MYMODULE=m 编译),其设置如下:
mymodule/Makefile
../foo/Makefile
../foo/component1/Makefile
../foo/component2/Makefile
目前使用的是:
我的模块/Makefile:
mymodule-y += mod1file.o mod2file.o mod3file.o #etc
include ../foo/Makefile
mymodule-y += $(FOO_FILES)
obj-$(CONFIG_MYMODULE) += mymodule.o
../foo/Makefile:
include component1/Makefile
include component2/Makefile
在我拥有的每个组件文件夹中:
../foo/component1/Makefile
FOO_FILES += foo1file.o foo2file.o foo3file.o #etc
这显然不是解决此问题的正确方法,因为所有内容都直接包含在 mymodule/Makefile 中,因此无法设置特定于文件夹的 gcc 标志。
在将所有内容构建到单个内核模块中的同时组织它的正确方法是什么?我已经阅读了 kbuild/modules.txt 文档,但我没有看到任何直接相关的内容,而且我无法完全弄清楚如何去做或者它是否确实可能。
谢谢
我尝试了以下方法,但出现以下错误:
“ld: 找不到 foo: 文件格式无法识别”
我的模块/Makefile:
mymodule-y += mod1file.o mod2file.o mod3file.o #etc
mymodule-y += ../foo/
obj-$(CONFIG_MYMODULE) += mymodule.o
../foo/Makefile
ccflags-y := -I$(src)/component1/ -I$(src)/component2/
foo-y := foo1file.o foo2file.o foo3file.o
foo-y += component1
foo-y += component2
../foo/component1/Makefile
component1-y := component1file.o component1file.o
../foo/component2/Makefile
component2-y := component2file.o component2file.o
如果我将其更改为使用 obj-y += ../foo 而不是 mymodule-y += ../foo 它至少会进入文件夹,但似乎不会尝试编译,我想要这将成为单个内核模块的一部分。
【问题讨论】:
-
您可以将文件夹添加到对象列表中。检查源中的任何文件夹/Makefile。
-
@AndyShevchenko:我已经尝试过查看其中的一些,但它们似乎无法将多个 Makefile 链接处理到同一个内核模块中。这不是我在底部尝试用 foo-y += ../foo/ 做的事情吗?如果我做类似“obj-y += ../foo/”的事情,可以编译到 mymodule 内核中模块?我还是有点困惑。你有一个很好的例子我可以看看吗?谢谢!
-
obj-[ym]是一个独立单元的全局空间。您需要为此使用模块命名空间。 -
从我的例子中,我是 mymodule-y += ../foo/ 还是类似 foo-y += ../foo 的东西?然后我会在我的 foo/Makefile 中做什么?那是 mymodule-y += component1 还是我会使用单独的模块命名空间?
标签: c makefile build linux-kernel kbuild