blob: 777d2bc0f67cbf0c6c53e35ed224fca009521de8 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001#
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
Ying Wang157a5e12012-09-27 13:26:25 -070019# 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.
The Android Open Source Project88b60792009-03-03 19:28:42 -080025
26#
27# Returns the list of all AndroidProducts.mk files.
28# $(call ) isn't necessary.
29#
30define _find-android-products-files
Dan Willemsenb9d63512018-05-01 22:34:03 -070031$(file <$(OUT_DIR)/.module_paths/AndroidProducts.mk.list) \
The Android Open Source Project88b60792009-03-03 19:28:42 -080032 $(SRC_TARGET_DIR)/product/AndroidProducts.mk
33endef
34
35#
Dan Willemsenaf2e1f82018-04-04 15:41:41 -070036# For entries returned by get-product-makefiles, decode an entry to a short
37# product name. These either may be in the form of <name>:path/to/file.mk or
38# path/to/<name>.mk
39# $(1): The entry to decode
40#
41# Returns two words:
42# <name> <file>
43#
44define _decode-product-name
45$(strip \
46 $(eval _cpm_words := $(subst :,$(space),$(1))) \
47 $(if $(word 2,$(_cpm_words)), \
48 $(wordlist 1,2,$(_cpm_words)), \
49 $(basename $(notdir $(1))) $(1)))
50endef
51
52#
53# Validates the new common lunch choices -- ensures that they're in an
54# appropriate form, and are paired with definitions of their products.
55# $(1): The new list of COMMON_LUNCH_CHOICES
56# $(2): The new list of PRODUCT_MAKEFILES
57#
58define _validate-common-lunch-choices
59$(strip $(foreach choice,$(1),\
60 $(eval _parts := $(subst -,$(space),$(choice))) \
61 $(if $(call math_lt,$(words $(_parts)),2), \
62 $(error $(LOCAL_DIR): $(choice): Invalid lunch choice)) \
63 $(if $(call math_gt_or_eq,$(words $(_parts)),4), \
64 $(error $(LOCAL_DIR): $(choice): Invalid lunch choice)) \
65 $(if $(filter-out eng userdebug user,$(word 2,$(_parts))), \
66 $(error $(LOCAL_DIR): $(choice): Invalid variant: $(word 2,$(_parts)))) \
67 $(if $(filter-out $(foreach p,$(2),$(call _decode-product-name,$(p))),$(word 1,$(_parts))), \
68 $(error $(LOCAL_DIR): $(word 1,$(_parts)): Product not defined in this file)) \
69 ))
70endef
71
72#
Ying Wang1a031e42010-05-10 16:35:39 -070073# Returns the sorted concatenation of PRODUCT_MAKEFILES
74# variables set in the given AndroidProducts.mk files.
75# $(1): the list of AndroidProducts.mk files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080076#
Dan Willemsenaf2e1f82018-04-04 15:41:41 -070077# As a side-effect, COMMON_LUNCH_CHOICES will be set to a
78# union of all of the COMMON_LUNCH_CHOICES definitions within
79# each AndroidProducts.mk file.
80#
Ying Wang1a031e42010-05-10 16:35:39 -070081define get-product-makefiles
The Android Open Source Project88b60792009-03-03 19:28:42 -080082$(sort \
Dan Willemsenaf2e1f82018-04-04 15:41:41 -070083 $(eval _COMMON_LUNCH_CHOICES :=) \
Ying Wang1a031e42010-05-10 16:35:39 -070084 $(foreach f,$(1), \
The Android Open Source Project88b60792009-03-03 19:28:42 -080085 $(eval PRODUCT_MAKEFILES :=) \
Dan Willemsenaf2e1f82018-04-04 15:41:41 -070086 $(eval COMMON_LUNCH_CHOICES :=) \
The Android Open Source Project88b60792009-03-03 19:28:42 -080087 $(eval LOCAL_DIR := $(patsubst %/,%,$(dir $(f)))) \
88 $(eval include $(f)) \
Dan Willemsenaf2e1f82018-04-04 15:41:41 -070089 $(call _validate-common-lunch-choices,$(COMMON_LUNCH_CHOICES),$(PRODUCT_MAKEFILES)) \
90 $(eval _COMMON_LUNCH_CHOICES += $(COMMON_LUNCH_CHOICES)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -080091 $(PRODUCT_MAKEFILES) \
92 ) \
93 $(eval PRODUCT_MAKEFILES :=) \
94 $(eval LOCAL_DIR :=) \
Dan Willemsen5436c7e2019-02-11 21:31:47 -080095 $(eval COMMON_LUNCH_CHOICES := $(sort $(_COMMON_LUNCH_CHOICES))) \
Dan Willemsenaf2e1f82018-04-04 15:41:41 -070096 $(eval _COMMON_LUNCH_CHOICES :=) \
The Android Open Source Project88b60792009-03-03 19:28:42 -080097 )
98endef
99
100#
Ying Wang1a031e42010-05-10 16:35:39 -0700101# Returns the sorted concatenation of all PRODUCT_MAKEFILES
102# variables set in all AndroidProducts.mk files.
103# $(call ) isn't necessary.
104#
105define get-all-product-makefiles
106$(call get-product-makefiles,$(_find-android-products-files))
107endef
108
Anton Hansson13ea2a62019-03-28 14:47:25 +0000109_product_var_list :=
110_product_var_list += PRODUCT_NAME
111_product_var_list += PRODUCT_MODEL
The Android Open Source Project88b60792009-03-03 19:28:42 -0800112
Anton Hansson13ea2a62019-03-28 14:47:25 +0000113# The resoure configuration options to use for this product.
114_product_var_list += PRODUCT_LOCALES
115_product_var_list += PRODUCT_AAPT_CONFIG
116_product_var_list += PRODUCT_AAPT_PREF_CONFIG
117_product_var_list += PRODUCT_AAPT_PREBUILT_DPI
118_product_var_list += PRODUCT_HOST_PACKAGES
119_product_var_list += PRODUCT_PACKAGES
120_product_var_list += PRODUCT_PACKAGES_DEBUG
121_product_var_list += PRODUCT_PACKAGES_DEBUG_ASAN
122_product_var_list += PRODUCT_PACKAGES_ENG
123_product_var_list += PRODUCT_PACKAGES_TESTS
124
125# The device that this product maps to.
126_product_var_list += PRODUCT_DEVICE
127_product_var_list += PRODUCT_MANUFACTURER
128_product_var_list += PRODUCT_BRAND
129
130# These PRODUCT_SYSTEM_* flags, if defined, are used in place of the
131# corresponding PRODUCT_* flags for the sysprops on /system.
132_product_var_list += \
Anton Hanssonee4c9702018-12-21 15:36:00 +0000133 PRODUCT_SYSTEM_NAME \
134 PRODUCT_SYSTEM_MODEL \
135 PRODUCT_SYSTEM_DEVICE \
136 PRODUCT_SYSTEM_BRAND \
137 PRODUCT_SYSTEM_MANUFACTURER \
Anton Hansson13ea2a62019-03-28 14:47:25 +0000138
139# A list of property assignments, like "key = value", with zero or more
140# whitespace characters on either side of the '='.
141_product_var_list += PRODUCT_PROPERTY_OVERRIDES
142
143# A list of property assignments, like "key = value", with zero or more
144# whitespace characters on either side of the '='.
145# used for adding properties to default.prop
146_product_var_list += PRODUCT_DEFAULT_PROPERTY_OVERRIDES
147
148# A list of property assignments, like "key = value", with zero or more
149# whitespace characters on either side of the '='.
150# used for adding properties to build.prop of product partition
151_product_var_list += PRODUCT_PRODUCT_PROPERTIES
152
153# A list of property assignments, like "key = value", with zero or more
154# whitespace characters on either side of the '='.
155# used for adding properties to build.prop of product partition
156_product_var_list += PRODUCT_PRODUCT_SERVICES_PROPERTIES
157_product_var_list += PRODUCT_ODM_PROPERTIES
158_product_var_list += PRODUCT_CHARACTERISTICS
159
160# A list of words like <source path>:<destination path>[:<owner>].
161# The file at the source path should be copied to the destination path
162# when building this product. <destination path> is relative to
163# $(PRODUCT_OUT), so it should look like, e.g., "system/etc/file.xml".
164# The rules for these copy steps are defined in build/make/core/Makefile.
165# The optional :<owner> is used to indicate the owner of a vendor file.
166_product_var_list += PRODUCT_COPY_FILES
167
168# The OTA key(s) specified by the product config, if any. The names
169# of these keys are stored in the target-files zip so that post-build
170# signing tools can substitute them for the test key embedded by
171# default.
172_product_var_list += PRODUCT_OTA_PUBLIC_KEYS
173_product_var_list += PRODUCT_EXTRA_RECOVERY_KEYS
174
175# Should we use the default resources or add any product specific overlays
176_product_var_list += PRODUCT_PACKAGE_OVERLAYS
177_product_var_list += DEVICE_PACKAGE_OVERLAYS
178
179# Resource overlay list which must be excluded from enforcing RRO.
180_product_var_list += PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS
181
182# Package list to apply enforcing RRO.
183_product_var_list += PRODUCT_ENFORCE_RRO_TARGETS
184
185_product_var_list += PRODUCT_SDK_ATREE_FILES
186_product_var_list += PRODUCT_SDK_ADDON_NAME
187_product_var_list += PRODUCT_SDK_ADDON_COPY_FILES
188_product_var_list += PRODUCT_SDK_ADDON_COPY_MODULES
189_product_var_list += PRODUCT_SDK_ADDON_DOC_MODULES
190_product_var_list += PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP
191
192# which Soong namespaces to export to Make
193_product_var_list += PRODUCT_SOONG_NAMESPACES
194
195_product_var_list += PRODUCT_DEFAULT_WIFI_CHANNELS
196_product_var_list += PRODUCT_DEFAULT_DEV_CERTIFICATE
197_product_var_list += PRODUCT_RESTRICT_VENDOR_FILES
198
199# The list of product-specific kernel header dirs
200_product_var_list += PRODUCT_VENDOR_KERNEL_HEADERS
201
202# A list of module names of BOOTCLASSPATH (jar files)
203_product_var_list += PRODUCT_BOOT_JARS
204_product_var_list += PRODUCT_SUPPORTS_BOOT_SIGNER
205_product_var_list += PRODUCT_SUPPORTS_VBOOT
206_product_var_list += PRODUCT_SUPPORTS_VERITY
207_product_var_list += PRODUCT_SUPPORTS_VERITY_FEC
208_product_var_list += PRODUCT_OEM_PROPERTIES
209
210# A list of property assignments, like "key = value", with zero or more
211# whitespace characters on either side of the '='.
212# used for adding properties to default.prop of system partition
213_product_var_list += PRODUCT_SYSTEM_DEFAULT_PROPERTIES
214
215_product_var_list += PRODUCT_SYSTEM_PROPERTY_BLACKLIST
216_product_var_list += PRODUCT_VENDOR_PROPERTY_BLACKLIST
217_product_var_list += PRODUCT_SYSTEM_SERVER_APPS
218_product_var_list += PRODUCT_SYSTEM_SERVER_JARS
219
220# All of the apps that we force preopt, this overrides WITH_DEXPREOPT.
221_product_var_list += PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK
222_product_var_list += PRODUCT_DEXPREOPT_SPEED_APPS
223_product_var_list += PRODUCT_LOADED_BY_PRIVILEGED_MODULES
224_product_var_list += PRODUCT_VBOOT_SIGNING_KEY
225_product_var_list += PRODUCT_VBOOT_SIGNING_SUBKEY
226_product_var_list += PRODUCT_VERITY_SIGNING_KEY
227_product_var_list += PRODUCT_SYSTEM_VERITY_PARTITION
228_product_var_list += PRODUCT_VENDOR_VERITY_PARTITION
229_product_var_list += PRODUCT_PRODUCT_VERITY_PARTITION
230_product_var_list += PRODUCT_PRODUCT_SERVICES_VERITY_PARTITION
231_product_var_list += PRODUCT_ODM_VERITY_PARTITION
232_product_var_list += PRODUCT_SYSTEM_SERVER_DEBUG_INFO
233_product_var_list += PRODUCT_OTHER_JAVA_DEBUG_INFO
234
235# Per-module dex-preopt configs.
236_product_var_list += PRODUCT_DEX_PREOPT_MODULE_CONFIGS
237_product_var_list += PRODUCT_DEX_PREOPT_DEFAULT_COMPILER_FILTER
238_product_var_list += PRODUCT_DEX_PREOPT_DEFAULT_FLAGS
239_product_var_list += PRODUCT_DEX_PREOPT_BOOT_FLAGS
240_product_var_list += PRODUCT_DEX_PREOPT_PROFILE_DIR
241_product_var_list += PRODUCT_DEX_PREOPT_GENERATE_DM_FILES
242_product_var_list += PRODUCT_DEX_PREOPT_NEVER_ALLOW_STRIPPING
243
244# Boot image options.
245_product_var_list += \
Mathieu Chartiera61acf62017-06-28 18:23:37 -0700246 PRODUCT_USE_PROFILE_FOR_BOOT_IMAGE \
Anton Hansson13ea2a62019-03-28 14:47:25 +0000247 PRODUCT_DEX_PREOPT_BOOT_IMAGE_PROFILE_LOCATION \
248
249_product_var_list += PRODUCT_SYSTEM_SERVER_COMPILER_FILTER
250# Per-module sanitizer configs
251_product_var_list += PRODUCT_SANITIZER_MODULE_CONFIGS
252_product_var_list += PRODUCT_SYSTEM_BASE_FS_PATH
253_product_var_list += PRODUCT_VENDOR_BASE_FS_PATH
254_product_var_list += PRODUCT_PRODUCT_BASE_FS_PATH
255_product_var_list += PRODUCT_PRODUCT_SERVICES_BASE_FS_PATH
256_product_var_list += PRODUCT_ODM_BASE_FS_PATH
257_product_var_list += PRODUCT_SHIPPING_API_LEVEL
258_product_var_list += VENDOR_PRODUCT_RESTRICT_VENDOR_FILES
259_product_var_list += VENDOR_EXCEPTION_MODULES
260_product_var_list += VENDOR_EXCEPTION_PATHS
261
262# Whether the product wants to ship libartd. For rules and meaning, see art/Android.mk.
263_product_var_list += PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD
264
265# Make this art variable visible to soong_config.mk.
266_product_var_list += PRODUCT_ART_USE_READ_BARRIER
267
268# Whether the product is an Android Things variant.
269_product_var_list += PRODUCT_IOT
270
271# Add reserved headroom to a system image.
272_product_var_list += PRODUCT_SYSTEM_HEADROOM
273
274# Whether to save disk space by minimizing java debug info
275_product_var_list += PRODUCT_MINIMIZE_JAVA_DEBUG_INFO
276
277# Whether any paths are excluded from sanitization when SANITIZE_TARGET=integer_overflow
278_product_var_list += PRODUCT_INTEGER_OVERFLOW_EXCLUDE_PATHS
279
280_product_var_list += PRODUCT_ADB_KEYS
281
282# Whether any paths should have CFI enabled for components
283_product_var_list += PRODUCT_CFI_INCLUDE_PATHS
284
285# Whether any paths are excluded from sanitization when SANITIZE_TARGET=cfi
286_product_var_list += PRODUCT_CFI_EXCLUDE_PATHS
287
288# Whether the Scudo hardened allocator is disabled platform-wide
289_product_var_list += PRODUCT_DISABLE_SCUDO
290
291# A flag to override PRODUCT_COMPATIBLE_PROPERTY
292_product_var_list += PRODUCT_COMPATIBLE_PROPERTY_OVERRIDE
293
294# Whether the whitelist of actionable compatible properties should be disabled or not
295_product_var_list += PRODUCT_ACTIONABLE_COMPATIBLE_PROPERTY_DISABLE
296_product_var_list += PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS
297_product_var_list += PRODUCT_ENFORCE_ARTIFACT_SYSTEM_CERTIFICATE_REQUIREMENT
298_product_var_list += PRODUCT_ARTIFACT_SYSTEM_CERTIFICATE_REQUIREMENT_WHITELIST
299_product_var_list += PRODUCT_ARTIFACT_PATH_REQUIREMENT_HINT
300_product_var_list += PRODUCT_ARTIFACT_PATH_REQUIREMENT_WHITELIST
301
302# List of modules that should be forcefully unmarked from being LOCAL_PRODUCT_MODULE, and hence
303# installed on /system directory by default.
304_product_var_list += PRODUCT_FORCE_PRODUCT_MODULES_TO_SYSTEM_PARTITION
305
306# When this is true, dynamic partitions is retrofitted on a device that has
307# already been launched without dynamic partitions. Otherwise, the device
308# is launched with dynamic partitions.
309# This flag implies PRODUCT_USE_DYNAMIC_PARTITIONS.
310_product_var_list += PRODUCT_RETROFIT_DYNAMIC_PARTITIONS
311
312# Other dynamic partition feature flags.PRODUCT_USE_DYNAMIC_PARTITION_SIZE and
313# PRODUCT_BUILD_SUPER_PARTITION default to the value of PRODUCT_USE_DYNAMIC_PARTITIONS.
314_product_var_list += \
315 PRODUCT_USE_DYNAMIC_PARTITIONS \
Yifan Hong2dae5722018-07-31 12:47:27 -0700316 PRODUCT_USE_DYNAMIC_PARTITION_SIZE \
317 PRODUCT_BUILD_SUPER_PARTITION \
Anton Hansson13ea2a62019-03-28 14:47:25 +0000318
319# If set, kernel configuration requirements are present in OTA package (and will be enforced
320# during OTA). Otherwise, kernel configuration requirements are enforced in VTS.
321# Devices that checks the running kernel (instead of the kernel in OTA package) should not
322# set this variable to prevent OTA failures.
323_product_var_list += PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS
324
Tao Bao9be20c72019-04-08 21:11:59 -0700325# If set to true, this product builds a generic OTA package, which installs generic system images
326# onto matching devices. The product may only build a subset of system images (e.g. only
327# system.img), so devices need to install the package in a system-only OTA manner.
328_product_var_list += PRODUCT_BUILD_GENERIC_OTA_PACKAGE
329
Anton Hansson13ea2a62019-03-28 14:47:25 +0000330# Whether any paths are excluded from being set XOM when ENABLE_XOM=true
331_product_var_list += PRODUCT_XOM_EXCLUDE_PATHS
332_product_var_list += PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES
333_product_var_list += PRODUCT_PACKAGE_NAME_OVERRIDES
334_product_var_list += PRODUCT_CERTIFICATE_OVERRIDES
335_product_var_list += PRODUCT_BUILD_SYSTEM_IMAGE
336_product_var_list += PRODUCT_BUILD_SYSTEM_OTHER_IMAGE
337_product_var_list += PRODUCT_BUILD_VENDOR_IMAGE
338_product_var_list += PRODUCT_BUILD_PRODUCT_IMAGE
339_product_var_list += PRODUCT_BUILD_PRODUCT_SERVICES_IMAGE
340_product_var_list += PRODUCT_BUILD_ODM_IMAGE
341_product_var_list += PRODUCT_BUILD_CACHE_IMAGE
342_product_var_list += PRODUCT_BUILD_RAMDISK_IMAGE
343_product_var_list += PRODUCT_BUILD_USERDATA_IMAGE
344_product_var_list += PRODUCT_UPDATABLE_BOOT_MODULES
345_product_var_list += PRODUCT_UPDATABLE_BOOT_LOCATIONS
346
347# Whether the product would like to check prebuilt ELF files.
348_product_var_list += PRODUCT_CHECK_ELF_FILES
349.KATI_READONLY := _product_var_list
Ying Wang20ebd2e2014-10-07 18:07:23 -0700350
The Android Open Source Project88b60792009-03-03 19:28:42 -0800351define dump-product
Anton Hanssondce3f922019-02-11 21:19:54 +0000352$(warning ==== $(1) ====)\
The Android Open Source Project88b60792009-03-03 19:28:42 -0800353$(foreach v,$(_product_var_list),\
Anton Hanssondce3f922019-02-11 21:19:54 +0000354$(warning PRODUCTS.$(1).$(v) := $(PRODUCTS.$(1).$(v))))\
355$(warning --------)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800356endef
357
358define dump-products
359$(foreach p,$(PRODUCTS),$(call dump-product,$(p)))
360endef
361
362#
Anton Hansson13ea2a62019-03-28 14:47:25 +0000363# Functions for including product makefiles
364#
365
366#
The Android Open Source Project88b60792009-03-03 19:28:42 -0800367# $(1): product to inherit
368#
Anton Hansson061cbcf2018-05-30 18:24:41 +0100369# To be called from product makefiles, and is later evaluated during the import-nodes
370# call below. It does three things:
The Android Open Source Project6a5f7f02009-03-05 14:34:30 -0800371# 1. Inherits all of the variables from $1.
372# 2. Records the inheritance in the .INHERITS_FROM variable
Anton Hansson061cbcf2018-05-30 18:24:41 +0100373# 3. Records the calling makefile in PARENT_PRODUCT_FILES
374#
375# (2) and (3) can be used together to reconstruct the include hierarchy
376# See e.g. product-graph.mk for an example of this.
The Android Open Source Project6a5f7f02009-03-05 14:34:30 -0800377#
The Android Open Source Project88b60792009-03-03 19:28:42 -0800378define inherit-product
Ying Wanga1742612015-10-28 14:33:40 -0700379 $(if $(findstring ../,$(1)),\
380 $(eval np := $(call normalize-paths,$(1))),\
381 $(eval np := $(strip $(1))))\
The Android Open Source Project88b60792009-03-03 19:28:42 -0800382 $(foreach v,$(_product_var_list), \
Ying Wanga1742612015-10-28 14:33:40 -0700383 $(eval $(v) := $($(v)) $(INHERIT_TAG)$(np))) \
Anton Hansson061cbcf2018-05-30 18:24:41 +0100384 $(eval current_mk := $(strip $(word 1,$(_include_stack)))) \
385 $(eval inherit_var := PRODUCTS.$(current_mk).INHERITS_FROM) \
Ying Wanga1742612015-10-28 14:33:40 -0700386 $(eval $(inherit_var) := $(sort $($(inherit_var)) $(np))) \
Anton Hansson061cbcf2018-05-30 18:24:41 +0100387 $(eval PARENT_PRODUCT_FILES := $(sort $(PARENT_PRODUCT_FILES) $(current_mk)))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800388endef
389
Anton Hansson837425b2018-06-01 14:18:14 +0100390# Specifies a number of path prefixes, relative to PRODUCT_OUT, where the
391# product makefile hierarchy rooted in the current node places its artifacts.
392# Creating artifacts outside the specified paths will cause a build-time error.
393define require-artifacts-in-path
394 $(eval current_mk := $(strip $(word 1,$(_include_stack)))) \
395 $(eval PRODUCTS.$(current_mk).ARTIFACT_PATH_REQUIREMENTS := $(strip $(1))) \
396 $(eval PRODUCTS.$(current_mk).ARTIFACT_PATH_WHITELIST := $(strip $(2))) \
397 $(eval ARTIFACT_PATH_REQUIREMENT_PRODUCTS := \
398 $(sort $(ARTIFACT_PATH_REQUIREMENT_PRODUCTS) $(current_mk)))
399endef
Joe Onorato28a846d2010-02-22 10:33:05 -0800400
Anton Hansson1ebcbd52018-07-04 17:17:23 +0100401# Makes including non-existant modules in PRODUCT_PACKAGES an error.
402# $(1): whitelist of non-existant modules to allow.
403define enforce-product-packages-exist
404 $(eval current_mk := $(strip $(word 1,$(_include_stack)))) \
405 $(eval PRODUCTS.$(current_mk).PRODUCT_ENFORCE_PACKAGES_EXIST := true) \
406 $(eval PRODUCTS.$(current_mk).PRODUCT_ENFORCE_PACKAGES_EXIST_WHITELIST := $(1)) \
407 $(eval .KATI_READONLY := PRODUCTS.$(current_mk).PRODUCT_ENFORCE_PACKAGES_EXIST) \
408 $(eval .KATI_READONLY := PRODUCTS.$(current_mk).PRODUCT_ENFORCE_PACKAGES_EXIST_WHITELIST)
409endef
410
Joe Onorato28a846d2010-02-22 10:33:05 -0800411#
412# Do inherit-product only if $(1) exists
413#
414define inherit-product-if-exists
415 $(if $(wildcard $(1)),$(call inherit-product,$(1)),)
416endef
417
The Android Open Source Project88b60792009-03-03 19:28:42 -0800418#
419# $(1): product makefile list
420#
421#TODO: check to make sure that products have all the necessary vars defined
422define import-products
423$(call import-nodes,PRODUCTS,$(1),$(_product_var_list))
424endef
425
426
427#
428# Does various consistency checks on all of the known products.
429# Takes no parameters, so $(call ) is not necessary.
430#
431define check-all-products
432$(if ,, \
433 $(eval _cap_names :=) \
434 $(foreach p,$(PRODUCTS), \
435 $(eval pn := $(strip $(PRODUCTS.$(p).PRODUCT_NAME))) \
436 $(if $(pn),,$(error $(p): PRODUCT_NAME must be defined.)) \
437 $(if $(filter $(pn),$(_cap_names)), \
438 $(error $(p): PRODUCT_NAME must be unique; "$(pn)" already used by $(strip \
439 $(foreach \
440 pp,$(PRODUCTS),
441 $(if $(filter $(pn),$(PRODUCTS.$(pp).PRODUCT_NAME)), \
442 $(pp) \
443 ))) \
444 ) \
445 ) \
446 $(eval _cap_names += $(pn)) \
447 $(if $(call is-c-identifier,$(pn)),, \
448 $(error $(p): PRODUCT_NAME must be a valid C identifier, not "$(pn)") \
449 ) \
450 $(eval pb := $(strip $(PRODUCTS.$(p).PRODUCT_BRAND))) \
451 $(if $(pb),,$(error $(p): PRODUCT_BRAND must be defined.)) \
452 $(foreach cf,$(strip $(PRODUCTS.$(p).PRODUCT_COPY_FILES)), \
Ying Wang4b0486b2012-09-20 16:35:36 -0700453 $(if $(filter 2 3,$(words $(subst :,$(space),$(cf)))),, \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800454 $(error $(p): malformed COPY_FILE "$(cf)") \
455 ) \
456 ) \
457 ) \
458)
459endef
460
461
462#
463# Returns the product makefile path for the product with the provided name
464#
465# $(1): short product name like "generic"
466#
467define _resolve-short-product-name
468 $(eval pn := $(strip $(1)))
469 $(eval p := \
470 $(foreach p,$(PRODUCTS), \
471 $(if $(filter $(pn),$(PRODUCTS.$(p).PRODUCT_NAME)), \
472 $(p) \
473 )) \
474 )
475 $(eval p := $(sort $(p)))
476 $(if $(filter 1,$(words $(p))), \
477 $(p), \
478 $(if $(filter 0,$(words $(p))), \
479 $(error No matches for product "$(pn)"), \
480 $(error Product "$(pn)" ambiguous: matches $(p)) \
481 ) \
482 )
483endef
484define resolve-short-product-name
485$(strip $(call _resolve-short-product-name,$(1)))
486endef
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400487
Anton Hansson13ea2a62019-03-28 14:47:25 +0000488# BoardConfig variables that are also inherited in product mks. Should ideally
489# be cleaned up to not be product variables.
490_readonly_late_variables := \
491 DEVICE_PACKAGE_OVERLAYS \
492 WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY \
493
494# Modified internally in the build system
495_readonly_late_variables += \
496 PRODUCT_COPY_FILES \
497 PRODUCT_DEX_PREOPT_NEVER_ALLOW_STRIPPING \
498 PRODUCT_DEX_PREOPT_BOOT_FLAGS \
499
500_readonly_early_variables := $(filter-out $(_readonly_late_variables),$(_product_var_list))
Yifan Honge5d879a2018-11-27 11:37:38 -0800501
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400502#
Dan Willemsenc1f17ff2016-10-05 16:57:27 -0700503# Mark the variables in _product_stash_var_list as readonly
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400504#
Anton Hansson13ea2a62019-03-28 14:47:25 +0000505define readonly-variables
506$(foreach v,$(1), \
Anton Hansson70222b22019-02-21 10:41:03 +0000507 $(eval $(v) ?=) \
508 $(eval .KATI_READONLY := $(v)) \
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400509 )
510endef
Anton Hansson13ea2a62019-03-28 14:47:25 +0000511define readonly-product-vars
512$(call readonly-variables,$(_readonly_early_variables))
513endef
514
515define readonly-final-product-vars
516$(call readonly-variables,$(_readonly_late_variables))
517endef
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400518
Yifan Honge5d879a2018-11-27 11:37:38 -0800519#
520# Strip the variables in _product_strip_var_list
521#
522define strip-product-vars
Anton Hansson13ea2a62019-03-28 14:47:25 +0000523$(foreach v,$(_product_var_list), \
524 $(eval $(v) := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).$(v)))) \
525)
Yifan Honge5d879a2018-11-27 11:37:38 -0800526endef
527
Keun young Parkc41c5f42012-05-30 10:22:29 -0700528define add-to-product-copy-files-if-exists
529$(if $(wildcard $(word 1,$(subst :, ,$(1)))),$(1))
530endef
Ying Wang20ebd2e2014-10-07 18:07:23 -0700531
532# whitespace placeholder when we record module's dex-preopt config.
533_PDPMC_SP_PLACE_HOLDER := |@SP@|
534# Set up dex-preopt config for a module.
535# $(1) list of module names
536# $(2) the modules' dex-preopt config
537define add-product-dex-preopt-module-config
538$(eval _c := $(subst $(space),$(_PDPMC_SP_PLACE_HOLDER),$(strip $(2))))\
539$(eval PRODUCT_DEX_PREOPT_MODULE_CONFIGS += \
540 $(foreach m,$(1),$(m)=$(_c)))
541endef
Andreas Gampe6b30d772016-06-27 15:15:31 -0700542
543# whitespace placeholder when we record module's sanitizer config.
544_PSMC_SP_PLACE_HOLDER := |@SP@|
545# Set up sanitizer config for a module.
546# $(1) list of module names
547# $(2) the modules' sanitizer config
548define add-product-sanitizer-module-config
549$(eval _c := $(subst $(space),$(_PSMC_SP_PLACE_HOLDER),$(strip $(2))))\
550$(eval PRODUCT_SANITIZER_MODULE_CONFIGS += \
551 $(foreach m,$(1),$(m)=$(_c)))
552endef