Android Makefile中inherit-product函数简介,以及与include的区别

来源:互联网 发布:linux pytorch安装教程 编辑:程序博客网 时间:2024/06/10 00:54

    在 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] 《Difference between `call inherit-product` and `include` in AOSP makefiles?》



0 0
原创粉丝点击