【发布时间】:2012-06-12 13:55:36
【问题描述】:
我明白了
的意思obj-$(CONFIG_USB) += usb.o
如果 CONFIG_USB 为 y,则将编译 usb.o。那么现在如何理解这个
obj-y += something/
【问题讨论】:
标签: c linux makefile linux-kernel
我明白了
的意思obj-$(CONFIG_USB) += usb.o
如果 CONFIG_USB 为 y,则将编译 usb.o。那么现在如何理解这个
obj-y += something/
【问题讨论】:
标签: c linux makefile linux-kernel
内核 Makefile 是 kbuild 系统的一部分,记录在网络上的各个地方,例如 http://lwn.net/Articles/21835/。相关摘录在这里:
--- 3.1 Goal definitions目标定义是 kbuild Makefile 的主要部分(核心)。 这些行定义了要构建的文件,任何特殊的编译 选项,以及递归输入的任何子目录。
最简单的kbuild makefile包含一行:
示例:obj-y += foo.o
这告诉 kbuild 该目录中有一个名为 foo.o. foo.o 将从 foo.c 或 foo.S 构建。
如果将 foo.o 构建为模块,则使用变量 obj-m。 因此经常使用以下模式:
示例:obj-$(CONFIG_FOO) += foo.o
$(CONFIG_FOO) 计算结果为 y(对于内置)或 m(对于模块)。 如果 CONFIG_FOO 既不是 y 也不是 m,那么文件将不会被编译 也没有链接。
所以m 表示模块,y 表示内置(在内核配置过程中代表是),而 $(CONFIG_FOO) 从正常配置过程中提取正确答案。
【讨论】:
obj-y += 某物/
这意味着 kbuild 应该进入目录“something”。一旦它移动到这个目录,它就会查看“某物”中的 Makefile 来决定应该构建哪些对象。
这类似于说-转到目录“某物”并执行“make”
【讨论】:
您的问题似乎是为什么要添加整个目录作为目标,KConfig 文档的相关部分是:
--- 3.6 Descending down in directories
A Makefile is only responsible for building objects in its own
directory. Files in subdirectories should be taken care of by
Makefiles in these subdirs. The build system will automatically
invoke make recursively in subdirectories, provided you let it know of
them.
To do so obj-y and obj-m are used.
ext2 lives in a separate directory, and the Makefile present in fs/
tells kbuild to descend down using the following assignment.
Example:
#fs/Makefile
obj-$(CONfIG_EXT2_FS) += ext2/
If CONFIG_EXT2_FS is set to either 'y' (built-in) or 'm' (modular)
the corresponding obj- variable will be set, and kbuild will descend
down in the ext2 directory.
Kbuild only uses this information to decide that it needs to visit
the directory, it is the Makefile in the subdirectory that
specifies what is modules and what is built-in.
It is good practice to use a CONFIG_ variable when assigning directory
names. This allows kbuild to totally skip the directory if the
corresponding CONFIG_ option is neither 'y' nor 'm'.
【讨论】: