2 # Copyright (C) 2007 The Android Open Source Project
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
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
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) \
32 -o -name AndroidProducts.mk -print))
36 # Returns the list of all AndroidProducts.mk files.
37 # $(call ) isn't necessary.
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
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.
49 define get-product-makefiles
52 $(eval PRODUCT_MAKEFILES :=) \
53 $(eval LOCAL_DIR := $(patsubst %/,%,$(dir $(f)))) \
54 $(eval include $(f)) \
55 $(PRODUCT_MAKEFILES) \
57 $(eval PRODUCT_MAKEFILES :=) \
58 $(eval LOCAL_DIR :=) \
63 # Returns the sorted concatenation of all PRODUCT_MAKEFILES
64 # variables set in all AndroidProducts.mk files.
65 # $(call ) isn't necessary.
67 define get-all-product-makefiles
68 $(call get-product-makefiles,$(_find-android-products-files))
72 # Functions for including product makefiles
75 _product_var_list := \
76 PRODUCT_BUILD_PROP_OVERRIDES \
81 PRODUCT_AAPT_PREF_CONFIG \
82 PRODUCT_AAPT_PREBUILT_DPI \
84 PRODUCT_PACKAGES_DEBUG \
85 PRODUCT_PACKAGES_ENG \
86 PRODUCT_PACKAGES_TESTS \
88 PRODUCT_MANUFACTURER \
90 PRODUCT_PROPERTY_OVERRIDES \
91 PRODUCT_DEFAULT_PROPERTY_OVERRIDES \
92 PRODUCT_CHARACTERISTICS \
94 PRODUCT_COPY_FILES_OVERRIDES \
95 PRODUCT_OTA_PUBLIC_KEYS \
96 PRODUCT_EXTRA_RECOVERY_KEYS \
97 PRODUCT_PACKAGE_OVERLAYS \
98 DEVICE_PACKAGE_OVERLAYS \
99 PRODUCT_SDK_ATREE_FILES \
100 PRODUCT_SDK_ADDON_NAME \
101 PRODUCT_SDK_ADDON_COPY_FILES \
102 PRODUCT_SDK_ADDON_COPY_MODULES \
103 PRODUCT_SDK_ADDON_DOC_MODULES \
104 PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP \
105 PRODUCT_DEFAULT_WIFI_CHANNELS \
106 PRODUCT_DEFAULT_DEV_CERTIFICATE \
107 PRODUCT_RESTRICT_VENDOR_FILES \
108 PRODUCT_VENDOR_KERNEL_HEADERS \
110 PRODUCT_SUPPORTS_BOOT_SIGNER \
111 PRODUCT_SUPPORTS_VBOOT \
112 PRODUCT_SUPPORTS_VERITY \
113 PRODUCT_SUPPORTS_VERITY_FEC \
114 PRODUCT_OEM_PROPERTIES \
115 PRODUCT_SYSTEM_PROPERTY_BLACKLIST \
116 PRODUCT_SYSTEM_SERVER_JARS \
117 PRODUCT_VBOOT_SIGNING_KEY \
118 PRODUCT_VBOOT_SIGNING_SUBKEY \
119 PRODUCT_VERITY_SIGNING_KEY \
120 PRODUCT_SYSTEM_VERITY_PARTITION \
121 PRODUCT_VENDOR_VERITY_PARTITION \
122 PRODUCT_DEX_PREOPT_MODULE_CONFIGS \
123 PRODUCT_DEX_PREOPT_DEFAULT_FLAGS \
124 PRODUCT_DEX_PREOPT_BOOT_FLAGS \
125 PRODUCT_SANITIZER_MODULE_CONFIGS \
126 PRODUCT_SYSTEM_BASE_FS_PATH \
127 PRODUCT_VENDOR_BASE_FS_PATH \
128 PRODUCT_SHIPPING_API_LEVEL \
133 $(info ==== $(1) ====)\
134 $(foreach v,$(_product_var_list),\
135 $(info PRODUCTS.$(1).$(v) := $(PRODUCTS.$(1).$(v))))\
140 $(foreach p,$(PRODUCTS),$(call dump-product,$(p)))
144 # Internal function. Appends inherited product variables to an existing one.
146 # $(1): Product variable to operate on
147 # $(2): Value to append
149 define inherit-product_append-var
150 $(if $(findstring ../,$(2)),\
151 $(eval np := $(call normalize-paths,$(2))),\
152 $(eval np := $(strip $(2))))\
153 $(eval $(1) := $($(1)) $(INHERIT_TAG)$(np))
157 # Internal function. Prepends inherited product variables to an existing one.
159 # $(1): Product variable to operate on
160 # $(2): Value to prepend
162 define inherit-product_prepend-var
163 $(eval $(1) := $(INHERIT_TAG)$(strip $(2)) $($(1)))
167 # Internal function. Tracks visited notes during inheritance resolution.
169 # $(1): Product being inherited
171 define inherit-product_track-node
172 $(if $(findstring ../,$(1)),\
173 $(eval np := $(call normalize-paths,$(1))),\
174 $(eval np := $(strip $(1))))\
175 $(eval inherit_var := \
176 PRODUCTS.$(strip $(word 1,$(_include_stack))).INHERITS_FROM) \
177 $(eval $(inherit_var) := $(sort $($(inherit_var)) $(np))) \
178 $(eval inherit_var:=) \
179 $(eval ALL_PRODUCTS := $(sort $(ALL_PRODUCTS) $(word 1,$(_include_stack))))
183 # $(1): product to inherit
186 # 1. Inherits all of the variables from $1, prioritizing existing settings.
187 # 2. Records the inheritance in the .INHERITS_FROM variable
188 # 3. Records that we've visited this node, in ALL_PRODUCTS
191 define inherit-product
192 $(foreach v,$(_product_var_list), \
193 $(call inherit-product_append-var,$(v),$(1))) \
194 $(call inherit-product_track-node,$(1))
198 # $(1): product to inherit
201 # 1. Inherits all of the variables from $1, prioritizing inherited settings.
202 # 2. Records the inheritance in the .INHERITS_FROM variable
203 # 3. Records that we've visited this node, in ALL_PRODUCTS
205 define prepend-product
206 $(foreach v,$(_product_var_list), \
207 $(call inherit-product_prepend-var,$(v),$(1))) \
208 $(call inherit-product_track-node,$(1))
212 # Do inherit-product only if $(1) exists
214 define inherit-product-if-exists
215 $(if $(wildcard $(1)),$(call inherit-product,$(1)),)
219 # Do inherit-product-prepend only if $(1) exists
221 define prepend-product-if-exists
222 $(if $(wildcard $(1)),$(call prepend-product,$(1)),)
226 # $(1): product makefile list
228 #TODO: check to make sure that products have all the necessary vars defined
229 define import-products
230 $(call import-nodes,PRODUCTS,$(1),$(_product_var_list))
235 # Does various consistency checks on all of the known products.
236 # Takes no parameters, so $(call ) is not necessary.
238 define check-all-products
240 $(eval _cap_names :=) \
241 $(foreach p,$(PRODUCTS), \
242 $(eval pn := $(strip $(PRODUCTS.$(p).PRODUCT_NAME))) \
243 $(if $(pn),,$(error $(p): PRODUCT_NAME must be defined.)) \
244 $(if $(filter $(pn),$(_cap_names)), \
245 $(error $(p): PRODUCT_NAME must be unique; "$(pn)" already used by $(strip \
248 $(if $(filter $(pn),$(PRODUCTS.$(pp).PRODUCT_NAME)), \
253 $(eval _cap_names += $(pn)) \
254 $(if $(call is-c-identifier,$(pn)),, \
255 $(error $(p): PRODUCT_NAME must be a valid C identifier, not "$(pn)") \
257 $(eval pb := $(strip $(PRODUCTS.$(p).PRODUCT_BRAND))) \
258 $(if $(pb),,$(error $(p): PRODUCT_BRAND must be defined.)) \
259 $(foreach cf,$(strip $(PRODUCTS.$(p).PRODUCT_COPY_FILES)), \
260 $(if $(filter 2 3,$(words $(subst :,$(space),$(cf)))),, \
261 $(error $(p): malformed COPY_FILE "$(cf)") \
270 # Returns the product makefile path for the product with the provided name
272 # $(1): short product name like "generic"
274 define _resolve-short-product-name
275 $(eval pn := $(strip $(1)))
277 $(foreach p,$(PRODUCTS), \
278 $(if $(filter $(pn),$(PRODUCTS.$(p).PRODUCT_NAME)), \
282 $(eval p := $(sort $(p)))
283 $(if $(filter 1,$(words $(p))), \
285 $(if $(filter 0,$(words $(p))), \
286 $(error No matches for product "$(pn)"), \
287 $(error Product "$(pn)" ambiguous: matches $(p)) \
291 define resolve-short-product-name
292 $(strip $(call _resolve-short-product-name,$(1)))
296 _product_stash_var_list := $(_product_var_list) \
297 PRODUCT_BOOTCLASSPATH \
298 PRODUCT_SYSTEM_SERVER_CLASSPATH \
300 TARGET_ARCH_VARIANT \
302 TARGET_BOARD_PLATFORM \
303 TARGET_BOARD_PLATFORM_GPU \
304 TARGET_BOARD_KERNEL_HEADERS \
305 TARGET_DEVICE_KERNEL_HEADERS \
306 TARGET_PRODUCT_KERNEL_HEADERS \
307 TARGET_BOOTLOADER_BOARD_NAME \
308 TARGET_NO_BOOTLOADER \
311 TARGET_NO_RADIOIMAGE \
317 _product_stash_var_list += \
318 BOARD_WPA_SUPPLICANT_DRIVER \
320 BOARD_USES_GENERIC_AUDIO \
321 BOARD_KERNEL_CMDLINE \
323 BOARD_HAVE_BLUETOOTH \
324 BOARD_VENDOR_USE_AKMD \
326 BOARD_BOOTIMAGE_PARTITION_SIZE \
327 BOARD_RECOVERYIMAGE_PARTITION_SIZE \
328 BOARD_SYSTEMIMAGE_PARTITION_SIZE \
329 BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE \
330 BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE \
331 BOARD_USERDATAIMAGE_PARTITION_SIZE \
332 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE \
333 BOARD_CACHEIMAGE_PARTITION_SIZE \
334 BOARD_FLASH_BLOCK_SIZE \
335 BOARD_VENDORIMAGE_PARTITION_SIZE \
336 BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE \
337 BOARD_INSTALLER_CMDLINE \
340 _product_stash_var_list += \
341 DEFAULT_SYSTEM_DEV_CERTIFICATE \
343 WITH_DEXPREOPT_BOOT_IMG_ONLY
345 _product_stash_var_list += \
346 GLOBAL_CFLAGS_NO_OVERRIDE \
347 GLOBAL_CPPFLAGS_NO_OVERRIDE \
348 GLOBAL_CLANG_CFLAGS_NO_OVERRIDE \
350 _product_stash_var_list += \
351 TARGET_SKIP_DEFAULT_LOCALE \
352 TARGET_SKIP_PRODUCT_DEVICE \
355 # Stash values of the variables in _product_stash_var_list.
356 # $(1): Renamed prefix
358 define stash-product-vars
359 $(foreach v,$(_product_stash_var_list), \
360 $(eval $(strip $(1))_$(call rot13,$(v)):=$$($$(v))) \
365 # Assert that the the variable stashed by stash-product-vars remains untouched.
366 # $(1): The prefix as supplied to stash-product-vars
368 define assert-product-vars
370 $(eval changed_variables:=)
371 $(foreach v,$(_product_stash_var_list), \
372 $(if $(call streq,$($(v)),$($(strip $(1))_$(call rot13,$(v)))),, \
373 $(eval $(warning $(v) has been modified: $($(v)))) \
374 $(eval $(warning previous value: $($(strip $(1))_$(call rot13,$(v))))) \
375 $(eval changed_variables := $(changed_variables) $(v))) \
377 $(if $(changed_variables),\
378 $(eval $(error The following variables have been changed: $(changed_variables))),)
382 define add-to-product-copy-files-if-exists
383 $(if $(wildcard $(word 1,$(subst :, ,$(1)))),$(1))
386 # whitespace placeholder when we record module's dex-preopt config.
387 _PDPMC_SP_PLACE_HOLDER := |@SP@|
388 # Set up dex-preopt config for a module.
389 # $(1) list of module names
390 # $(2) the modules' dex-preopt config
391 define add-product-dex-preopt-module-config
392 $(eval _c := $(subst $(space),$(_PDPMC_SP_PLACE_HOLDER),$(strip $(2))))\
393 $(eval PRODUCT_DEX_PREOPT_MODULE_CONFIGS += \
394 $(foreach m,$(1),$(m)=$(_c)))
397 # whitespace placeholder when we record module's sanitizer config.
398 _PSMC_SP_PLACE_HOLDER := |@SP@|
399 # Set up sanitizer config for a module.
400 # $(1) list of module names
401 # $(2) the modules' sanitizer config
402 define add-product-sanitizer-module-config
403 $(eval _c := $(subst $(space),$(_PSMC_SP_PLACE_HOLDER),$(strip $(2))))\
404 $(eval PRODUCT_SANITIZER_MODULE_CONFIGS += \
405 $(foreach m,$(1),$(m)=$(_c)))