TARGET_DEVICE_DIR取值过程分析

整个分析过程以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 :=

根据在lunch阶段的选择,TARGET_PRODUCT变量会被赋值为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

因此TARGET_DEVICE_DIR的取值最终就是device/***/xxx

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值