25

我明白了的意思

obj-$(CONFIG_USB)       += usb.o

如果 CONFIG_USB 为 y,则将编译 usb.o。那么现在如何理解这个

obj-y               += something/
4

3 回答 3

49

内核 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) 从正常的配置过程中提取正确的答案。

于 2012-06-08T13:46:14.247 回答
11

obj-y += 某物/

这意味着 kbuild 应该进入目录“something”。一旦它移动到这个目录,它就会查看“某物”中的 Makefile 来决定应该构建哪些对象。

这类似于说-转到目录“某物”并执行“make”

于 2013-07-29T22:08:19.450 回答
7

您的问题似乎是为什么将整个目录添加为目标,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'.
于 2013-07-23T10:31:29.840 回答