【问题标题】:In Kernel makefile $(call cmd, tags) what is the cmd here refers to?在 Kernel makefile $(call cmd, tags) 中,这里的 cmd 指的是什么?
【发布时间】:2014-05-21 05:23:27
【问题描述】:

在内核 Makefile 中,我找到了如下代码:

ctags CTAGS CSCOPE: $(HEADERS) $(SOURCES) 

$(ETAGS) $(ETAGSFALGS) $(HEADERS) $(SOURCES)

$(call cmd, ctags)

另外,我在哪里可以找到宏或函数?

【问题讨论】:

    标签: makefile linux-kernel kernel kbuild


    【解决方案1】:

    在内核 v4.1 上使用 MadScientist 的方法:

    make -p | grep -B1 -E '^cmd '
    

    我们发现:

    # makefile (from `scripts/Kbuild.include', line 211)
    cmd = @$(echo-cmd) $(cmd_$(1))
    

    scripts/Kbuild.include 包含在顶级 Makefile 中。它还包含:

    echo-cmd = $(if $($(quiet)cmd_$(1)),\
        echo '  $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
    
    • quiet:设置在顶层makefile,取决于V的值。

      将是:

      • quiet_ 打印 CC file.c
      • 为空以在V= 上打印命令
      • silent_ 不在make -s 上打印任何内容
    • escsq 定义为:

      squote  := '
      escsq = $(subst $(squote),'\$(squote)',$1)
      

      它转义单引号,以便echo '$(call escsq,Letter 'a'.' 将在sh 中正确打印。

    • echo-why:进一步向下定义为Kbuild.include

      它用于make V=2,并说明为什么要重新制作目标。

    make tags的设置在Makefile中完成:

    quiet_cmd_tags = GEN     $@
          cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@
    
    tags TAGS cscope gtags: FORCE
        $(call cmd,tags)
    

    其中显示了在 kbuild 上调用命令的典型使用模式:

    quiet_cmd_XXX = NAME     $@
          cmd_XXX = actual-command $@
    
    target: prerequisites
        $(call cmd,tags)
    

    Makefile 上的评论解释了如何完成所有这些以使 make 输出更漂亮:

    # Beautify output
    # ---------------------------------------------------------------------------
    #
    # Normally, we echo the whole command before executing it. By making
    # that echo $($(quiet)$(cmd)), we now have the possibility to set
    # $(quiet) to choose other forms of output instead, e.g.
    #
    #         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
    #         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
    

    【讨论】:

      【解决方案2】:

      如果您运行make -p,它将打印所有变量、规则等的整个数据库以及它们最后定义的行号。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-02
        • 2018-12-17
        • 2014-02-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-10
        • 2021-03-15
        相关资源
        最近更新 更多