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)/$@
    #         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
    #
    # 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) doesn't exist.
    #
    # A simple variant is to prefix commands with $(Q) - that's useful
    # for commands that shall be hidden in non-verbose mode.
    #
    #    $(Q)ln $@ :<
    #
    # 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 $@
        [...省略]
    2. 添加调试信息:
        [...省略]
        %config: scripts_basic outputmakefile FORCE
            $(info zengjf $@ $(Q))
            $(Q)$(MAKE) $(build)=scripts/kconfig $@
        [...省略]
    3. $(info zengjf $@ $(Q))输出信息:
        zengjf mx6dlsabresd_defconfig @
    4. 可知:$(Q) = @
    5. 从上面Makefile Help中可以,Makefile中的Q变量和KBUILD_VERBOSE有关,KBUILD_VERBOSE和make执行的时候V变量有关;
    6. 所以执行make相关的命令,加入V=1就可以回显make命令执行的流程了。

 

posted on 2018-06-29 11:40  zengjf  阅读(2429)  评论(0编辑  收藏  举报

导航