微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何正确链接KBuild Makefiles以在内核模块中构建子文件夹

我有一个内核模块(通常使用CONfig_MYMODULE = m编译),其设置如下:

mymodule/Makefile
../foo/Makefile
../foo/component1/Makefile
../foo/component2/Makefile

目前正在使用的是:

MyModule的/ 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: cannot find foo: File format not recognized”

MyModule的/ 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它至少进入文件夹,但似乎没有尝试编译,我希望这是一个全部单个内核模块的一部分.

解决方法

这似乎并不太难.

MyModule的/ Makefile文件

...
include ../foo/Makefile
...
# whatever rules use the folder-specific flags:
foo:
    gcc blah blah $(FOLDERFLAGS) blah

../foo/component1/Makefile:

FOLDER_FILES := foo1file.o foo2file.o foo3file.o #etc
$(FOLDER_FILES): FOLDER_FLAGS=folder_1_flag
FOO_FILES += FOLDER_FILES

../foo/component2/Makefile:

FOLDER_FILES := foo20file.o foo21file.o foo22file.o #etc
$(FOLDER_FILES): FOLDER_FLAGS=folder_2_flag
FOO_FILES += FOLDER_FILES

这足以满足您的目的吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐