Android Makefile中inherit-product函数和include的区别

在 Android Makefile中inherit-product函数和include都是执行某个文件。

include 使用:

include device/mediatek/mt2712/device.mk

inherit-product 函数

使用方法:

 $(call inherit-product, device/mediatek/mt2712/device.mk)

或者

$(call inherit-product-if-exists, device/mediatek/mt2712/device.mk)

inherit-product-if-exists先判断文件是否存在。

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
 
 
#
# Do inherit-product only if $(1) exists
#
define inherit-product-if-exists
  $(if $(wildcard $(1)),$(call inherit-product,$(1)),)
endef

从注释中可以看到,inherit-product 函数除了会执行通过其参数传入的 Makefile 文件之外,还会额外做 3 件事:

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

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

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xiaowang_lj

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值