gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 15:40:09 25 4
gpt4 key购买 nike

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

mymodule/Makefile
../foo/Makefile
../foo/component1/Makefile
../foo/component2/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-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 它至少会进入文件夹,但似乎不会尝试编译,我想要这将成为单个内核模块的一部分。

最佳答案

这看起来并不太难。

我的模块/生成文件:

...
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

这足以满足您的目的吗?

关于c - 如何正确链接 KBuild Makefile 以在内核模块中构建子文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40006803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com