加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 07:17:42 所属栏目:百科 来源:网络整理
导读:我有一个内核模块(通常使用CONFIG_MYMODULE = m编译),其设置如下: mymodule/Makefile../foo/Makefile../foo/component1/Makefile../foo/component2/Makefile 目前正在使用的是: MyModule的/ Makefile文件: mymodule-y += mod1file.o mod2file.o mod3file.
我有一个内核模块(通常使用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

这足以满足您的目的吗?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读