【问题标题】:Whats meaning of obj-y += something/ in linux kernel Makefile?linux内核Makefile中obj-y + = something /的含义是什么?
【发布时间】:2012-06-12 13:55:36
【问题描述】:

我明白了

的意思
obj-$(CONFIG_USB)       += usb.o

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

obj-y               += something/

【问题讨论】:

    标签: c linux makefile linux-kernel


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      obj-y += 某物/

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

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

      【讨论】:

        【解决方案3】:

        您的问题似乎是为什么要添加整个目录作为目标,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'.
        

        【讨论】:

        • 顺便说一句,在 obj-y 变量中添加所有 .o 文件后,它实际上在哪里编译它们?我的意思是内核树中许多 Makefile 之一的位置?
        猜你喜欢
        • 2015-08-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-09
        • 2013-08-31
        相关资源
        最近更新 更多