product.mk revision 0c4eb4188553fc06049834111416067da53ac605
1# 2# Copyright (C) 2007 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17# 18# Functions for including AndroidProducts.mk files 19# PRODUCT_MAKEFILES is set up in AndroidProducts.mks. 20# Format of PRODUCT_MAKEFILES: 21# <product_name>:<path_to_the_product_makefile> 22# If the <product_name> is the same as the base file name (without dir 23# and the .mk suffix) of the product makefile, "<product_name>:" can be 24# omitted. 25 26# 27# Returns the list of all AndroidProducts.mk files. 28# $(call ) isn't necessary. 29# 30define _find-android-products-files 31$(shell test -d device && find device -maxdepth 6 -name AndroidProducts.mk) \ 32 $(shell test -d vendor && find vendor -maxdepth 6 -name AndroidProducts.mk) \ 33 $(SRC_TARGET_DIR)/product/AndroidProducts.mk 34endef 35 36# 37# Returns the sorted concatenation of PRODUCT_MAKEFILES 38# variables set in the given AndroidProducts.mk files. 39# $(1): the list of AndroidProducts.mk files. 40# 41define get-product-makefiles 42$(sort \ 43 $(foreach f,$(1), \ 44 $(eval PRODUCT_MAKEFILES :=) \ 45 $(eval LOCAL_DIR := $(patsubst %/,%,$(dir $(f)))) \ 46 $(eval include $(f)) \ 47 $(PRODUCT_MAKEFILES) \ 48 ) \ 49 $(eval PRODUCT_MAKEFILES :=) \ 50 $(eval LOCAL_DIR :=) \ 51 ) 52endef 53 54# 55# Returns the sorted concatenation of all PRODUCT_MAKEFILES 56# variables set in all AndroidProducts.mk files. 57# $(call ) isn't necessary. 58# 59define get-all-product-makefiles 60$(call get-product-makefiles,$(_find-android-products-files)) 61endef 62 63# 64# Functions for including product makefiles 65# 66 67_product_var_list := \ 68 PRODUCT_NAME \ 69 PRODUCT_MODEL \ 70 PRODUCT_LOCALES \ 71 PRODUCT_AAPT_CONFIG \ 72 PRODUCT_AAPT_PREF_CONFIG \ 73 PRODUCT_PACKAGES \ 74 PRODUCT_DEVICE \ 75 PRODUCT_MANUFACTURER \ 76 PRODUCT_BRAND \ 77 PRODUCT_PROPERTY_OVERRIDES \ 78 PRODUCT_DEFAULT_PROPERTY_OVERRIDES \ 79 PRODUCT_CHARACTERISTICS \ 80 PRODUCT_COPY_FILES \ 81 PRODUCT_OTA_PUBLIC_KEYS \ 82 PRODUCT_EXTRA_RECOVERY_KEYS \ 83 PRODUCT_PACKAGE_OVERLAYS \ 84 DEVICE_PACKAGE_OVERLAYS \ 85 PRODUCT_TAGS \ 86 PRODUCT_SDK_ADDON_NAME \ 87 PRODUCT_SDK_ADDON_COPY_FILES \ 88 PRODUCT_SDK_ADDON_COPY_MODULES \ 89 PRODUCT_SDK_ADDON_DOC_MODULES \ 90 PRODUCT_DEFAULT_WIFI_CHANNELS \ 91 PRODUCT_DEFAULT_DEV_CERTIFICATE \ 92 PRODUCT_RESTRICT_VENDOR_FILES \ 93 PRODUCT_FACTORY_RAMDISK_MODULES \ 94 PRODUCT_VENDOR_KERNEL_HEADERS \ 95 96 97define dump-product 98$(info ==== $(1) ====)\ 99$(foreach v,$(_product_var_list),\ 100$(info PRODUCTS.$(1).$(v) := $(PRODUCTS.$(1).$(v))))\ 101$(info --------) 102endef 103 104define dump-products 105$(foreach p,$(PRODUCTS),$(call dump-product,$(p))) 106endef 107 108# 109# $(1): product to inherit 110# 111# Does three things: 112# 1. Inherits all of the variables from $1. 113# 2. Records the inheritance in the .INHERITS_FROM variable 114# 3. Records that we've visited this node, in ALL_PRODUCTS 115# 116define inherit-product 117 $(foreach v,$(_product_var_list), \ 118 $(eval $(v) := $($(v)) $(INHERIT_TAG)$(strip $(1)))) \ 119 $(eval inherit_var := \ 120 PRODUCTS.$(strip $(word 1,$(_include_stack))).INHERITS_FROM) \ 121 $(eval $(inherit_var) := $(sort $($(inherit_var)) $(strip $(1)))) \ 122 $(eval inherit_var:=) \ 123 $(eval ALL_PRODUCTS := $(sort $(ALL_PRODUCTS) $(word 1,$(_include_stack)))) 124endef 125 126 127# 128# Do inherit-product only if $(1) exists 129# 130define inherit-product-if-exists 131 $(if $(wildcard $(1)),$(call inherit-product,$(1)),) 132endef 133 134# 135# $(1): product makefile list 136# 137#TODO: check to make sure that products have all the necessary vars defined 138define import-products 139$(call import-nodes,PRODUCTS,$(1),$(_product_var_list)) 140endef 141 142 143# 144# Does various consistency checks on all of the known products. 145# Takes no parameters, so $(call ) is not necessary. 146# 147define check-all-products 148$(if ,, \ 149 $(eval _cap_names :=) \ 150 $(foreach p,$(PRODUCTS), \ 151 $(eval pn := $(strip $(PRODUCTS.$(p).PRODUCT_NAME))) \ 152 $(if $(pn),,$(error $(p): PRODUCT_NAME must be defined.)) \ 153 $(if $(filter $(pn),$(_cap_names)), \ 154 $(error $(p): PRODUCT_NAME must be unique; "$(pn)" already used by $(strip \ 155 $(foreach \ 156 pp,$(PRODUCTS), 157 $(if $(filter $(pn),$(PRODUCTS.$(pp).PRODUCT_NAME)), \ 158 $(pp) \ 159 ))) \ 160 ) \ 161 ) \ 162 $(eval _cap_names += $(pn)) \ 163 $(if $(call is-c-identifier,$(pn)),, \ 164 $(error $(p): PRODUCT_NAME must be a valid C identifier, not "$(pn)") \ 165 ) \ 166 $(eval pb := $(strip $(PRODUCTS.$(p).PRODUCT_BRAND))) \ 167 $(if $(pb),,$(error $(p): PRODUCT_BRAND must be defined.)) \ 168 $(foreach cf,$(strip $(PRODUCTS.$(p).PRODUCT_COPY_FILES)), \ 169 $(if $(filter 2,$(words $(subst :,$(space),$(cf)))),, \ 170 $(error $(p): malformed COPY_FILE "$(cf)") \ 171 ) \ 172 ) \ 173 ) \ 174) 175endef 176 177 178# 179# Returns the product makefile path for the product with the provided name 180# 181# $(1): short product name like "generic" 182# 183define _resolve-short-product-name 184 $(eval pn := $(strip $(1))) 185 $(eval p := \ 186 $(foreach p,$(PRODUCTS), \ 187 $(if $(filter $(pn),$(PRODUCTS.$(p).PRODUCT_NAME)), \ 188 $(p) \ 189 )) \ 190 ) 191 $(eval p := $(sort $(p))) 192 $(if $(filter 1,$(words $(p))), \ 193 $(p), \ 194 $(if $(filter 0,$(words $(p))), \ 195 $(error No matches for product "$(pn)"), \ 196 $(error Product "$(pn)" ambiguous: matches $(p)) \ 197 ) \ 198 ) 199endef 200define resolve-short-product-name 201$(strip $(call _resolve-short-product-name,$(1))) 202endef 203 204 205_product_stash_var_list := $(_product_var_list) \ 206 TARGET_ARCH \ 207 TARGET_ARCH_VARIANT \ 208 TARGET_BOARD_PLATFORM \ 209 TARGET_BOARD_PLATFORM_GPU \ 210 TARGET_BOARD_KERNEL_HEADERS \ 211 TARGET_DEVICE_KERNEL_HEADERS \ 212 TARGET_PRODUCT_KERNEL_HEADERS \ 213 TARGET_BOOTLOADER_BOARD_NAME \ 214 TARGET_COMPRESS_MODULE_SYMBOLS \ 215 TARGET_NO_BOOTLOADER \ 216 TARGET_NO_KERNEL \ 217 TARGET_NO_RECOVERY \ 218 TARGET_NO_RADIOIMAGE \ 219 TARGET_HARDWARE_3D \ 220 TARGET_PROVIDES_INIT_RC \ 221 TARGET_CPU_ABI \ 222 TARGET_CPU_ABI2 \ 223 TARGET_CPU_SMP \ 224 225 226_product_stash_var_list += \ 227 BOARD_WPA_SUPPLICANT_DRIVER \ 228 BOARD_WLAN_DEVICE \ 229 BOARD_USES_GENERIC_AUDIO \ 230 BOARD_KERNEL_CMDLINE \ 231 BOARD_KERNEL_BASE \ 232 BOARD_HAVE_BLUETOOTH \ 233 BOARD_HAVE_BLUETOOTH_BCM \ 234 BOARD_VENDOR_QCOM_AMSS_VERSION \ 235 BOARD_VENDOR_USE_AKMD \ 236 BOARD_EGL_CFG \ 237 BOARD_BOOTIMAGE_PARTITION_SIZE \ 238 BOARD_RECOVERYIMAGE_PARTITION_SIZE \ 239 BOARD_SYSTEMIMAGE_PARTITION_SIZE \ 240 BOARD_USERDATAIMAGE_PARTITION_SIZE \ 241 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE \ 242 BOARD_CACHEIMAGE_PARTITION_SIZE \ 243 BOARD_FLASH_BLOCK_SIZE \ 244 BOARD_SYSTEMIMAGE_PARTITION_SIZE \ 245 BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE \ 246 BOARD_VENDOR_QCOM_GPS_LOC_API_AMSS_VERSION \ 247 BOARD_INSTALLER_CMDLINE \ 248 249 250_product_stash_var_list += \ 251 DEFAULT_SYSTEM_DEV_CERTIFICATE 252 253# 254# Stash vaues of the variables in _product_stash_var_list. 255# $(1): Renamed prefix 256# 257define stash-product-vars 258$(foreach v,$(_product_stash_var_list), \ 259 $(eval $(strip $(1))_$(call rot13,$(v)):=$$($$(v))) \ 260 ) 261endef 262 263# 264# Assert that the the variable stashed by stash-product-vars remains untouched. 265# $(1): The prefix as supplied to stash-product-vars 266# 267define assert-product-vars 268$(strip \ 269 $(eval changed_variables:=) 270 $(foreach v,$(_product_stash_var_list), \ 271 $(if $(call streq,$($(v)),$($(strip $(1))_$(call rot13,$(v)))),, \ 272 $(eval $(warning $(v) has been modified: $($(v)))) \ 273 $(eval $(warning previous value: $($(strip $(1))_$(call rot13,$(v))))) \ 274 $(eval changed_variables := $(changed_variables) $(v))) \ 275 ) \ 276 $(if $(changed_variables),\ 277 $(eval $(error The following variables have been changed: $(changed_variables))),) 278) 279endef 280 281define add-to-product-copy-files-if-exists 282$(if $(wildcard $(word 1,$(subst :, ,$(1)))),$(1)) 283endef 284