1# 2# Copyright (C) 2008 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# Generic functions 19# TODO: Move these to definitions.make once we're able to include 20# definitions.make before config.make. 21 22########################################################### 23## Return non-empty if $(1) is a C identifier; i.e., if it 24## matches /^[a-zA-Z_][a-zA-Z0-9_]*$/. We do this by first 25## making sure that it isn't empty and doesn't start with 26## a digit, then by removing each valid character. If the 27## final result is empty, then it was a valid C identifier. 28## 29## $(1): word to check 30########################################################### 31 32_ici_digits := 0 1 2 3 4 5 6 7 8 9 33_ici_alphaunderscore := \ 34 a b c d e f g h i j k l m n o p q r s t u v w x y z \ 35 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ 36define is-c-identifier 37$(strip \ 38 $(if $(1), \ 39 $(if $(filter $(addsuffix %,$(_ici_digits)),$(1)), \ 40 , \ 41 $(eval w := $(1)) \ 42 $(foreach c,$(_ici_digits) $(_ici_alphaunderscore), \ 43 $(eval w := $(subst $(c),,$(w))) \ 44 ) \ 45 $(if $(w),,TRUE) \ 46 $(eval w :=) \ 47 ) \ 48 ) \ 49 ) 50endef 51 52# TODO: push this into the combo files; unfortunately, we don't even 53# know HOST_OS at this point. 54trysed := $(shell echo a | sed -E -e 's/a/b/' 2>/dev/null) 55ifeq ($(trysed),b) 56 SED_EXTENDED := sed -E 57else 58 trysed := $(shell echo c | sed -r -e 's/c/d/' 2>/dev/null) 59 ifeq ($(trysed),d) 60 SED_EXTENDED := sed -r 61 else 62 $(error Unknown sed version) 63 endif 64endif 65 66########################################################### 67## List all of the files in a subdirectory in a format 68## suitable for PRODUCT_COPY_FILES and 69## PRODUCT_SDK_ADDON_COPY_FILES 70## 71## $(1): Glob to match file name 72## $(2): Source directory 73## $(3): Target base directory 74########################################################### 75 76define find-copy-subdir-files 77$(sort $(shell find $(2) -name "$(1)" -type f | $(SED_EXTENDED) "s:($(2)/?(.*)):\\1\\:$(3)/\\2:" | sed "s://:/:g")) 78endef 79 80# --------------------------------------------------------------- 81 82# These are the valid values of TARGET_BUILD_VARIANT. Also, if anything else is passed 83# as the variant in the PRODUCT-$TARGET_BUILD_PRODUCT-$TARGET_BUILD_VARIANT form, 84# it will be treated as a goal, and the eng variant will be used. 85INTERNAL_VALID_VARIANTS := user userdebug eng 86 87# --------------------------------------------------------------- 88# Provide "PRODUCT-<prodname>-<goal>" targets, which lets you build 89# a particular configuration without needing to set up the environment. 90# 91ifeq ($(CALLED_FROM_SETUP),true) 92product_goals := $(strip $(filter PRODUCT-%,$(MAKECMDGOALS))) 93ifdef product_goals 94 # Scrape the product and build names out of the goal, 95 # which should be of the form PRODUCT-<productname>-<buildname>. 96 # 97 ifneq ($(words $(product_goals)),1) 98 $(error Only one PRODUCT-* goal may be specified; saw "$(product_goals)") 99 endif 100 goal_name := $(product_goals) 101 product_goals := $(patsubst PRODUCT-%,%,$(product_goals)) 102 product_goals := $(subst -, ,$(product_goals)) 103 ifneq ($(words $(product_goals)),2) 104 $(error Bad PRODUCT-* goal "$(goal_name)") 105 endif 106 107 # The product they want 108 TARGET_PRODUCT := $(word 1,$(product_goals)) 109 110 # The variant they want 111 TARGET_BUILD_VARIANT := $(word 2,$(product_goals)) 112 113 ifeq ($(TARGET_BUILD_VARIANT),tests) 114 $(error "tests" has been deprecated as a build variant. Use it as a build goal instead.) 115 endif 116 117 # The build server wants to do make PRODUCT-dream-sdk 118 # which really means TARGET_PRODUCT=dream make sdk. 119 ifneq ($(filter-out $(INTERNAL_VALID_VARIANTS),$(TARGET_BUILD_VARIANT)),) 120 override MAKECMDGOALS := $(MAKECMDGOALS) $(TARGET_BUILD_VARIANT) 121 TARGET_BUILD_VARIANT := userdebug 122 default_goal_substitution := 123 else 124 default_goal_substitution := droid 125 endif 126 127 # Replace the PRODUCT-* goal with the build goal that it refers to. 128 # Note that this will ensure that it appears in the same relative 129 # position, in case it matters. 130 override MAKECMDGOALS := $(patsubst $(goal_name),$(default_goal_substitution),$(MAKECMDGOALS)) 131endif 132endif # CALLED_FROM_SETUP 133# else: Use the value set in the environment or buildspec.mk. 134 135# --------------------------------------------------------------- 136# Provide "APP-<appname>" targets, which lets you build 137# an unbundled app. 138# 139ifeq ($(CALLED_FROM_SETUP),true) 140unbundled_goals := $(strip $(filter APP-%,$(MAKECMDGOALS))) 141ifdef unbundled_goals 142 ifneq ($(words $(unbundled_goals)),1) 143 $(error Only one APP-* goal may be specified; saw "$(unbundled_goals)") 144 endif 145 TARGET_BUILD_APPS := $(strip $(subst -, ,$(patsubst APP-%,%,$(unbundled_goals)))) 146 ifneq ($(filter droid,$(MAKECMDGOALS)),) 147 override MAKECMDGOALS := $(patsubst $(unbundled_goals),,$(MAKECMDGOALS)) 148 else 149 override MAKECMDGOALS := $(patsubst $(unbundled_goals),droid,$(MAKECMDGOALS)) 150 endif 151endif # unbundled_goals 152endif 153 154# Now that we've parsed APP-* and PRODUCT-*, mark these as readonly 155TARGET_BUILD_APPS ?= 156.KATI_READONLY := \ 157 TARGET_PRODUCT \ 158 TARGET_BUILD_VARIANT \ 159 TARGET_BUILD_APPS 160 161# Default to building dalvikvm on hosts that support it... 162ifeq ($(HOST_OS),linux) 163# ... or if the if the option is already set 164ifeq ($(WITH_HOST_DALVIK),) 165 WITH_HOST_DALVIK := true 166endif 167endif 168 169# --------------------------------------------------------------- 170# Include the product definitions. 171# We need to do this to translate TARGET_PRODUCT into its 172# underlying TARGET_DEVICE before we start defining any rules. 173# 174include $(BUILD_SYSTEM)/node_fns.mk 175include $(BUILD_SYSTEM)/product.mk 176include $(BUILD_SYSTEM)/device.mk 177 178# Read in all of the product definitions specified by the AndroidProducts.mk 179# files in the tree. 180all_product_configs := $(get-all-product-makefiles) 181 182all_named_products := 183 184# Find the product config makefile for the current product. 185# all_product_configs consists items like: 186# <product_name>:<path_to_the_product_makefile> 187# or just <path_to_the_product_makefile> in case the product name is the 188# same as the base filename of the product config makefile. 189current_product_makefile := 190all_product_makefiles := 191$(foreach f, $(all_product_configs),\ 192 $(eval _cpm_words := $(call _decode-product-name,$(f)))\ 193 $(eval _cpm_word1 := $(word 1,$(_cpm_words)))\ 194 $(eval _cpm_word2 := $(word 2,$(_cpm_words)))\ 195 $(eval all_product_makefiles += $(_cpm_word2))\ 196 $(eval all_named_products += $(_cpm_word1))\ 197 $(if $(filter $(TARGET_PRODUCT),$(_cpm_word1)),\ 198 $(eval current_product_makefile += $(_cpm_word2)),)) 199_cpm_words := 200_cpm_word1 := 201_cpm_word2 := 202current_product_makefile := $(strip $(current_product_makefile)) 203all_product_makefiles := $(strip $(all_product_makefiles)) 204 205load_all_product_makefiles := 206ifneq (,$(filter product-graph, $(MAKECMDGOALS))) 207ifeq ($(ANDROID_PRODUCT_GRAPH),--all) 208load_all_product_makefiles := true 209endif 210endif 211ifneq (,$(filter dump-products,$(MAKECMDGOALS))) 212ifeq ($(ANDROID_DUMP_PRODUCTS),all) 213load_all_product_makefiles := true 214endif 215endif 216 217ifeq ($(load_all_product_makefiles),true) 218# Import all product makefiles. 219$(call import-products, $(all_product_makefiles)) 220else 221# Import just the current product. 222ifndef current_product_makefile 223$(error Can not locate config makefile for product "$(TARGET_PRODUCT)") 224endif 225ifneq (1,$(words $(current_product_makefile))) 226$(error Product "$(TARGET_PRODUCT)" ambiguous: matches $(current_product_makefile)) 227endif 228$(call import-products, $(current_product_makefile)) 229endif # Import all or just the current product makefile 230 231# Import all the products that have made artifact path requirements, so that we can verify 232# the artifacts they produce. 233$(foreach makefile,$(ARTIFACT_PATH_REQUIREMENT_PRODUCTS),\ 234 $(if $(filter-out $(makefile),$(PRODUCTS)),$(eval $(call import-products,$(makefile))))\ 235) 236 237# Sanity check 238$(check-all-products) 239 240ifneq ($(filter dump-products, $(MAKECMDGOALS)),) 241$(dump-products) 242endif 243 244# Convert a short name like "sooner" into the path to the product 245# file defining that product. 246# 247INTERNAL_PRODUCT := $(call resolve-short-product-name, $(TARGET_PRODUCT)) 248ifneq ($(current_product_makefile),$(INTERNAL_PRODUCT)) 249$(error PRODUCT_NAME inconsistent in $(current_product_makefile) and $(INTERNAL_PRODUCT)) 250endif 251current_product_makefile := 252all_product_makefiles := 253all_product_configs := 254 255############################################################################ 256# Strip and assign the PRODUCT_ variables. 257$(call strip-product-vars) 258 259############################################################################# 260# Sanity check and assign default values 261 262TARGET_DEVICE := $(PRODUCT_DEVICE) 263 264# TODO: also keep track of things like "port", "land" in product files. 265 266# Figure out which resoure configuration options to use for this 267# product. 268# If CUSTOM_LOCALES contains any locales not already included 269# in PRODUCT_LOCALES, add them to PRODUCT_LOCALES. 270extra_locales := $(filter-out $(PRODUCT_LOCALES),$(CUSTOM_LOCALES)) 271ifneq (,$(extra_locales)) 272 ifneq ($(CALLED_FROM_SETUP),true) 273 # Don't spam stdout, because envsetup.sh may be scraping values from it. 274 $(info Adding CUSTOM_LOCALES [$(extra_locales)] to PRODUCT_LOCALES [$(PRODUCT_LOCALES)]) 275 endif 276 PRODUCT_LOCALES += $(extra_locales) 277 extra_locales := 278endif 279 280# Add PRODUCT_LOCALES to PRODUCT_AAPT_CONFIG 281PRODUCT_AAPT_CONFIG := $(PRODUCT_LOCALES) $(PRODUCT_AAPT_CONFIG) 282 283# Keep a copy of the space-separated config 284PRODUCT_AAPT_CONFIG_SP := $(PRODUCT_AAPT_CONFIG) 285PRODUCT_AAPT_CONFIG := $(subst $(space),$(comma),$(PRODUCT_AAPT_CONFIG)) 286 287ifndef PRODUCT_SYSTEM_NAME 288 PRODUCT_SYSTEM_NAME := $(PRODUCT_NAME) 289endif 290ifndef PRODUCT_SYSTEM_DEVICE 291 PRODUCT_SYSTEM_DEVICE := $(PRODUCT_DEVICE) 292endif 293ifndef PRODUCT_SYSTEM_BRAND 294 PRODUCT_SYSTEM_BRAND := $(PRODUCT_BRAND) 295endif 296ifndef PRODUCT_MODEL 297 PRODUCT_MODEL := $(PRODUCT_NAME) 298endif 299ifndef PRODUCT_SYSTEM_MODEL 300 PRODUCT_SYSTEM_MODEL := $(PRODUCT_MODEL) 301endif 302 303ifndef PRODUCT_MANUFACTURER 304 PRODUCT_MANUFACTURER := unknown 305endif 306ifndef PRODUCT_SYSTEM_MANUFACTURER 307 PRODUCT_SYSTEM_MANUFACTURER := $(PRODUCT_MANUFACTURER) 308endif 309 310ifndef PRODUCT_CHARACTERISTICS 311 TARGET_AAPT_CHARACTERISTICS := default 312else 313 TARGET_AAPT_CHARACTERISTICS := $(PRODUCT_CHARACTERISTICS) 314endif 315 316ifdef PRODUCT_DEFAULT_DEV_CERTIFICATE 317 ifneq (1,$(words $(PRODUCT_DEFAULT_DEV_CERTIFICATE))) 318 $(error PRODUCT_DEFAULT_DEV_CERTIFICATE='$(PRODUCT_DEFAULT_DEV_CERTIFICATE)', \ 319 only 1 certificate is allowed.) 320 endif 321endif 322 323ENFORCE_SYSTEM_CERTIFICATE := $(PRODUCT_ENFORCE_ARTIFACT_SYSTEM_CERTIFICATE_REQUIREMENT) 324ENFORCE_SYSTEM_CERTIFICATE_WHITELIST := $(PRODUCT_ARTIFACT_SYSTEM_CERTIFICATE_REQUIREMENT_WHITELIST) 325 326PRODUCT_OTA_PUBLIC_KEYS := $(sort $(PRODUCT_OTA_PUBLIC_KEYS)) 327PRODUCT_EXTRA_RECOVERY_KEYS := $(sort $(PRODUCT_EXTRA_RECOVERY_KEYS)) 328 329# Resolve and setup per-module dex-preopt configs. 330DEXPREOPT_DISABLED_MODULES := 331# If a module has multiple setups, the first takes precedence. 332_pdpmc_modules := 333$(foreach c,$(PRODUCT_DEX_PREOPT_MODULE_CONFIGS),\ 334 $(eval m := $(firstword $(subst =,$(space),$(c))))\ 335 $(if $(filter $(_pdpmc_modules),$(m)),,\ 336 $(eval _pdpmc_modules += $(m))\ 337 $(eval cf := $(patsubst $(m)=%,%,$(c)))\ 338 $(eval cf := $(subst $(_PDPMC_SP_PLACE_HOLDER),$(space),$(cf)))\ 339 $(if $(filter disable,$(cf)),\ 340 $(eval DEXPREOPT_DISABLED_MODULES += $(m)),\ 341 $(eval DEXPREOPT.$(TARGET_PRODUCT).$(m).CONFIG := $(cf))))) 342_pdpmc_modules := 343 344 345# Resolve and setup per-module sanitizer configs. 346# If a module has multiple setups, the first takes precedence. 347_psmc_modules := 348$(foreach c,$(PRODUCT_SANITIZER_MODULE_CONFIGS),\ 349 $(eval m := $(firstword $(subst =,$(space),$(c))))\ 350 $(if $(filter $(_psmc_modules),$(m)),,\ 351 $(eval _psmc_modules += $(m))\ 352 $(eval cf := $(patsubst $(m)=%,%,$(c)))\ 353 $(eval cf := $(subst $(_PSMC_SP_PLACE_HOLDER),$(space),$(cf)))\ 354 $(eval SANITIZER.$(TARGET_PRODUCT).$(m).CONFIG := $(cf)))) 355_psmc_modules := 356 357# Reset ADB keys for non-debuggable builds 358ifeq (,$(filter eng userdebug,$(TARGET_BUILD_VARIANT)),) 359 PRODUCT_ADB_KEYS := 360endif 361ifneq ($(filter-out 0 1,$(words $(PRODUCT_ADB_KEYS))),) 362 $(error Only one file may be in PRODUCT_ADB_KEYS: $(PRODUCT_ADB_KEYS)) 363endif 364 365ifndef PRODUCT_USE_DYNAMIC_PARTITIONS 366 PRODUCT_USE_DYNAMIC_PARTITIONS := $(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS) 367endif 368 369# All requirements of PRODUCT_USE_DYNAMIC_PARTITIONS falls back to 370# PRODUCT_USE_DYNAMIC_PARTITIONS if not defined. 371ifndef PRODUCT_USE_DYNAMIC_PARTITION_SIZE 372 PRODUCT_USE_DYNAMIC_PARTITION_SIZE := $(PRODUCT_USE_DYNAMIC_PARTITIONS) 373endif 374 375ifndef PRODUCT_BUILD_SUPER_PARTITION 376 PRODUCT_BUILD_SUPER_PARTITION := $(PRODUCT_USE_DYNAMIC_PARTITIONS) 377endif 378 379ifeq ($(PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS),) 380 ifdef PRODUCT_SHIPPING_API_LEVEL 381 ifeq (true,$(call math_gt_or_eq,$(PRODUCT_SHIPPING_API_LEVEL),29)) 382 PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS := true 383 endif 384 endif 385endif 386 387define product-overrides-config 388$$(foreach rule,$$(PRODUCT_$(1)_OVERRIDES),\ 389 $$(if $$(filter 2,$$(words $$(subst :,$$(space),$$(rule)))),,\ 390 $$(error Rule "$$(rule)" in PRODUCT_$(1)_OVERRIDE is not <module_name>:<new_value>))) 391endef 392 393$(foreach var, \ 394 MANIFEST_PACKAGE_NAME \ 395 PACKAGE_NAME \ 396 CERTIFICATE, \ 397 $(eval $(call product-overrides-config,$(var)))) 398 399# Macro to use below. $(1) is the name of the partition 400define product-build-image-config 401PRODUCT_BUILD_$(1)_IMAGE := $$(firstword $$(PRODUCT_BUILD_$(1)_IMAGE)) 402ifneq ($$(filter-out true false,$$(PRODUCT_BUILD_$(1)_IMAGE)),) 403 $$(error Invalid PRODUCT_BUILD_$(1)_IMAGE: $$(PRODUCT_BUILD_$(1)_IMAGE) -- true false and empty are supported) 404endif 405endef 406 407# Copy and check the value of each PRODUCT_BUILD_*_IMAGE variable 408$(foreach image, \ 409 SYSTEM \ 410 SYSTEM_OTHER \ 411 VENDOR \ 412 PRODUCT \ 413 PRODUCT_SERVICES \ 414 ODM \ 415 CACHE \ 416 RAMDISK \ 417 USERDATA, \ 418 $(eval $(call product-build-image-config,$(image)))) 419 420product-build-image-config := 421 422$(call readonly-product-vars) 423