xxx(机型名)为例

在build/core/main.mk中, 会包含build/core/config.mk,在config.mk中,会包含build/core/envsetup.mk,在envsetup.mk中有:


# Read the product specs so we can get TARGET_DEVICE and other          


           # variables that we need in order to locate the output files.          


           include $(BUILD_SYSTEM)           /product_config           .mk          


           .......          


           # Boards may be defined under $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)          


           # or under vendor/*/$(TARGET_DEVICE).  Search in both places, but          


           # make sure only one exists.          


           # Real boards should always be associated with an OEM vendor.          


           board_config_mk := \          


                      $(strip $(wildcard \          


                      $(SRC_TARGET_DIR)           /board/           $(TARGET_DEVICE)           /BoardConfig           .mk \          


                      $(shell            test            -d device &&            find            device -maxdepth 4 -path            '*/$(TARGET_DEVICE)/BoardConfig.mk'           ) \          


                      $(shell            test            -d vendor &&            find            vendor -maxdepth 4 -path            '*/$(TARGET_DEVICE)/BoardConfig.mk'           ) \          


                      ))          


           ifeq ($(board_config_mk),)          


                      $(error No config            file            found            for            TARGET_DEVICE $(TARGET_DEVICE))          


           endif          


           ifneq ($(words $(board_config_mk)),1)          


                      $(error Multiple board config files            for            TARGET_DEVICE $(TARGET_DEVICE): $(board_config_mk))          


           endif          


           include $(board_config_mk)          


           ifeq ($(TARGET_ARCH),)          


                      $(error TARGET_ARCH not defined by board config: $(board_config_mk))          


           endif          


           TARGET_DEVICE_DIR := $(patsubst %/,%,$(           dir            $(board_config_mk)))          


           board_config_mk :=


这里首先在main.mk最前面有:

TOPDIR :=

BUILD_SYSTEM := $(TOPDIR)build/core

因此在envsetup.mk中会include build/core/product_config.mk

在product_config.mk中有:


# ---------------------------------------------------------------          


           # Include the product definitions.          


           # We need to do this to translate TARGET_PRODUCT into its          


           # underlying TARGET_DEVICE before we start defining any rules.          


           #          


           include $(BUILD_SYSTEM)           /node_fns           .mk          


           include $(BUILD_SYSTEM)           /product           .mk          


           include $(BUILD_SYSTEM)           /device           .mk          


           ifneq ($(strip $(TARGET_BUILD_APPS)),)          


           # An unbundled app build needs only the core product makefiles.          


           all_product_configs := $(call get-product-makefiles,\          


                      $(SRC_TARGET_DIR)           /product/AndroidProducts           .mk)          


           else          


           # Read in all of the product definitions specified by the AndroidProducts.mk          


           # files in the tree.          


           all_product_configs := $(get-all-product-makefiles)          


           endif


先调用 build/core/product.mk中定义的函数get-all-product-makefiles ,get-all-product-makefiles函数会返回所有的.mk文件中的宏PRODUCT_MAKEFILES ,

在product.mk开始有:


#          


           # Returns the list of all AndroidProducts.mk files.          


           # $(call ) isn't necessary.          


           #          


           define _find-android-products-files          


           $(shell            test            -d device &&            find            device -maxdepth 6 -name AndroidProducts.mk) \          


                      $(shell            test            -d vendor &&            find            vendor -maxdepth 6 -name AndroidProducts.mk) \          


                      $(SRC_TARGET_DIR)           /product/AndroidProducts           .mk          


           endef          


           #          


           # Returns the sorted concatenation of PRODUCT_MAKEFILES          


           # variables set in the given AndroidProducts.mk files.          


           # $(1): the list of AndroidProducts.mk files.          


           #          


           define get-product-makefiles          


           $(           sort            \          


                      $(foreach f,$(1), \          


                      $(           eval            PRODUCT_MAKEFILES :=) \          


                      $(           eval            LOCAL_DIR := $(patsubst %/,%,$(           dir            $(f)))) \          


                      $(           eval            include $(f)) \          


                      $(PRODUCT_MAKEFILES) \          


                      ) \          


                      $(           eval            PRODUCT_MAKEFILES :=) \          


                      $(           eval            LOCAL_DIR :=) \          


                      )          


           endef          


           #          


           # Returns the sorted concatenation of all PRODUCT_MAKEFILES          


           # variables set in all AndroidProducts.mk files.          


           # $(call ) isn't necessary.          


           #          


           define get-all-product-makefiles          


           $(call get-product-makefiles,$(_find-android-products-files))          


           endef


因此这里会找到device下的所有AndroidProducts.mk,不同子目录下的AndroidProducts.mk 中定义了不同的 PRODUCT_NAME, PRODUCT_DEVICE 等信息

# Import all product makefiles.

$(call import-products, $(all_product_makefiles))

调用import-products,读取找到的所有的AndrodProducts.mk文件中定义的产品信息,import-products函数去验证这些产品配置文件是否都包含有必须的配置信息

然后有:


# Convert a short name like "sooner" into the path to the product          


           # file defining that product.          


           #          


           INTERNAL_PRODUCT := $(call resolve-short-product-name, $(TARGET_PRODUCT))          


           ifneq ($(current_product_makefile),$(INTERNAL_PRODUCT))          


           $(error PRODUCT_NAME inconsistent            in            $(current_product_makefile) and $(INTERNAL_PRODUCT))          


           endif          


           current_product_makefile :=          


           all_product_makefiles :=          


           all_product_configs :=


xxx(机型名)

调用函数resolve-short-product-name,它将返回TARGET_PRODUCT代表的配置文件路径,并赋给INTERNAL_PRODUCT,因此这里就是device/***/xxx/xxx.mk

# Find the device that this product maps to.

TARGET_DEVICE := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_DEVICE)

之后TARGET_DEVICE取值xxx

回到envsetup.mk中,


board_config_mk := \          


                      $(strip $(wildcard \          


                      $(SRC_TARGET_DIR)           /board/           $(TARGET_DEVICE)           /BoardConfig           .mk \          


                      $(shell            test            -d device &&            find            device -maxdepth 4 -path            '*/$(TARGET_DEVICE)/BoardConfig.mk'           ) \          


                      $(shell            test            -d vendor &&            find            vendor -maxdepth 4 -path            '*/$(TARGET_DEVICE)/BoardConfig.mk'           ) \          


                      ))          


           ifeq ($(board_config_mk),)          


                      $(error No config            file            found            for            TARGET_DEVICE $(TARGET_DEVICE))          


           endif          


           ifneq ($(words $(board_config_mk)),1)          


                      $(error Multiple board config files            for            TARGET_DEVICE $(TARGET_DEVICE): $(board_config_mk))          


           endif          


           include $(board_config_mk)          


           ifeq ($(TARGET_ARCH),)          


                      $(error TARGET_ARCH not defined by board config: $(board_config_mk))          


           endif          


           TARGET_DEVICE_DIR := $(patsubst %/,%,$(           dir            $(board_config_mk)))          


           board_config_mk :=


这里先在device下按照xxx/BoardConfig.mk这个规则搜索,会找到device/***/xxx/下的BoardConfig.mk文件,将路径赋值给TARGET_DEVICE_DIR

***/xxx