product.mk revision 780128a6f05ad6bcd594ce10953a8ca533e63597
1#
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
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
24# omitted.
25
26#
27# Returns the list of all AndroidProducts.mk files.
28# $(call ) isn't necessary.
29#
30define _find-android-products-files
31$(shell test -d device && find device -maxdepth 6 -name AndroidProducts.mk) \
32  $(shell test -d vendor && find vendor -maxdepth 6 -name AndroidProducts.mk) \
33  $(SRC_TARGET_DIR)/product/AndroidProducts.mk
34endef
35
36#
37# Returns the sorted concatenation of PRODUCT_MAKEFILES
38# variables set in the given AndroidProducts.mk files.
39# $(1): the list of AndroidProducts.mk files.
40#
41define get-product-makefiles
42$(sort \
43  $(foreach f,$(1), \
44    $(eval PRODUCT_MAKEFILES :=) \
45    $(eval LOCAL_DIR := $(patsubst %/,%,$(dir $(f)))) \
46    $(eval include $(f)) \
47    $(PRODUCT_MAKEFILES) \
48   ) \
49  $(eval PRODUCT_MAKEFILES :=) \
50  $(eval LOCAL_DIR :=) \
51 )
52endef
53
54#
55# Returns the sorted concatenation of all PRODUCT_MAKEFILES
56# variables set in all AndroidProducts.mk files.
57# $(call ) isn't necessary.
58#
59define get-all-product-makefiles
60$(call get-product-makefiles,$(_find-android-products-files))
61endef
62
63#
64# Functions for including product makefiles
65#
66
67_product_var_list := \
68    PRODUCT_NAME \
69    PRODUCT_MODEL \
70    PRODUCT_LOCALES \
71    PRODUCT_AAPT_CONFIG \
72    PRODUCT_AAPT_PREF_CONFIG \
73    PRODUCT_PACKAGES \
74    PRODUCT_PACKAGES_DEBUG \
75    PRODUCT_PACKAGES_ENG \
76    PRODUCT_PACKAGES_TESTS \
77    PRODUCT_DEVICE \
78    PRODUCT_MANUFACTURER \
79    PRODUCT_BRAND \
80    PRODUCT_PROPERTY_OVERRIDES \
81    PRODUCT_DEFAULT_PROPERTY_OVERRIDES \
82    PRODUCT_CHARACTERISTICS \
83    PRODUCT_COPY_FILES \
84    PRODUCT_OTA_PUBLIC_KEYS \
85    PRODUCT_EXTRA_RECOVERY_KEYS \
86    PRODUCT_PACKAGE_OVERLAYS \
87    DEVICE_PACKAGE_OVERLAYS \
88    PRODUCT_TAGS \
89    PRODUCT_SDK_ATREE_FILES \
90    PRODUCT_SDK_ADDON_NAME \
91    PRODUCT_SDK_ADDON_COPY_FILES \
92    PRODUCT_SDK_ADDON_COPY_MODULES \
93    PRODUCT_SDK_ADDON_DOC_MODULES \
94    PRODUCT_DEFAULT_WIFI_CHANNELS \
95    PRODUCT_DEFAULT_DEV_CERTIFICATE \
96    PRODUCT_RESTRICT_VENDOR_FILES \
97    PRODUCT_VENDOR_KERNEL_HEADERS \
98    PRODUCT_FACTORY_RAMDISK_MODULES \
99    PRODUCT_FACTORY_BUNDLE_MODULES \
100    PRODUCT_RUNTIMES \
101    PRODUCT_BOOT_JARS \
102    PRODUCT_DEX_PREOPT_IMAGE_IN_DATA \
103
104define dump-product
105$(info ==== $(1) ====)\
106$(foreach v,$(_product_var_list),\
107$(info PRODUCTS.$(1).$(v) := $(PRODUCTS.$(1).$(v))))\
108$(info --------)
109endef
110
111define dump-products
112$(foreach p,$(PRODUCTS),$(call dump-product,$(p)))
113endef
114
115#
116# $(1): product to inherit
117#
118# Does three things:
119#  1. Inherits all of the variables from $1.
120#  2. Records the inheritance in the .INHERITS_FROM variable
121#  3. Records that we've visited this node, in ALL_PRODUCTS
122#
123define inherit-product
124  $(foreach v,$(_product_var_list), \
125      $(eval $(v) := $($(v)) $(INHERIT_TAG)$(strip $(1)))) \
126  $(eval inherit_var := \
127      PRODUCTS.$(strip $(word 1,$(_include_stack))).INHERITS_FROM) \
128  $(eval $(inherit_var) := $(sort $($(inherit_var)) $(strip $(1)))) \
129  $(eval inherit_var:=) \
130  $(eval ALL_PRODUCTS := $(sort $(ALL_PRODUCTS) $(word 1,$(_include_stack))))
131endef
132
133
134#
135# Do inherit-product only if $(1) exists
136#
137define inherit-product-if-exists
138  $(if $(wildcard $(1)),$(call inherit-product,$(1)),)
139endef
140
141#
142# $(1): product makefile list
143#
144#TODO: check to make sure that products have all the necessary vars defined
145define import-products
146$(call import-nodes,PRODUCTS,$(1),$(_product_var_list))
147endef
148
149
150#
151# Does various consistency checks on all of the known products.
152# Takes no parameters, so $(call ) is not necessary.
153#
154define check-all-products
155$(if ,, \
156  $(eval _cap_names :=) \
157  $(foreach p,$(PRODUCTS), \
158    $(eval pn := $(strip $(PRODUCTS.$(p).PRODUCT_NAME))) \
159    $(if $(pn),,$(error $(p): PRODUCT_NAME must be defined.)) \
160    $(if $(filter $(pn),$(_cap_names)), \
161      $(error $(p): PRODUCT_NAME must be unique; "$(pn)" already used by $(strip \
162          $(foreach \
163            pp,$(PRODUCTS),
164              $(if $(filter $(pn),$(PRODUCTS.$(pp).PRODUCT_NAME)), \
165                $(pp) \
166               ))) \
167       ) \
168     ) \
169    $(eval _cap_names += $(pn)) \
170    $(if $(call is-c-identifier,$(pn)),, \
171      $(error $(p): PRODUCT_NAME must be a valid C identifier, not "$(pn)") \
172     ) \
173    $(eval pb := $(strip $(PRODUCTS.$(p).PRODUCT_BRAND))) \
174    $(if $(pb),,$(error $(p): PRODUCT_BRAND must be defined.)) \
175    $(foreach cf,$(strip $(PRODUCTS.$(p).PRODUCT_COPY_FILES)), \
176      $(if $(filter 2 3,$(words $(subst :,$(space),$(cf)))),, \
177        $(error $(p): malformed COPY_FILE "$(cf)") \
178       ) \
179     ) \
180   ) \
181)
182endef
183
184
185#
186# Returns the product makefile path for the product with the provided name
187#
188# $(1): short product name like "generic"
189#
190define _resolve-short-product-name
191  $(eval pn := $(strip $(1)))
192  $(eval p := \
193      $(foreach p,$(PRODUCTS), \
194          $(if $(filter $(pn),$(PRODUCTS.$(p).PRODUCT_NAME)), \
195            $(p) \
196       )) \
197   )
198  $(eval p := $(sort $(p)))
199  $(if $(filter 1,$(words $(p))), \
200    $(p), \
201    $(if $(filter 0,$(words $(p))), \
202      $(error No matches for product "$(pn)"), \
203      $(error Product "$(pn)" ambiguous: matches $(p)) \
204    ) \
205  )
206endef
207define resolve-short-product-name
208$(strip $(call _resolve-short-product-name,$(1)))
209endef
210
211
212_product_stash_var_list := $(_product_var_list) \
213	PRODUCT_BOOTCLASSPATH \
214	TARGET_ARCH \
215	TARGET_ARCH_VARIANT \
216	TARGET_CPU_VARIANT \
217	TARGET_BOARD_PLATFORM \
218	TARGET_BOARD_PLATFORM_GPU \
219	TARGET_BOARD_KERNEL_HEADERS \
220	TARGET_DEVICE_KERNEL_HEADERS \
221	TARGET_PRODUCT_KERNEL_HEADERS \
222	TARGET_BOOTLOADER_BOARD_NAME \
223	TARGET_COMPRESS_MODULE_SYMBOLS \
224	TARGET_NO_BOOTLOADER \
225	TARGET_NO_KERNEL \
226	TARGET_NO_RECOVERY \
227	TARGET_NO_RADIOIMAGE \
228	TARGET_HARDWARE_3D \
229	TARGET_PROVIDES_INIT_RC \
230	TARGET_CPU_ABI \
231	TARGET_CPU_ABI2 \
232	TARGET_CPU_SMP \
233
234
235_product_stash_var_list += \
236	BOARD_WPA_SUPPLICANT_DRIVER \
237	BOARD_WLAN_DEVICE \
238	BOARD_USES_GENERIC_AUDIO \
239	BOARD_KERNEL_CMDLINE \
240	BOARD_KERNEL_BASE \
241	BOARD_HAVE_BLUETOOTH \
242	BOARD_VENDOR_USE_AKMD \
243	BOARD_EGL_CFG \
244	BOARD_BOOTIMAGE_PARTITION_SIZE \
245	BOARD_RECOVERYIMAGE_PARTITION_SIZE \
246	BOARD_SYSTEMIMAGE_PARTITION_SIZE \
247	BOARD_USERDATAIMAGE_PARTITION_SIZE \
248	BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE \
249	BOARD_CACHEIMAGE_PARTITION_SIZE \
250	BOARD_FLASH_BLOCK_SIZE \
251	BOARD_SYSTEMIMAGE_PARTITION_SIZE \
252	BOARD_INSTALLER_CMDLINE \
253
254
255_product_stash_var_list += \
256	DEFAULT_SYSTEM_DEV_CERTIFICATE
257
258#
259# Stash values of the variables in _product_stash_var_list.
260# $(1): Renamed prefix
261#
262define stash-product-vars
263$(foreach v,$(_product_stash_var_list), \
264        $(eval $(strip $(1))_$(call rot13,$(v)):=$$($$(v))) \
265 )
266endef
267
268#
269# Assert that the the variable stashed by stash-product-vars remains untouched.
270# $(1): The prefix as supplied to stash-product-vars
271#
272define assert-product-vars
273$(strip \
274  $(eval changed_variables:=)
275  $(foreach v,$(_product_stash_var_list), \
276    $(if $(call streq,$($(v)),$($(strip $(1))_$(call rot13,$(v)))),, \
277        $(eval $(warning $(v) has been modified: $($(v)))) \
278        $(eval $(warning previous value: $($(strip $(1))_$(call rot13,$(v))))) \
279        $(eval changed_variables := $(changed_variables) $(v))) \
280   ) \
281  $(if $(changed_variables),\
282    $(eval $(error The following variables have been changed: $(changed_variables))),)
283)
284endef
285
286define add-to-product-copy-files-if-exists
287$(if $(wildcard $(word 1,$(subst :, ,$(1)))),$(1))
288endef
289