makefile中的注释

来源:互联网 发布:吴昕淘宝店omg关了吗 编辑:程序博客网 时间:2024/05/18 00:42
$(Q)@:

Q=
或者
Q=@

那么这句就是 @: 或者@@: 其实都是一样的 @:

解释一下:
makefile里面命令前加@表示不显示源命令。试试就可以了。加多个和加一个的效果是一样的。

:是bash的内建命令,效果就是就是什么都不做, 并且总是返回状态0. (命令可以带参数)

所以总体来说 $(Q)@:  就是什么都不做。如果后面有参数。等同于注释掉。


通过以上的说明,我们就可以很好地解析U-boot中“ : Generate the dependancies ; 和 : Extract the config macros ;”这2句的意思

#
# Auto-generate the autoconf.mk file (which is included by all makefiles)
#
# This target actually generates 2 files; autoconf.mk and autoconf.mk.dep.
# the dep file is only include in this top level makefile to determine when
# to regenerate the autoconf.mk file.
$(obj)include/autoconf.mk.dep: $(obj)include/config.h include/common.h
    @$(XECHO) Generating $@ ; \
    set -e ; \
    : Generate the dependancies ; \
    $(CC) -x c -DDO_DEPS_ONLY -M $(HOSTCFLAGS) $(CPPFLAGS) \
        -MQ $(obj)include/autoconf.mk include/common.h > $@

$(obj)include/autoconf.mk: $(obj)include/config.h
    @$(XECHO) Generating $@ ; \
    set -e ; \
    : Extract the config macros ; \
    $(CPP) $(CFLAGS) -DDO_DEPS_ONLY -dM include/common.h | \
        sed -n -f tools/scripts/define2mk.sed > $@.tmp && \
    mv $@.tmp $@

上面:  @$(XECHO)中的@表示不回显,它的作用域是一整条命令(用‘\’符号连接的都算是1条指令),所有它会作用的$(CC)和$(CPP),于是可以转换为:

@: Generate the dependancies;

@: Extract the config macros ;

就是不回显(回显是指: makefile中不指定@的命令,将会在终端中输出)

结合起来就是不回显输出: Generate the dependancies; 和: Extract the config macros ;这2条指令,而:指令就是上面也不做。

这样在终端中我们看不多任何的输出,在makefile中也不回到任何作用。

总结:这通常在makefile中起注释的作用。

           但是为上面这么做呢?为什么不用#号来实现注释呢?

           如果#在行首的话当然没有问题,makefile不会做任何动作。

           但是如果#号以tab开头,makefile虽然不会执行,但是会回显到终端上。

           用@:在以tab开头的情况和#在行首的情况是一样的。


0 0
原创粉丝点击