Chinaunix首页 | 论坛 | 博客
  • 博客访问: 335628
  • 博文数量: 41
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 476
  • 用 户 组: 普通用户
  • 注册时间: 2016-09-01 19:08
个人简介

Android/Linux/音频/驱动

文章分类

全部博文(41)

文章存档

2017年(21)

2016年(20)

我的朋友

分类: Android平台

2017-02-22 10:50:05

    在 Android Makefile 中时不时会看见 inherit-product 函数的使用,类似下方这样:

        $(call  inherit-product,  vendor/dolby/ds/dolby-product.mk)

    从参数来看,我们可以猜到这条命令的作用应该是执行了 vendor/dolby/ds/dolby-product.mk 文件。如果仅仅是这样,那么 inherit-product 和 include 的区别又是什么呢?

    要回答上面的问题,需要看一下 inherit-product 函数的定义。该定义位于 build/core/product.mk 文件中,如下:

#
# $(1): product to inherit
#
# Does three things:
#  1. Inherits all of the variables from $1.
#  2. Records the inheritance in the .INHERITS_FROM variable
#  3. Records that we've visited this node, in ALL_PRODUCTS
#
define inherit-product
  $(if $(findstring ../,$(1)),\
    $(eval np := $(call normalize-paths,$(1))),\
    $(eval np := $(strip $(1))))\
  $(foreach v,$(_product_var_list), \
      $(eval $(v) := $($(v)) $(INHERIT_TAG)$(np))) \
  $(eval inherit_var := \
      PRODUCTS.$(strip $(word 1,$(_include_stack))).INHERITS_FROM) \
  $(eval $(inherit_var) := $(sort $($(inherit_var)) $(np))) \
  $(eval inherit_var:=) \
  $(eval ALL_PRODUCTS := $(sort $(ALL_PRODUCTS) $(word 1,$(_include_stack))))
endef
    从注释中可以看到,inherit-product 函数除了会执行通过其参数传入的 Makefile 文件之外,还会额外做 3 件事:

    1、继承通过参数传入的 Makefile 文件中的所有变量;

    2、在 .INHERITS_FROM 变量中记录下这些继承关系;

    3、在 ALL_PRODUCTS 变量中标识出当前操作的 Makefile 文件已经被访问过了(以免重复访问)。

    而 include 则只会执行 Makefile 文件,不会进行上方所述的 3 个操作。


【扩展阅读】

    [1] 


阅读(4216) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~