Makefile中$@应用举例


内核顶层Makefile中,对混合目标的处理,以此作为例子来验证$@在Makefile中的使用:

  
  
  
  
ifeq ($(KBUILD_EXTMOD),)
        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
                config-targets := 1
                ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
                        mixed-targets := 1
                endif
        endif
endif


首先,如果mixed-targets取值为1,则表明是混合目标的情况,我们取出其中代码如下:

  
  
  
  
# ======================================================
# We're called with mixed targets (*config and build targets).
# Handle them one by one.

 %:: FORCE
        $(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@



从代码中可以看出,这里使用了一个双冒号的模式匹配规则。百分号代表任何目标都使用这个规则,其中$(srctree)为内核代码树所在目录,KBUILD_SRC定义为空。所以如果make命令为:make s3c2410_defconfig all,那么构建系统就会分别执行下面两条命令:

	make -C $(srctree) KBUILD_SRC= s3c2410_defconfig
	make -C $(srctree) KBUILD_SRC= all

这其实和简单的用手动的输入两条连续命令(make s3c2410_defconfig 和 make all)是一样效果的。


你可能感兴趣的:(c,filter,Build,makefile)