Linux Out of Tree模块构建问题 [英] Linux out of tree module build issue

查看:491
本文介绍了Linux Out of Tree模块构建问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

obj-m := $(MODNAME).o
ccflags-y := $(CCFLAGS)
src_files := $(wildcard $(foreach pat,*.c *.cpp *.s,src/$(pat) src/$(MODNAME)/$(pat)))
$(MODNAME)-objs := $(addsuffix .o, $(basename $(src_files)))

all:

    make -C $(KDIR) M=$(shell pwd) modules

clean:

    make -C $(KDIR) M=$(shell pwd) clean

我有这个make文件来构建内核模块.但是,每当我运行它时,我都会收到一条错误消息,指出没有规则可以使目标.c成为目标. .c不是源文件.如果我取消了"if [-d src]"检查,那么我会收到一条错误消息,说明从内核构建系统进行的递归make调用中不存在src.如果我指定src的完整路径,则会给出相同的输出,表明找不到它(这确实很奇怪).如果我对src_files进行硬编码,则它可以工作(如果我没有错误地复制和粘贴).有人知道发生了什么吗?

I have this make file for building kernel modules. However whenever I run it, I get an error saying that there is no rule to make target .c. .c is not a source file. If I remove the "if [ -d src ]" check then I get an error saying src doesn't exists on the recursive make call from the kernel build system. If I specify the full path to src it gives the same output saying that it can't find it (which is really weird). If I hard code src_files it works (if I didn't copy and paste wrong). Does anybody have any idea what is going on?

推荐答案

在您的makefile中,您希望当前目录是给定makefile中包含的目录.但是,从Kbuild上下文执行文件时,情况就不再正确:当前目录是包含内核源代码的目录.

In your makefile you expect current directory to be the one contained given makefile. But when your file is executed from Kbuild context, this is no longer true: current directory is directory with kernel sources.

这就是为什么src_files变量的内容出错的原因:wildcard在内核源文件中的 src/下找不到文件.您可以使用特殊的src变量来使用makefile来引用目录:

That is why content of src_files variable becomes wrong: wildcard cannot find files under src/ in kernel sources. You may use special src variable for refer to directory with your makefile:

src_files := $(wildcard $(foreach pat,*.c *.cpp *.s,$(src)/src/$(pat) $(src)/src/$(MODNAME)/$(pat)))

从另一方面讲,在*-objs变量中枚举的路径应该是 relative (这是Kbuild的要求).因此,您需要从以下绝对路径中删除前缀:

From the other side, paths enumerated in *-objs variable should be relative (this is requirement by Kbuild). So you need to strip prefix from these absolute paths:

src_files_rel := $(src_files:$(src)/%=%)

然后,您可以使用以下路径创建对象列表:

Then you may use these paths for create objects list:

$(MODNAME)-objs := $(addsuffix .o, $(basename $(src_files_rel)))

这篇关于Linux Out of Tree模块构建问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆