make命令回显Makefile执行脚本命令

Posted zengjfgit

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了make命令回显Makefile执行脚本命令相关的知识,希望对你有一定的参考价值。

/**********************************************************************
 *                make命令回显Makefile执行脚本命令
 * 说明:
 *     当我们拿到别人的源代码的时候,如果是用Makefile组织的,同时希望能够
 * 跟踪一下源代码的编译架构,从而建立对源代码的组织架构的全局理解,可以通
 * 过传入V=1打开执行回显功能,当然要源代码的Makefile支持这个功能。
 *
 *                                2018-6-29 深圳 宝安西乡 曾剑锋
 *********************************************************************/

一、参考文档:
    https://github.com/ZengjfOS/Buildroot/blob/fsl_uboot_L4.1.15_from_TP/Makefile

二、Makefile Help
    # 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)/[email protected]
    #         cmd_cc_o_c       = $(CC) $(c_flags) -c -o [email protected] $<
    #
    # If $(quiet) is empty, the whole command will be printed.
    # If it is set to "quiet_", only the short version will be printed.
    # If it is set to "silent_", nothing will be printed at all, since
    # the variable $(silent_cmd_cc_o_c) doesnt exist.
    #
    # A simple variant is to prefix commands with $(Q) - thats useful
    # for commands that shall be hidden in non-verbose mode.
    #
    #    $(Q)ln [email protected] :<
    #
    # If KBUILD_VERBOSE equals 0 then the above command will be hidden.
    # If KBUILD_VERBOSE equals 1 then the above command is displayed.
    #
    # To put more focus on warnings, be less verbose as default
    # Use make V=1 to see the full commands
    
    ifeq ("$(origin V)", "command line")
      KBUILD_VERBOSE = $(V)
    endif
    ifndef KBUILD_VERBOSE
      KBUILD_VERBOSE = 0
    endif
    
    ifeq ($(KBUILD_VERBOSE),1)
      quiet =
      Q =
    else
      quiet=quiet_
      Q = @
    endif

三、命令解析
    1. %config:
        [...省略]
        %config: scripts_basic outputmakefile FORCE
            $(Q)$(MAKE) $(build)=scripts/kconfig [email protected]
        [...省略]
    2. 添加调试信息:
        [...省略]
        %config: scripts_basic outputmakefile FORCE
            $(info zengjf [email protected] $(Q))
            $(Q)$(MAKE) $(build)=scripts/kconfig [email protected]
        [...省略]
    3. $(info zengjf [email protected] $(Q))输出信息:
        zengjf mx6dlsabresd_defconfig @
    4. 可知:$(Q) = @
    5. 从上面Makefile Help中可以,Makefile中的Q变量和KBUILD_VERBOSE有关,KBUILD_VERBOSE和make执行的时候V变量有关;
    6. 所以执行make相关的命令,加入V=1就可以回显make命令执行的流程了。

 

以上是关于make命令回显Makefile执行脚本命令的主要内容,如果未能解决你的问题,请参考以下文章

Shell脚本——make命令和Makefile文件

Makefile里的echo使用!

Makefile入门: 用最美味的例子

Make和Makefile快速入门

控制make命令的输出更简洁,不要回显每个命令

Linux中make