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 # Search for AndroidProducts.mks in the given dir. 27 # $(1): the path to the dir 28 define _search-android-products-files-in-dir 29 $(sort $(shell test -d $(1) && find -L $(1) \ 30 -maxdepth 6 \ 31 -name .git -prune \ 32 -o -name AndroidProducts.mk -print)) 33 endef 34 35 # 36 # Returns the list of all AndroidProducts.mk files. 37 # $(call ) isn't necessary. 38 # 39 define _find-android-products-files 40 $(foreach d, device vendor product,$(call _search-android-products-files-in-dir,$(d))) \ 41 $(SRC_TARGET_DIR)/product/AndroidProducts.mk 42 endef 43 44 # 45 # Returns the sorted concatenation of PRODUCT_MAKEFILES 46 # variables set in the given AndroidProducts.mk files. 47 # $(1): the list of AndroidProducts.mk files. 48 # 49 define get-product-makefiles 50 $(sort \ 51 $(foreach f,$(1), \ 52 $(eval PRODUCT_MAKEFILES :=) \ 53 $(eval LOCAL_DIR := $(patsubst %/,%,$(dir $(f)))) \ 54 $(eval include $(f)) \ 55 $(PRODUCT_MAKEFILES) \ 56 ) \ 57 $(eval PRODUCT_MAKEFILES :=) \ 58 $(eval LOCAL_DIR :=) \ 59 ) 60 endef 61 62 # 63 # Returns the sorted concatenation of all PRODUCT_MAKEFILES 64 # variables set in all AndroidProducts.mk files. 65 # $(call ) isn't necessary. 66 # 67 define get-all-product-makefiles 68 $(call get-product-makefiles,$(_find-android-products-files)) 69 endef 70 71 # 72 # Functions for including product makefiles 73 # 74 75 _product_var_list := \ 76 PRODUCT_NAME \ 77 PRODUCT_MODEL \ 78 PRODUCT_LOCALES \ 79 PRODUCT_AAPT_CONFIG \ 80 PRODUCT_AAPT_PREF_CONFIG \ 81 PRODUCT_AAPT_PREBUILT_DPI \ 82 PRODUCT_PACKAGES \ 83 PRODUCT_PACKAGES_DEBUG \ 84 PRODUCT_PACKAGES_ENG \ 85 PRODUCT_PACKAGES_TESTS \ 86 PRODUCT_DEVICE \ 87 PRODUCT_MANUFACTURER \ 88 PRODUCT_BRAND \ 89 PRODUCT_PROPERTY_OVERRIDES \ 90 PRODUCT_DEFAULT_PROPERTY_OVERRIDES \ 91 PRODUCT_PRODUCT_PROPERTIES \ 92 PRODUCT_CHARACTERISTICS \ 93 PRODUCT_COPY_FILES \ 94 PRODUCT_OTA_PUBLIC_KEYS \ 95 PRODUCT_EXTRA_RECOVERY_KEYS \ 96 PRODUCT_PACKAGE_OVERLAYS \ 97 DEVICE_PACKAGE_OVERLAYS \ 98 PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS \ 99 PRODUCT_ENFORCE_RRO_TARGETS \ 100 PRODUCT_SDK_ATREE_FILES \ 101 PRODUCT_SDK_ADDON_NAME \ 102 PRODUCT_SDK_ADDON_COPY_FILES \ 103 PRODUCT_SDK_ADDON_COPY_MODULES \ 104 PRODUCT_SDK_ADDON_DOC_MODULES \ 105 PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP \ 106 PRODUCT_SOONG_NAMESPACES \ 107 PRODUCT_DEFAULT_WIFI_CHANNELS \ 108 PRODUCT_DEFAULT_DEV_CERTIFICATE \ 109 PRODUCT_RESTRICT_VENDOR_FILES \ 110 PRODUCT_VENDOR_KERNEL_HEADERS \ 111 PRODUCT_BOOT_JARS \ 112 PRODUCT_SUPPORTS_BOOT_SIGNER \ 113 PRODUCT_SUPPORTS_VBOOT \ 114 PRODUCT_SUPPORTS_VERITY \ 115 PRODUCT_SUPPORTS_VERITY_FEC \ 116 PRODUCT_OEM_PROPERTIES \ 117 PRODUCT_SYSTEM_DEFAULT_PROPERTIES \ 118 PRODUCT_SYSTEM_PROPERTY_BLACKLIST \ 119 PRODUCT_VENDOR_PROPERTY_BLACKLIST \ 120 PRODUCT_SYSTEM_SERVER_APPS \ 121 PRODUCT_SYSTEM_SERVER_JARS \ 122 PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK \ 123 PRODUCT_DEXPREOPT_SPEED_APPS \ 124 PRODUCT_LOADED_BY_PRIVILEGED_MODULES \ 125 PRODUCT_VBOOT_SIGNING_KEY \ 126 PRODUCT_VBOOT_SIGNING_SUBKEY \ 127 PRODUCT_VERITY_SIGNING_KEY \ 128 PRODUCT_SYSTEM_VERITY_PARTITION \ 129 PRODUCT_VENDOR_VERITY_PARTITION \ 130 PRODUCT_PRODUCT_VERITY_PARTITION \ 131 PRODUCT_SYSTEM_SERVER_DEBUG_INFO \ 132 PRODUCT_OTHER_JAVA_DEBUG_INFO \ 133 PRODUCT_DEX_PREOPT_MODULE_CONFIGS \ 134 PRODUCT_DEX_PREOPT_DEFAULT_COMPILER_FILTER \ 135 PRODUCT_DEX_PREOPT_DEFAULT_FLAGS \ 136 PRODUCT_DEX_PREOPT_BOOT_FLAGS \ 137 PRODUCT_DEX_PREOPT_PROFILE_DIR \ 138 PRODUCT_DEX_PREOPT_BOOT_IMAGE_PROFILE_LOCATION \ 139 PRODUCT_DEX_PREOPT_GENERATE_DM_FILES \ 140 PRODUCT_USE_PROFILE_FOR_BOOT_IMAGE \ 141 PRODUCT_SYSTEM_SERVER_COMPILER_FILTER \ 142 PRODUCT_SANITIZER_MODULE_CONFIGS \ 143 PRODUCT_SYSTEM_BASE_FS_PATH \ 144 PRODUCT_VENDOR_BASE_FS_PATH \ 145 PRODUCT_PRODUCT_BASE_FS_PATH \ 146 PRODUCT_SHIPPING_API_LEVEL \ 147 VENDOR_PRODUCT_RESTRICT_VENDOR_FILES \ 148 VENDOR_EXCEPTION_MODULES \ 149 VENDOR_EXCEPTION_PATHS \ 150 PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD \ 151 PRODUCT_ART_USE_READ_BARRIER \ 152 PRODUCT_IOT \ 153 PRODUCT_SYSTEM_HEADROOM \ 154 PRODUCT_MINIMIZE_JAVA_DEBUG_INFO \ 155 PRODUCT_INTEGER_OVERFLOW_EXCLUDE_PATHS \ 156 PRODUCT_ADB_KEYS \ 157 PRODUCT_CFI_INCLUDE_PATHS \ 158 PRODUCT_CFI_EXCLUDE_PATHS \ 159 PRODUCT_COMPATIBLE_PROPERTY_OVERRIDE \ 160 PRODUCT_ACTIONABLE_COMPATIBLE_PROPERTY_DISABLE \ 161 162 define dump-product 163 $(info ==== $(1) ====)\ 164 $(foreach v,$(_product_var_list),\ 165 $(info PRODUCTS.$(1).$(v) := $(PRODUCTS.$(1).$(v))))\ 166 $(info --------) 167 endef 168 169 define dump-products 170 $(foreach p,$(PRODUCTS),$(call dump-product,$(p))) 171 endef 172 173 # 174 # $(1): product to inherit 175 # 176 # Does three things: 177 # 1. Inherits all of the variables from $1. 178 # 2. Records the inheritance in the .INHERITS_FROM variable 179 # 3. Records that we've visited this node, in ALL_PRODUCTS 180 # 181 define inherit-product 182 $(if $(findstring ../,$(1)),\ 183 $(eval np := $(call normalize-paths,$(1))),\ 184 $(eval np := $(strip $(1))))\ 185 $(foreach v,$(_product_var_list), \ 186 $(eval $(v) := $($(v)) $(INHERIT_TAG)$(np))) \ 187 $(eval inherit_var := \ 188 PRODUCTS.$(strip $(word 1,$(_include_stack))).INHERITS_FROM) \ 189 $(eval $(inherit_var) := $(sort $($(inherit_var)) $(np))) \ 190 $(eval inherit_var:=) \ 191 $(eval ALL_PRODUCTS := $(sort $(ALL_PRODUCTS) $(word 1,$(_include_stack)))) 192 endef 193 194 195 # 196 # Do inherit-product only if $(1) exists 197 # 198 define inherit-product-if-exists 199 $(if $(wildcard $(1)),$(call inherit-product,$(1)),) 200 endef 201 202 # 203 # $(1): product makefile list 204 # 205 #TODO: check to make sure that products have all the necessary vars defined 206 define import-products 207 $(call import-nodes,PRODUCTS,$(1),$(_product_var_list)) 208 endef 209 210 211 # 212 # Does various consistency checks on all of the known products. 213 # Takes no parameters, so $(call ) is not necessary. 214 # 215 define check-all-products 216 $(if ,, \ 217 $(eval _cap_names :=) \ 218 $(foreach p,$(PRODUCTS), \ 219 $(eval pn := $(strip $(PRODUCTS.$(p).PRODUCT_NAME))) \ 220 $(if $(pn),,$(error $(p): PRODUCT_NAME must be defined.)) \ 221 $(if $(filter $(pn),$(_cap_names)), \ 222 $(error $(p): PRODUCT_NAME must be unique; "$(pn)" already used by $(strip \ 223 $(foreach \ 224 pp,$(PRODUCTS), 225 $(if $(filter $(pn),$(PRODUCTS.$(pp).PRODUCT_NAME)), \ 226 $(pp) \ 227 ))) \ 228 ) \ 229 ) \ 230 $(eval _cap_names += $(pn)) \ 231 $(if $(call is-c-identifier,$(pn)),, \ 232 $(error $(p): PRODUCT_NAME must be a valid C identifier, not "$(pn)") \ 233 ) \ 234 $(eval pb := $(strip $(PRODUCTS.$(p).PRODUCT_BRAND))) \ 235 $(if $(pb),,$(error $(p): PRODUCT_BRAND must be defined.)) \ 236 $(foreach cf,$(strip $(PRODUCTS.$(p).PRODUCT_COPY_FILES)), \ 237 $(if $(filter 2 3,$(words $(subst :,$(space),$(cf)))),, \ 238 $(error $(p): malformed COPY_FILE "$(cf)") \ 239 ) \ 240 ) \ 241 ) \ 242 ) 243 endef 244 245 246 # 247 # Returns the product makefile path for the product with the provided name 248 # 249 # $(1): short product name like "generic" 250 # 251 define _resolve-short-product-name 252 $(eval pn := $(strip $(1))) 253 $(eval p := \ 254 $(foreach p,$(PRODUCTS), \ 255 $(if $(filter $(pn),$(PRODUCTS.$(p).PRODUCT_NAME)), \ 256 $(p) \ 257 )) \ 258 ) 259 $(eval p := $(sort $(p))) 260 $(if $(filter 1,$(words $(p))), \ 261 $(p), \ 262 $(if $(filter 0,$(words $(p))), \ 263 $(error No matches for product "$(pn)"), \ 264 $(error Product "$(pn)" ambiguous: matches $(p)) \ 265 ) \ 266 ) 267 endef 268 define resolve-short-product-name 269 $(strip $(call _resolve-short-product-name,$(1))) 270 endef 271 272 273 _product_stash_var_list := $(_product_var_list) \ 274 PRODUCT_BOOTCLASSPATH \ 275 PRODUCT_SYSTEM_SERVER_CLASSPATH \ 276 TARGET_ARCH \ 277 TARGET_ARCH_VARIANT \ 278 TARGET_CPU_VARIANT \ 279 TARGET_BOARD_PLATFORM \ 280 TARGET_BOARD_PLATFORM_GPU \ 281 TARGET_BOARD_KERNEL_HEADERS \ 282 TARGET_DEVICE_KERNEL_HEADERS \ 283 TARGET_PRODUCT_KERNEL_HEADERS \ 284 TARGET_BOOTLOADER_BOARD_NAME \ 285 TARGET_NO_BOOTLOADER \ 286 TARGET_NO_KERNEL \ 287 TARGET_NO_RECOVERY \ 288 TARGET_NO_RADIOIMAGE \ 289 TARGET_HARDWARE_3D \ 290 TARGET_CPU_ABI \ 291 TARGET_CPU_ABI2 \ 292 293 294 _product_stash_var_list += \ 295 BOARD_WPA_SUPPLICANT_DRIVER \ 296 BOARD_WLAN_DEVICE \ 297 BOARD_USES_GENERIC_AUDIO \ 298 BOARD_KERNEL_CMDLINE \ 299 BOARD_KERNEL_BASE \ 300 BOARD_HAVE_BLUETOOTH \ 301 BOARD_VENDOR_USE_AKMD \ 302 BOARD_EGL_CFG \ 303 BOARD_BOOTIMAGE_PARTITION_SIZE \ 304 BOARD_RECOVERYIMAGE_PARTITION_SIZE \ 305 BOARD_SYSTEMIMAGE_PARTITION_SIZE \ 306 BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE \ 307 BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE \ 308 BOARD_USERDATAIMAGE_PARTITION_SIZE \ 309 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE \ 310 BOARD_CACHEIMAGE_PARTITION_SIZE \ 311 BOARD_FLASH_BLOCK_SIZE \ 312 BOARD_VENDORIMAGE_PARTITION_SIZE \ 313 BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE \ 314 BOARD_PRODUCTIMAGE_PARTITION_SIZE \ 315 BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE \ 316 BOARD_INSTALLER_CMDLINE \ 317 318 319 _product_stash_var_list += \ 320 DEFAULT_SYSTEM_DEV_CERTIFICATE \ 321 WITH_DEXPREOPT \ 322 WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY 323 324 # 325 # Mark the variables in _product_stash_var_list as readonly 326 # 327 define readonly-product-vars 328 $(foreach v,$(_product_stash_var_list), \ 329 $(eval $(v) ?=) \ 330 $(eval .KATI_READONLY := $(v)) \ 331 ) 332 endef 333 334 define add-to-product-copy-files-if-exists 335 $(if $(wildcard $(word 1,$(subst :, ,$(1)))),$(1)) 336 endef 337 338 # whitespace placeholder when we record module's dex-preopt config. 339 _PDPMC_SP_PLACE_HOLDER := |@SP@| 340 # Set up dex-preopt config for a module. 341 # $(1) list of module names 342 # $(2) the modules' dex-preopt config 343 define add-product-dex-preopt-module-config 344 $(eval _c := $(subst $(space),$(_PDPMC_SP_PLACE_HOLDER),$(strip $(2))))\ 345 $(eval PRODUCT_DEX_PREOPT_MODULE_CONFIGS += \ 346 $(foreach m,$(1),$(m)=$(_c))) 347 endef 348 349 # whitespace placeholder when we record module's sanitizer config. 350 _PSMC_SP_PLACE_HOLDER := |@SP@| 351 # Set up sanitizer config for a module. 352 # $(1) list of module names 353 # $(2) the modules' sanitizer config 354 define add-product-sanitizer-module-config 355 $(eval _c := $(subst $(space),$(_PSMC_SP_PLACE_HOLDER),$(strip $(2))))\ 356 $(eval PRODUCT_SANITIZER_MODULE_CONFIGS += \ 357 $(foreach m,$(1),$(m)=$(_c))) 358 endef 359