16

I'm looking through the Android Open Source Project makefiles, and I'm seeing what appears to be two different ways of including another makefile. For example, master/build/target/product/aosp_arm64.mk has these lines:

PRODUCT_COPY_FILES += frameworks/native/data/etc/android.hardware.ethernet.xml:system/etc/permissions/android.hardware.ethernet.xml

$(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_base_telephony.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/board/generic_arm64/device.mk)

include $(SRC_TARGET_DIR)/product/emulator.mk

PRODUCT_NAME := aosp_arm64
PRODUCT_DEVICE := generic_arm64
PRODUCT_BRAND := Android
PRODUCT_MODEL := AOSP on ARM arm64 Emulator

What is the difference(s) between the $(call inherit-product ...) line and the include ... line?

  • `$(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)` is not a way of inclduing another makefile. It's a [call to the user-defined make-function](https://www.gnu.org/software/make/manual/html_node/Call-Function.html) `inherit-product` with the argument `$(SRC_TARGET_DIR)/product/core_64_bit.mk`. To know that that function does you'll have to search for its definition. – Mike Kinghan Mar 31 '16 at 09:46

2 Answers2

13

include just includes the file. inherit-product does that and three more things accordig to file in link below:

  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

See line 113 in this file for details core/product.mk

Olle
  • 480
  • 3
  • 10
  • Maybe just a link directly to the mentioned line: https://android.googlesource.com/platform/build/+/157a5e1/core/product.mk#113 – tellob Mar 04 '22 at 11:18
5

Let's say you have PRODUCT_VAR := a in A.mk, PRODUCT_VAR := b in B.mk.

If you include B.mk in A.mk, you will get PRODUCT_VAR := b at last.

But if you inherit-product B.mk in A.mk, you will get PRODUCT_VAR := a b.

And inherit-product makes sure that you won't include a makefile twice because it Records that we've visited this node, in ALL_PRODUCTS.

ZhouZhuo
  • 196
  • 2
  • 5