简体   繁体   English

如何理解 Linux 内核模块的“构建单独文件”?

[英]How to understand “Building Separate Files” for a Linux kernel module?

Excerpted from the Linux kernel documentation :摘自 Linux 内核文档

2.4 Building Separate Files 2.4 构建单独的文件

It is possible to build single files that are part of a module.
This works equally well for the kernel, a module, and even for
external modules.

Example (The module foo.ko, consist of bar.o and baz.o):
    make -C $KDIR M=$PWD bar.lst
    make -C $KDIR M=$PWD baz.o
    make -C $KDIR M=$PWD foo.ko
    make -C $KDIR M=$PWD /

I can't understand what these commands mean.我无法理解这些命令是什么意思。

make -C $KDIR M=$PWD bar.lst make -C $KDIR M=$PWD bar.lst

Does it mean: look for bar.c and compile it into bar.1st?这是否意味着:查找 bar.c 并将其编译为 bar.1st?

make -C $KDIR M=$PWD foo.ko make -C $KDIR M=$PWD foo.ko

Does it mean: look for all *.o and link them into foo.ko?这是否意味着:查找所有 *.o 并将它们链接到 foo.ko? Does it also look for *.1st?它也寻找*.1st吗?

make -C $KDIR M=$PWD / make -C $KDIR M=$PWD /

What does it mean?这是什么意思?

First let's understand首先让我们了解

make -C $KDIR M=$PWD [target]

here target can be anything defined as target (ie bar.o : )这里的目标可以是任何定义为目标的东西(即 bar.o : )

mostly we use dependency in make file.大多数情况下,我们在 make 文件中使用依赖项。

in given example three files在给定的示例中,三个文件

foo.c bar.c baz.c foo.c bar.c baz.c

foo.c has module_init ie entry point foo.c 有 module_init 即入口点

the statement states that we can build all files at once.该声明指出我们可以一次构建所有文件。 or single files individually and link them together finally.或单个文件,最后将它们链接在一起。

in a nutshell you can try compiling just bar.c without compiling other two files.简而言之,您可以尝试只编译 bar.c 而不编译其他两个文件。 producing only bar.o只生产 bar.o

once all .o files are generated you can create.ko file.生成所有 .o 文件后,您可以创建 .ko 文件。

refer linux/fs/ufs/Makefile参考linux/fs/ufs/Makefile

in you can compile once ufs.ko or balloc.o cylinder.o dir.o file.o ialloc.o inode.o etc. and compile ufs to create ufs.ko在你可以编译一次 ufs.ko 或 balloc.o cylinder.o dir.o file.o ialloc.o inode.o 等并编译 ufs 以创建 ufs.ko

Those commands all mean "do whatever the makefile says is necessary to build the named target".这些命令都意味着“做任何makefile所说的构建命名目标所必需的事情”。 What the set of actions involved in doing that is I can't say and will depend entirely on what the specific target is.我不能说这样做所涉及的一系列行动,这将完全取决于具体目标是什么。

If you want to know, specifically, what make will do for a given command give it the -n argument.如果你想知道,具体来说,make 会对给定的命令做什么,给它-n参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM