blob: bb63ab8288b8573f30080d39eff52c6a45bcd28b [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
109#
The Android Open Source Project88b60792009-03-03 19:28:42 -0800110# Functions for including product makefiles
111#
112
113_product_var_list := \
114 PRODUCT_NAME \
115 PRODUCT_MODEL \
116 PRODUCT_LOCALES \
Ying Wang4f1ab922011-03-15 13:19:30 -0700117 PRODUCT_AAPT_CONFIG \
Dianne Hackborna0f464a2011-10-14 19:37:57 -0700118 PRODUCT_AAPT_PREF_CONFIG \
Ying Wang60686582014-12-10 12:40:09 -0800119 PRODUCT_AAPT_PREBUILT_DPI \
Dan Willemsen3d05a082019-02-22 23:06:03 +0000120 PRODUCT_HOST_PACKAGES \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800121 PRODUCT_PACKAGES \
Joe Onoratod7d0afc2012-06-05 15:54:09 -0700122 PRODUCT_PACKAGES_DEBUG \
Zach Riggle9323b7f2018-03-26 16:17:03 -0500123 PRODUCT_PACKAGES_DEBUG_ASAN \
Joe Onoratod7d0afc2012-06-05 15:54:09 -0700124 PRODUCT_PACKAGES_ENG \
125 PRODUCT_PACKAGES_TESTS \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800126 PRODUCT_DEVICE \
127 PRODUCT_MANUFACTURER \
128 PRODUCT_BRAND \
Anton Hanssonee4c9702018-12-21 15:36:00 +0000129 PRODUCT_SYSTEM_NAME \
130 PRODUCT_SYSTEM_MODEL \
131 PRODUCT_SYSTEM_DEVICE \
132 PRODUCT_SYSTEM_BRAND \
133 PRODUCT_SYSTEM_MANUFACTURER \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800134 PRODUCT_PROPERTY_OVERRIDES \
Mike Lockwood0d23fec2011-06-09 14:54:40 -0700135 PRODUCT_DEFAULT_PROPERTY_OVERRIDES \
Jaekyun Seokb7735d82017-11-27 17:04:47 +0900136 PRODUCT_PRODUCT_PROPERTIES \
Dario Freni5f681e12018-05-29 13:09:01 +0100137 PRODUCT_PRODUCT_SERVICES_PROPERTIES \
Bowgo Tsaid624fa62017-11-14 23:42:30 +0800138 PRODUCT_ODM_PROPERTIES \
Joe Onorato700b88e2010-10-05 17:33:58 -0400139 PRODUCT_CHARACTERISTICS \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800140 PRODUCT_COPY_FILES \
141 PRODUCT_OTA_PUBLIC_KEYS \
Doug Zongker5d4808d2011-03-16 07:49:13 -0700142 PRODUCT_EXTRA_RECOVERY_KEYS \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800143 PRODUCT_PACKAGE_OVERLAYS \
144 DEVICE_PACKAGE_OVERLAYS \
Jaekyun Seokccee95e2017-09-01 17:23:25 +0900145 PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS \
Jaekyun Seok1b224282017-03-30 11:25:02 +0900146 PRODUCT_ENFORCE_RRO_TARGETS \
Ying Wang780128a2014-01-29 13:35:55 -0800147 PRODUCT_SDK_ATREE_FILES \
Joe Onorato214a42b2009-04-09 20:36:06 -0700148 PRODUCT_SDK_ADDON_NAME \
149 PRODUCT_SDK_ADDON_COPY_FILES \
150 PRODUCT_SDK_ADDON_COPY_MODULES \
Ying Wanga032d3d2011-11-11 10:52:12 -0800151 PRODUCT_SDK_ADDON_DOC_MODULES \
Raphael Moll0d7d09a2014-08-21 15:22:08 -0700152 PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP \
Jeff Gaston1fe28d32017-11-21 15:05:07 -0800153 PRODUCT_SOONG_NAMESPACES \
Ying Wang3c21fe52011-10-04 10:50:08 -0700154 PRODUCT_DEFAULT_WIFI_CHANNELS \
155 PRODUCT_DEFAULT_DEV_CERTIFICATE \
Ying Wangdbb31be2011-12-09 15:11:57 -0800156 PRODUCT_RESTRICT_VENDOR_FILES \
Dima Zavinf9269902012-03-16 09:57:11 -0700157 PRODUCT_VENDOR_KERNEL_HEADERS \
Geremy Condrafd6f7512013-06-16 17:26:08 -0700158 PRODUCT_BOOT_JARS \
Sami Tolvanen8b3f08b2015-04-07 15:08:59 +0100159 PRODUCT_SUPPORTS_BOOT_SIGNER \
David Riley17be3d32015-03-03 08:54:11 -0800160 PRODUCT_SUPPORTS_VBOOT \
Geremy Condrafd6f7512013-06-16 17:26:08 -0700161 PRODUCT_SUPPORTS_VERITY \
Sami Tolvanenf99b5312015-05-20 07:30:57 +0100162 PRODUCT_SUPPORTS_VERITY_FEC \
Jeff Sharkey26d22f72014-03-18 17:20:10 -0700163 PRODUCT_OEM_PROPERTIES \
Jaekyun Seokb31b9ba2017-11-03 15:18:55 +0900164 PRODUCT_SYSTEM_DEFAULT_PROPERTIES \
Jeff Sharkey26d22f72014-03-18 17:20:10 -0700165 PRODUCT_SYSTEM_PROPERTY_BLACKLIST \
Ivan Podogovd5726322018-03-29 15:22:33 +0100166 PRODUCT_VENDOR_PROPERTY_BLACKLIST \
Nicolas Geoffrayb08ada12017-03-22 12:36:05 +0000167 PRODUCT_SYSTEM_SERVER_APPS \
Narayan Kamath89ec4962014-08-05 14:51:08 +0100168 PRODUCT_SYSTEM_SERVER_JARS \
Mathieu Chartier55eabd52017-09-15 13:40:48 -0700169 PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK \
Nicolas Geoffray4a0ad4a2017-06-12 15:19:16 +0100170 PRODUCT_DEXPREOPT_SPEED_APPS \
Nicolas Geoffraya95fbd12017-09-19 13:10:31 +0100171 PRODUCT_LOADED_BY_PRIVILEGED_MODULES \
David Riley17be3d32015-03-03 08:54:11 -0800172 PRODUCT_VBOOT_SIGNING_KEY \
Furquan Shaikhe8c21222015-08-07 11:58:05 -0700173 PRODUCT_VBOOT_SIGNING_SUBKEY \
Geremy Condra5b5f4952014-05-05 22:19:37 -0700174 PRODUCT_VERITY_SIGNING_KEY \
Daniel Rosenbergf4eabc32014-07-10 15:42:38 -0700175 PRODUCT_SYSTEM_VERITY_PARTITION \
Ying Wang87557562014-10-09 19:29:53 -0700176 PRODUCT_VENDOR_VERITY_PARTITION \
Jaekyun Seokb7735d82017-11-27 17:04:47 +0900177 PRODUCT_PRODUCT_VERITY_PARTITION \
Dario Freni5f681e12018-05-29 13:09:01 +0100178 PRODUCT_PRODUCT_SERVICES_VERITY_PARTITION \
Bowgo Tsaid624fa62017-11-14 23:42:30 +0800179 PRODUCT_ODM_VERITY_PARTITION \
Mathieu Chartierf0db9082017-06-23 14:47:56 -0700180 PRODUCT_SYSTEM_SERVER_DEBUG_INFO \
Andreas Gampec3e15192018-03-19 14:28:15 -0700181 PRODUCT_OTHER_JAVA_DEBUG_INFO \
Ying Wang20ebd2e2014-10-07 18:07:23 -0700182 PRODUCT_DEX_PREOPT_MODULE_CONFIGS \
Mathieu Chartiere8fb7cf2018-02-15 13:19:38 -0800183 PRODUCT_DEX_PREOPT_DEFAULT_COMPILER_FILTER \
Ying Wang20ebd2e2014-10-07 18:07:23 -0700184 PRODUCT_DEX_PREOPT_DEFAULT_FLAGS \
185 PRODUCT_DEX_PREOPT_BOOT_FLAGS \
Mathieu Chartierfcc8d8b2017-05-05 17:22:37 -0700186 PRODUCT_DEX_PREOPT_PROFILE_DIR \
Mathieu Chartiera61acf62017-06-28 18:23:37 -0700187 PRODUCT_DEX_PREOPT_BOOT_IMAGE_PROFILE_LOCATION \
Mathieu Chartier5c658ac2018-02-15 13:19:38 -0800188 PRODUCT_DEX_PREOPT_GENERATE_DM_FILES \
Nicolas Geoffray98f5e862019-02-12 13:12:47 +0000189 PRODUCT_DEX_PREOPT_NEVER_ALLOW_STRIPPING \
Mathieu Chartiera61acf62017-06-28 18:23:37 -0700190 PRODUCT_USE_PROFILE_FOR_BOOT_IMAGE \
Mathieu Chartier6228ec22017-06-23 10:44:45 -0700191 PRODUCT_SYSTEM_SERVER_COMPILER_FILTER \
Andreas Gampe6b30d772016-06-27 15:15:31 -0700192 PRODUCT_SANITIZER_MODULE_CONFIGS \
Mohamad Ayyash1868a602016-04-22 17:22:07 -0700193 PRODUCT_SYSTEM_BASE_FS_PATH \
194 PRODUCT_VENDOR_BASE_FS_PATH \
Jaekyun Seokb7735d82017-11-27 17:04:47 +0900195 PRODUCT_PRODUCT_BASE_FS_PATH \
Dario Freni5f681e12018-05-29 13:09:01 +0100196 PRODUCT_PRODUCT_SERVICES_BASE_FS_PATH \
Bowgo Tsaid624fa62017-11-14 23:42:30 +0800197 PRODUCT_ODM_BASE_FS_PATH \
Gustav Sennton81ee1862016-05-27 14:07:54 +0100198 PRODUCT_SHIPPING_API_LEVEL \
Hung-ying Tyan3c054d82016-05-20 19:08:30 +0800199 VENDOR_PRODUCT_RESTRICT_VENDOR_FILES \
200 VENDOR_EXCEPTION_MODULES \
201 VENDOR_EXCEPTION_PATHS \
Andreas Gampe831fc712017-06-30 11:36:26 -0700202 PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD \
Hiroshi Yamauchi64594c42016-12-15 16:00:41 -0800203 PRODUCT_ART_USE_READ_BARRIER \
Alex Deymo8fe63c32017-03-02 22:08:41 -0800204 PRODUCT_IOT \
Julius D'souza001c6762017-05-03 13:43:27 -0700205 PRODUCT_SYSTEM_HEADROOM \
Przemyslaw Szczepaniak2e81b3c2017-06-30 14:51:12 +0100206 PRODUCT_MINIMIZE_JAVA_DEBUG_INFO \
Ivan Lozano9a82bfd2017-07-13 14:49:12 -0700207 PRODUCT_INTEGER_OVERFLOW_EXCLUDE_PATHS \
Dan Willemsen0bd79382017-11-03 15:53:52 -0700208 PRODUCT_ADB_KEYS \
Vishwath Mohan23b2d2e2017-10-31 02:25:16 -0700209 PRODUCT_CFI_INCLUDE_PATHS \
210 PRODUCT_CFI_EXCLUDE_PATHS \
Kostya Kortchinsky02732402019-02-01 09:06:42 -0800211 PRODUCT_DISABLE_SCUDO \
Jaekyun Seok0538ff72018-01-16 14:14:59 +0900212 PRODUCT_COMPATIBLE_PROPERTY_OVERRIDE \
213 PRODUCT_ACTIONABLE_COMPATIBLE_PROPERTY_DISABLE \
Anton Hansson427d8552018-06-05 17:53:09 +0100214 PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS \
Jeongik Chab2c4bb72018-12-17 14:45:15 +0900215 PRODUCT_ENFORCE_ARTIFACT_SYSTEM_CERTIFICATE_REQUIREMENT \
216 PRODUCT_ARTIFACT_SYSTEM_CERTIFICATE_REQUIREMENT_WHITELIST \
Anton Hansson83ba31c2018-10-12 16:15:49 +0100217 PRODUCT_ARTIFACT_PATH_REQUIREMENT_HINT \
Anton Hansson427d8552018-06-05 17:53:09 +0100218 PRODUCT_ARTIFACT_PATH_REQUIREMENT_WHITELIST \
Yifan Hong2dae5722018-07-31 12:47:27 -0700219 PRODUCT_USE_DYNAMIC_PARTITION_SIZE \
220 PRODUCT_BUILD_SUPER_PARTITION \
Dario Frenif31bc452018-07-12 19:44:33 +0100221 PRODUCT_FORCE_PRODUCT_MODULES_TO_SYSTEM_PARTITION \
Yifan Hongc5c01242018-11-09 10:27:23 -0800222 PRODUCT_USE_DYNAMIC_PARTITIONS \
David Anderson619fe2d2018-10-30 18:47:59 -0700223 PRODUCT_RETROFIT_DYNAMIC_PARTITIONS \
Yifan Hong452d9262018-11-07 16:46:45 -0800224 PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS \
Ivan Lozanofda9a6f2018-11-21 09:04:18 -0800225 PRODUCT_XOM_EXCLUDE_PATHS \
Jiyong Park185d41e2019-01-05 12:57:54 +0900226 PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES \
Jaewoong Jung7dfae502019-01-28 16:19:33 -0800227 PRODUCT_PACKAGE_NAME_OVERRIDES \
228 PRODUCT_CERTIFICATE_OVERRIDES \
Dan Willemsen67495202019-01-16 12:42:05 -0800229 PRODUCT_BUILD_SYSTEM_IMAGE \
230 PRODUCT_BUILD_SYSTEM_OTHER_IMAGE \
231 PRODUCT_BUILD_VENDOR_IMAGE \
232 PRODUCT_BUILD_PRODUCT_IMAGE \
233 PRODUCT_BUILD_PRODUCT_SERVICES_IMAGE \
234 PRODUCT_BUILD_ODM_IMAGE \
235 PRODUCT_BUILD_CACHE_IMAGE \
236 PRODUCT_BUILD_RAMDISK_IMAGE \
237 PRODUCT_BUILD_USERDATA_IMAGE \
Dongwon Kang167758a2019-01-18 08:26:30 -0800238 PRODUCT_UPDATABLE_BOOT_MODULES \
239 PRODUCT_UPDATABLE_BOOT_LOCATIONS \
Logan Chien0e53d882018-11-06 17:32:40 +0800240 PRODUCT_CHECK_ELF_FILES \
Ying Wang20ebd2e2014-10-07 18:07:23 -0700241
The Android Open Source Project88b60792009-03-03 19:28:42 -0800242define dump-product
Anton Hanssondce3f922019-02-11 21:19:54 +0000243$(warning ==== $(1) ====)\
The Android Open Source Project88b60792009-03-03 19:28:42 -0800244$(foreach v,$(_product_var_list),\
Anton Hanssondce3f922019-02-11 21:19:54 +0000245$(warning PRODUCTS.$(1).$(v) := $(PRODUCTS.$(1).$(v))))\
246$(warning --------)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800247endef
248
249define dump-products
250$(foreach p,$(PRODUCTS),$(call dump-product,$(p)))
251endef
252
253#
254# $(1): product to inherit
255#
Anton Hansson061cbcf2018-05-30 18:24:41 +0100256# To be called from product makefiles, and is later evaluated during the import-nodes
257# call below. It does three things:
The Android Open Source Project6a5f7f02009-03-05 14:34:30 -0800258# 1. Inherits all of the variables from $1.
259# 2. Records the inheritance in the .INHERITS_FROM variable
Anton Hansson061cbcf2018-05-30 18:24:41 +0100260# 3. Records the calling makefile in PARENT_PRODUCT_FILES
261#
262# (2) and (3) can be used together to reconstruct the include hierarchy
263# See e.g. product-graph.mk for an example of this.
The Android Open Source Project6a5f7f02009-03-05 14:34:30 -0800264#
The Android Open Source Project88b60792009-03-03 19:28:42 -0800265define inherit-product
Ying Wanga1742612015-10-28 14:33:40 -0700266 $(if $(findstring ../,$(1)),\
267 $(eval np := $(call normalize-paths,$(1))),\
268 $(eval np := $(strip $(1))))\
The Android Open Source Project88b60792009-03-03 19:28:42 -0800269 $(foreach v,$(_product_var_list), \
Ying Wanga1742612015-10-28 14:33:40 -0700270 $(eval $(v) := $($(v)) $(INHERIT_TAG)$(np))) \
Anton Hansson061cbcf2018-05-30 18:24:41 +0100271 $(eval current_mk := $(strip $(word 1,$(_include_stack)))) \
272 $(eval inherit_var := PRODUCTS.$(current_mk).INHERITS_FROM) \
Ying Wanga1742612015-10-28 14:33:40 -0700273 $(eval $(inherit_var) := $(sort $($(inherit_var)) $(np))) \
Anton Hansson061cbcf2018-05-30 18:24:41 +0100274 $(eval PARENT_PRODUCT_FILES := $(sort $(PARENT_PRODUCT_FILES) $(current_mk)))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800275endef
276
Anton Hansson837425b2018-06-01 14:18:14 +0100277# Specifies a number of path prefixes, relative to PRODUCT_OUT, where the
278# product makefile hierarchy rooted in the current node places its artifacts.
279# Creating artifacts outside the specified paths will cause a build-time error.
280define require-artifacts-in-path
281 $(eval current_mk := $(strip $(word 1,$(_include_stack)))) \
282 $(eval PRODUCTS.$(current_mk).ARTIFACT_PATH_REQUIREMENTS := $(strip $(1))) \
283 $(eval PRODUCTS.$(current_mk).ARTIFACT_PATH_WHITELIST := $(strip $(2))) \
284 $(eval ARTIFACT_PATH_REQUIREMENT_PRODUCTS := \
285 $(sort $(ARTIFACT_PATH_REQUIREMENT_PRODUCTS) $(current_mk)))
286endef
Joe Onorato28a846d2010-02-22 10:33:05 -0800287
Anton Hansson1ebcbd52018-07-04 17:17:23 +0100288# Makes including non-existant modules in PRODUCT_PACKAGES an error.
289# $(1): whitelist of non-existant modules to allow.
290define enforce-product-packages-exist
291 $(eval current_mk := $(strip $(word 1,$(_include_stack)))) \
292 $(eval PRODUCTS.$(current_mk).PRODUCT_ENFORCE_PACKAGES_EXIST := true) \
293 $(eval PRODUCTS.$(current_mk).PRODUCT_ENFORCE_PACKAGES_EXIST_WHITELIST := $(1)) \
294 $(eval .KATI_READONLY := PRODUCTS.$(current_mk).PRODUCT_ENFORCE_PACKAGES_EXIST) \
295 $(eval .KATI_READONLY := PRODUCTS.$(current_mk).PRODUCT_ENFORCE_PACKAGES_EXIST_WHITELIST)
296endef
297
Joe Onorato28a846d2010-02-22 10:33:05 -0800298#
299# Do inherit-product only if $(1) exists
300#
301define inherit-product-if-exists
302 $(if $(wildcard $(1)),$(call inherit-product,$(1)),)
303endef
304
The Android Open Source Project88b60792009-03-03 19:28:42 -0800305#
306# $(1): product makefile list
307#
308#TODO: check to make sure that products have all the necessary vars defined
309define import-products
310$(call import-nodes,PRODUCTS,$(1),$(_product_var_list))
311endef
312
313
314#
315# Does various consistency checks on all of the known products.
316# Takes no parameters, so $(call ) is not necessary.
317#
318define check-all-products
319$(if ,, \
320 $(eval _cap_names :=) \
321 $(foreach p,$(PRODUCTS), \
322 $(eval pn := $(strip $(PRODUCTS.$(p).PRODUCT_NAME))) \
323 $(if $(pn),,$(error $(p): PRODUCT_NAME must be defined.)) \
324 $(if $(filter $(pn),$(_cap_names)), \
325 $(error $(p): PRODUCT_NAME must be unique; "$(pn)" already used by $(strip \
326 $(foreach \
327 pp,$(PRODUCTS),
328 $(if $(filter $(pn),$(PRODUCTS.$(pp).PRODUCT_NAME)), \
329 $(pp) \
330 ))) \
331 ) \
332 ) \
333 $(eval _cap_names += $(pn)) \
334 $(if $(call is-c-identifier,$(pn)),, \
335 $(error $(p): PRODUCT_NAME must be a valid C identifier, not "$(pn)") \
336 ) \
337 $(eval pb := $(strip $(PRODUCTS.$(p).PRODUCT_BRAND))) \
338 $(if $(pb),,$(error $(p): PRODUCT_BRAND must be defined.)) \
339 $(foreach cf,$(strip $(PRODUCTS.$(p).PRODUCT_COPY_FILES)), \
Ying Wang4b0486b2012-09-20 16:35:36 -0700340 $(if $(filter 2 3,$(words $(subst :,$(space),$(cf)))),, \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800341 $(error $(p): malformed COPY_FILE "$(cf)") \
342 ) \
343 ) \
344 ) \
345)
346endef
347
348
349#
350# Returns the product makefile path for the product with the provided name
351#
352# $(1): short product name like "generic"
353#
354define _resolve-short-product-name
355 $(eval pn := $(strip $(1)))
356 $(eval p := \
357 $(foreach p,$(PRODUCTS), \
358 $(if $(filter $(pn),$(PRODUCTS.$(p).PRODUCT_NAME)), \
359 $(p) \
360 )) \
361 )
362 $(eval p := $(sort $(p)))
363 $(if $(filter 1,$(words $(p))), \
364 $(p), \
365 $(if $(filter 0,$(words $(p))), \
366 $(error No matches for product "$(pn)"), \
367 $(error Product "$(pn)" ambiguous: matches $(p)) \
368 ) \
369 )
370endef
371define resolve-short-product-name
372$(strip $(call _resolve-short-product-name,$(1)))
373endef
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400374
Anton Hanssond488d2d2019-02-26 15:49:25 +0000375_product_stash_var_list := $(_product_var_list)
376# TODO: Move this to board_config.mk when no longer set in product makefiles
377_product_stash_var_list += WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY
378_product_strip_var_list :=
Yifan Honge5d879a2018-11-27 11:37:38 -0800379
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400380#
Dan Willemsenc1f17ff2016-10-05 16:57:27 -0700381# Mark the variables in _product_stash_var_list as readonly
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400382#
Dan Willemsenc1f17ff2016-10-05 16:57:27 -0700383define readonly-product-vars
Ying Wangf9953b42010-12-29 14:07:38 -0800384$(foreach v,$(_product_stash_var_list), \
Anton Hansson70222b22019-02-21 10:41:03 +0000385 $(eval $(v) ?=) \
386 $(eval .KATI_READONLY := $(v)) \
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400387 )
388endef
389
Yifan Honge5d879a2018-11-27 11:37:38 -0800390#
391# Strip the variables in _product_strip_var_list
392#
393define strip-product-vars
394$(foreach v,$(_product_strip_var_list),$(eval $(v) := $(strip $($(v)))))
395endef
396
Keun young Parkc41c5f42012-05-30 10:22:29 -0700397define add-to-product-copy-files-if-exists
398$(if $(wildcard $(word 1,$(subst :, ,$(1)))),$(1))
399endef
Ying Wang20ebd2e2014-10-07 18:07:23 -0700400
401# whitespace placeholder when we record module's dex-preopt config.
402_PDPMC_SP_PLACE_HOLDER := |@SP@|
403# Set up dex-preopt config for a module.
404# $(1) list of module names
405# $(2) the modules' dex-preopt config
406define add-product-dex-preopt-module-config
407$(eval _c := $(subst $(space),$(_PDPMC_SP_PLACE_HOLDER),$(strip $(2))))\
408$(eval PRODUCT_DEX_PREOPT_MODULE_CONFIGS += \
409 $(foreach m,$(1),$(m)=$(_c)))
410endef
Andreas Gampe6b30d772016-06-27 15:15:31 -0700411
412# whitespace placeholder when we record module's sanitizer config.
413_PSMC_SP_PLACE_HOLDER := |@SP@|
414# Set up sanitizer config for a module.
415# $(1) list of module names
416# $(2) the modules' sanitizer config
417define add-product-sanitizer-module-config
418$(eval _c := $(subst $(space),$(_PSMC_SP_PLACE_HOLDER),$(strip $(2))))\
419$(eval PRODUCT_SANITIZER_MODULE_CONFIGS += \
420 $(foreach m,$(1),$(m)=$(_c)))
421endef