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# Check for obsolete PRODUCT- and APP- goals
82ifeq ($(CALLED_FROM_SETUP),true)
83product_goals := $(strip $(filter PRODUCT-%,$(MAKECMDGOALS)))
84ifdef product_goals
85  $(error The PRODUCT-* goal is no longer supported. Use `TARGET_PRODUCT=<product> m droid` instead)
86endif
87unbundled_goals := $(strip $(filter APP-%,$(MAKECMDGOALS)))
88ifdef unbundled_goals
89  $(error The APP-* goal is no longer supported. Use `TARGET_BUILD_APPS="<app>" m droid` instead)
90endif # unbundled_goals
91endif
92
93# Default to building dalvikvm on hosts that support it...
94ifeq ($(HOST_OS),linux)
95# ... or if the if the option is already set
96ifeq ($(WITH_HOST_DALVIK),)
97  WITH_HOST_DALVIK := true
98endif
99endif
100
101# ---------------------------------------------------------------
102# Include the product definitions.
103# We need to do this to translate TARGET_PRODUCT into its
104# underlying TARGET_DEVICE before we start defining any rules.
105#
106include $(BUILD_SYSTEM)/node_fns.mk
107include $(BUILD_SYSTEM)/product.mk
108include $(BUILD_SYSTEM)/device.mk
109
110# Read in all of the product definitions specified by the AndroidProducts.mk
111# files in the tree.
112all_product_configs := $(get-all-product-makefiles)
113
114all_named_products :=
115
116# Find the product config makefile for the current product.
117# all_product_configs consists items like:
118# <product_name>:<path_to_the_product_makefile>
119# or just <path_to_the_product_makefile> in case the product name is the
120# same as the base filename of the product config makefile.
121current_product_makefile :=
122all_product_makefiles :=
123$(foreach f, $(all_product_configs),\
124    $(eval _cpm_words := $(call _decode-product-name,$(f)))\
125    $(eval _cpm_word1 := $(word 1,$(_cpm_words)))\
126    $(eval _cpm_word2 := $(word 2,$(_cpm_words)))\
127    $(eval all_product_makefiles += $(_cpm_word2))\
128    $(eval all_named_products += $(_cpm_word1))\
129    $(if $(filter $(TARGET_PRODUCT),$(_cpm_word1)),\
130        $(eval current_product_makefile += $(_cpm_word2)),))
131_cpm_words :=
132_cpm_word1 :=
133_cpm_word2 :=
134current_product_makefile := $(strip $(current_product_makefile))
135all_product_makefiles := $(strip $(all_product_makefiles))
136
137load_all_product_makefiles :=
138ifneq (,$(filter product-graph, $(MAKECMDGOALS)))
139ifeq ($(ANDROID_PRODUCT_GRAPH),--all)
140load_all_product_makefiles := true
141endif
142endif
143ifneq (,$(filter dump-products,$(MAKECMDGOALS)))
144ifeq ($(ANDROID_DUMP_PRODUCTS),all)
145load_all_product_makefiles := true
146endif
147endif
148
149ifeq ($(load_all_product_makefiles),true)
150# Import all product makefiles.
151$(call import-products, $(all_product_makefiles))
152else
153# Import just the current product.
154ifndef current_product_makefile
155$(error Can not locate config makefile for product "$(TARGET_PRODUCT)")
156endif
157ifneq (1,$(words $(current_product_makefile)))
158$(error Product "$(TARGET_PRODUCT)" ambiguous: matches $(current_product_makefile))
159endif
160$(call import-products, $(current_product_makefile))
161endif  # Import all or just the current product makefile
162
163# Import all the products that have made artifact path requirements, so that we can verify
164# the artifacts they produce.
165$(foreach makefile,$(ARTIFACT_PATH_REQUIREMENT_PRODUCTS),\
166  $(if $(filter-out $(makefile),$(PRODUCTS)),$(eval $(call import-products,$(makefile))))\
167)
168
169# Sanity check
170$(check-all-products)
171
172ifneq ($(filter dump-products, $(MAKECMDGOALS)),)
173$(dump-products)
174endif
175
176# Convert a short name like "sooner" into the path to the product
177# file defining that product.
178#
179INTERNAL_PRODUCT := $(call resolve-short-product-name, $(TARGET_PRODUCT))
180ifneq ($(current_product_makefile),$(INTERNAL_PRODUCT))
181$(error PRODUCT_NAME inconsistent in $(current_product_makefile) and $(INTERNAL_PRODUCT))
182endif
183current_product_makefile :=
184all_product_makefiles :=
185all_product_configs :=
186
187# Jacoco agent JARS to be built and installed, if any.
188ifeq ($(EMMA_INSTRUMENT),true)
189  ifneq ($(EMMA_INSTRUMENT_STATIC),true)
190    # For instrumented build, if Jacoco is not being included statically
191    # in instrumented packages then include Jacoco classes into the
192    # bootclasspath.
193    $(foreach product,$(PRODUCTS),\
194      $(eval PRODUCTS.$(product).PRODUCT_PACKAGES += jacocoagent)\
195      $(eval PRODUCTS.$(product).PRODUCT_BOOT_JARS += jacocoagent))
196  endif # EMMA_INSTRUMENT_STATIC
197endif # EMMA_INSTRUMENT
198
199############################################################################
200# Strip and assign the PRODUCT_ variables.
201$(call strip-product-vars)
202
203#############################################################################
204# Sanity check and assign default values
205
206TARGET_DEVICE := $(PRODUCT_DEVICE)
207
208# TODO: also keep track of things like "port", "land" in product files.
209
210# Figure out which resoure configuration options to use for this
211# product.
212# If CUSTOM_LOCALES contains any locales not already included
213# in PRODUCT_LOCALES, add them to PRODUCT_LOCALES.
214extra_locales := $(filter-out $(PRODUCT_LOCALES),$(CUSTOM_LOCALES))
215ifneq (,$(extra_locales))
216  ifneq ($(CALLED_FROM_SETUP),true)
217    # Don't spam stdout, because envsetup.sh may be scraping values from it.
218    $(info Adding CUSTOM_LOCALES [$(extra_locales)] to PRODUCT_LOCALES [$(PRODUCT_LOCALES)])
219  endif
220  PRODUCT_LOCALES += $(extra_locales)
221  extra_locales :=
222endif
223
224# Add PRODUCT_LOCALES to PRODUCT_AAPT_CONFIG
225PRODUCT_AAPT_CONFIG := $(PRODUCT_LOCALES) $(PRODUCT_AAPT_CONFIG)
226
227# Keep a copy of the space-separated config
228PRODUCT_AAPT_CONFIG_SP := $(PRODUCT_AAPT_CONFIG)
229PRODUCT_AAPT_CONFIG := $(subst $(space),$(comma),$(PRODUCT_AAPT_CONFIG))
230
231# Extra boot jars must be appended at the end after common boot jars.
232PRODUCT_BOOT_JARS += $(PRODUCT_BOOT_JARS_EXTRA)
233
234# The extra system server jars must be appended at the end after common system server jars.
235PRODUCT_SYSTEM_SERVER_JARS += $(PRODUCT_SYSTEM_SERVER_JARS_EXTRA)
236
237ifndef PRODUCT_SYSTEM_NAME
238  PRODUCT_SYSTEM_NAME := $(PRODUCT_NAME)
239endif
240ifndef PRODUCT_SYSTEM_DEVICE
241  PRODUCT_SYSTEM_DEVICE := $(PRODUCT_DEVICE)
242endif
243ifndef PRODUCT_SYSTEM_BRAND
244  PRODUCT_SYSTEM_BRAND := $(PRODUCT_BRAND)
245endif
246ifndef PRODUCT_MODEL
247  PRODUCT_MODEL := $(PRODUCT_NAME)
248endif
249ifndef PRODUCT_SYSTEM_MODEL
250  PRODUCT_SYSTEM_MODEL := $(PRODUCT_MODEL)
251endif
252
253ifndef PRODUCT_MANUFACTURER
254  PRODUCT_MANUFACTURER := unknown
255endif
256ifndef PRODUCT_SYSTEM_MANUFACTURER
257  PRODUCT_SYSTEM_MANUFACTURER := $(PRODUCT_MANUFACTURER)
258endif
259
260ifndef PRODUCT_CHARACTERISTICS
261  TARGET_AAPT_CHARACTERISTICS := default
262else
263  TARGET_AAPT_CHARACTERISTICS := $(PRODUCT_CHARACTERISTICS)
264endif
265
266ifdef PRODUCT_DEFAULT_DEV_CERTIFICATE
267  ifneq (1,$(words $(PRODUCT_DEFAULT_DEV_CERTIFICATE)))
268    $(error PRODUCT_DEFAULT_DEV_CERTIFICATE='$(PRODUCT_DEFAULT_DEV_CERTIFICATE)', \
269      only 1 certificate is allowed.)
270  endif
271endif
272
273$(foreach pair,$(PRODUCT_UPDATABLE_BOOT_JARS), \
274  $(if $(findstring $(call word-colon,2,$(pair)),$(PRODUCT_BOOT_JARS)), \
275    $(error A jar in PRODUCT_UPDATABLE_BOOT_JARS must not be in PRODUCT_BOOT_JARS, \
276      but $(call word-colon,2,$(pair)) is) \
277  ) \
278)
279
280ENFORCE_SYSTEM_CERTIFICATE := $(PRODUCT_ENFORCE_ARTIFACT_SYSTEM_CERTIFICATE_REQUIREMENT)
281ENFORCE_SYSTEM_CERTIFICATE_ALLOW_LIST := $(PRODUCT_ARTIFACT_SYSTEM_CERTIFICATE_REQUIREMENT_ALLOW_LIST)
282
283PRODUCT_OTA_PUBLIC_KEYS := $(sort $(PRODUCT_OTA_PUBLIC_KEYS))
284PRODUCT_EXTRA_RECOVERY_KEYS := $(sort $(PRODUCT_EXTRA_RECOVERY_KEYS))
285
286# Resolve and setup per-module dex-preopt configs.
287DEXPREOPT_DISABLED_MODULES :=
288# If a module has multiple setups, the first takes precedence.
289_pdpmc_modules :=
290$(foreach c,$(PRODUCT_DEX_PREOPT_MODULE_CONFIGS),\
291  $(eval m := $(firstword $(subst =,$(space),$(c))))\
292  $(if $(filter $(_pdpmc_modules),$(m)),,\
293    $(eval _pdpmc_modules += $(m))\
294    $(eval cf := $(patsubst $(m)=%,%,$(c)))\
295    $(eval cf := $(subst $(_PDPMC_SP_PLACE_HOLDER),$(space),$(cf)))\
296    $(if $(filter disable,$(cf)),\
297      $(eval DEXPREOPT_DISABLED_MODULES += $(m)),\
298      $(eval DEXPREOPT.$(TARGET_PRODUCT).$(m).CONFIG := $(cf)))))
299_pdpmc_modules :=
300
301
302# Resolve and setup per-module sanitizer configs.
303# If a module has multiple setups, the first takes precedence.
304_psmc_modules :=
305$(foreach c,$(PRODUCT_SANITIZER_MODULE_CONFIGS),\
306  $(eval m := $(firstword $(subst =,$(space),$(c))))\
307  $(if $(filter $(_psmc_modules),$(m)),,\
308    $(eval _psmc_modules += $(m))\
309    $(eval cf := $(patsubst $(m)=%,%,$(c)))\
310    $(eval cf := $(subst $(_PSMC_SP_PLACE_HOLDER),$(space),$(cf)))\
311    $(eval SANITIZER.$(TARGET_PRODUCT).$(m).CONFIG := $(cf))))
312_psmc_modules :=
313
314# Reset ADB keys for non-debuggable builds
315ifeq (,$(filter eng userdebug,$(TARGET_BUILD_VARIANT)),)
316  PRODUCT_ADB_KEYS :=
317endif
318ifneq ($(filter-out 0 1,$(words $(PRODUCT_ADB_KEYS))),)
319  $(error Only one file may be in PRODUCT_ADB_KEYS: $(PRODUCT_ADB_KEYS))
320endif
321
322ifndef PRODUCT_USE_DYNAMIC_PARTITIONS
323  PRODUCT_USE_DYNAMIC_PARTITIONS := $(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS)
324endif
325
326# All requirements of PRODUCT_USE_DYNAMIC_PARTITIONS falls back to
327# PRODUCT_USE_DYNAMIC_PARTITIONS if not defined.
328ifndef PRODUCT_USE_DYNAMIC_PARTITION_SIZE
329  PRODUCT_USE_DYNAMIC_PARTITION_SIZE := $(PRODUCT_USE_DYNAMIC_PARTITIONS)
330endif
331
332ifndef PRODUCT_BUILD_SUPER_PARTITION
333  PRODUCT_BUILD_SUPER_PARTITION := $(PRODUCT_USE_DYNAMIC_PARTITIONS)
334endif
335
336ifeq ($(PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS),)
337  ifdef PRODUCT_SHIPPING_API_LEVEL
338    ifeq (true,$(call math_gt_or_eq,$(PRODUCT_SHIPPING_API_LEVEL),29))
339      PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS := true
340    endif
341  endif
342endif
343
344ifdef PRODUCT_SHIPPING_API_LEVEL
345  ifneq (,$(call math_gt_or_eq,29,$(PRODUCT_SHIPPING_API_LEVEL)))
346    PRODUCT_PACKAGES += $(PRODUCT_PACKAGES_SHIPPING_API_LEVEL_29)
347  endif
348endif
349
350# If build command defines OVERRIDE_PRODUCT_EXTRA_VNDK_VERSIONS,
351# override PRODUCT_EXTRA_VNDK_VERSIONS with it.
352ifdef OVERRIDE_PRODUCT_EXTRA_VNDK_VERSIONS
353  PRODUCT_EXTRA_VNDK_VERSIONS := $(OVERRIDE_PRODUCT_EXTRA_VNDK_VERSIONS)
354endif
355
356$(KATI_obsolete_var OVERRIDE_PRODUCT_EXTRA_VNDK_VERSIONS \
357    ,Use PRODUCT_EXTRA_VNDK_VERSIONS instead)
358
359ifdef OVERRIDE_PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE
360  ifeq (false,$(OVERRIDE_PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE))
361    PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE :=
362  else
363    PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE := $(OVERRIDE_PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE)
364  endif
365else ifeq ($(PRODUCT_SHIPPING_API_LEVEL),)
366  # No shipping level defined
367else ifeq ($(call math_gt,$(PRODUCT_SHIPPING_API_LEVEL),29),true)
368  PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE := true
369endif
370
371$(KATI_obsolete_var OVERRIDE_PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE,Use PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE instead)
372
373define product-overrides-config
374$$(foreach rule,$$(PRODUCT_$(1)_OVERRIDES),\
375    $$(if $$(filter 2,$$(words $$(subst :,$$(space),$$(rule)))),,\
376        $$(error Rule "$$(rule)" in PRODUCT_$(1)_OVERRIDE is not <module_name>:<new_value>)))
377endef
378
379$(foreach var, \
380    MANIFEST_PACKAGE_NAME \
381    PACKAGE_NAME \
382    CERTIFICATE, \
383  $(eval $(call product-overrides-config,$(var))))
384
385# Macro to use below. $(1) is the name of the partition
386define product-build-image-config
387ifneq ($$(filter-out true false,$$(PRODUCT_BUILD_$(1)_IMAGE)),)
388    $$(error Invalid PRODUCT_BUILD_$(1)_IMAGE: $$(PRODUCT_BUILD_$(1)_IMAGE) -- true false and empty are supported)
389endif
390endef
391
392# Copy and check the value of each PRODUCT_BUILD_*_IMAGE variable
393$(foreach image, \
394    SYSTEM \
395    SYSTEM_OTHER \
396    VENDOR \
397    PRODUCT \
398    SYSTEM_EXT \
399    ODM \
400    CACHE \
401    RAMDISK \
402    USERDATA \
403    BOOT \
404    RECOVERY, \
405  $(eval $(call product-build-image-config,$(image))))
406
407product-build-image-config :=
408
409$(call readonly-product-vars)
410