product.mk revision 475fa12adef8fc2b08290555a33dc8a9fef05be4
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#
20
21#
22# Returns the list of all AndroidProducts.mk files.
23# $(call ) isn't necessary.
24#
25define _find-android-products-files
26$(shell test -d vendor && find vendor -maxdepth 6 -name AndroidProducts.mk) \
27  $(SRC_TARGET_DIR)/product/AndroidProducts.mk
28endef
29
30#
31# Returns the sorted concatenation of all PRODUCT_MAKEFILES
32# variables set in all AndroidProducts.mk files.
33# $(call ) isn't necessary.
34#
35define get-all-product-makefiles
36$(sort \
37  $(foreach f,$(_find-android-products-files), \
38    $(eval PRODUCT_MAKEFILES :=) \
39    $(eval LOCAL_DIR := $(patsubst %/,%,$(dir $(f)))) \
40    $(eval include $(f)) \
41    $(PRODUCT_MAKEFILES) \
42   ) \
43  $(eval PRODUCT_MAKEFILES :=) \
44  $(eval LOCAL_DIR :=) \
45 )
46endef
47
48#
49# Functions for including product makefiles
50#
51
52_product_var_list := \
53    PRODUCT_NAME \
54    PRODUCT_MODEL \
55    PRODUCT_LOCALES \
56    PRODUCT_PACKAGES \
57    PRODUCT_DEVICE \
58    PRODUCT_MANUFACTURER \
59    PRODUCT_BRAND \
60    PRODUCT_PROPERTY_OVERRIDES \
61    PRODUCT_COPY_FILES \
62    PRODUCT_OTA_PUBLIC_KEYS \
63    PRODUCT_POLICY \
64    PRODUCT_PACKAGE_OVERLAYS \
65    DEVICE_PACKAGE_OVERLAYS \
66    PRODUCT_CONTRIBUTORS_FILE \
67    PRODUCT_TAGS
68
69define dump-product
70$(info ==== $(1) ====)\
71$(foreach v,$(_product_var_list),\
72$(info PRODUCTS.$(1).$(v) := $(PRODUCTS.$(1).$(v))))\
73$(info --------)
74endef
75
76define dump-products
77$(foreach p,$(PRODUCTS),$(call dump-product,$(p)))
78endef
79
80#
81# $(1): product to inherit
82#
83define inherit-product
84  $(foreach v,$(_product_var_list), \
85      $(eval $(v) := $($(v)) $(INHERIT_TAG)$(strip $(1))))
86endef
87
88#
89# $(1): product makefile list
90#
91#TODO: check to make sure that products have all the necessary vars defined
92define import-products
93$(call import-nodes,PRODUCTS,$(1),$(_product_var_list))
94endef
95
96
97#
98# Does various consistency checks on all of the known products.
99# Takes no parameters, so $(call ) is not necessary.
100#
101define check-all-products
102$(if ,, \
103  $(eval _cap_names :=) \
104  $(foreach p,$(PRODUCTS), \
105    $(eval pn := $(strip $(PRODUCTS.$(p).PRODUCT_NAME))) \
106    $(if $(pn),,$(error $(p): PRODUCT_NAME must be defined.)) \
107    $(if $(filter $(pn),$(_cap_names)), \
108      $(error $(p): PRODUCT_NAME must be unique; "$(pn)" already used by $(strip \
109          $(foreach \
110            pp,$(PRODUCTS),
111              $(if $(filter $(pn),$(PRODUCTS.$(pp).PRODUCT_NAME)), \
112                $(pp) \
113               ))) \
114       ) \
115     ) \
116    $(eval _cap_names += $(pn)) \
117    $(if $(call is-c-identifier,$(pn)),, \
118      $(error $(p): PRODUCT_NAME must be a valid C identifier, not "$(pn)") \
119     ) \
120    $(eval pb := $(strip $(PRODUCTS.$(p).PRODUCT_BRAND))) \
121    $(if $(pb),,$(error $(p): PRODUCT_BRAND must be defined.)) \
122    $(foreach cf,$(strip $(PRODUCTS.$(p).PRODUCT_COPY_FILES)), \
123      $(if $(filter 2,$(words $(subst :,$(space),$(cf)))),, \
124        $(error $(p): malformed COPY_FILE "$(cf)") \
125       ) \
126     ) \
127   ) \
128)
129endef
130
131
132#
133# Returns the product makefile path for the product with the provided name
134#
135# $(1): short product name like "generic"
136#
137define _resolve-short-product-name
138  $(eval pn := $(strip $(1)))
139  $(eval p := \
140      $(foreach p,$(PRODUCTS), \
141          $(if $(filter $(pn),$(PRODUCTS.$(p).PRODUCT_NAME)), \
142            $(p) \
143       )) \
144   )
145  $(eval p := $(sort $(p)))
146  $(if $(filter 1,$(words $(p))), \
147    $(p), \
148    $(if $(filter 0,$(words $(p))), \
149      $(error No matches for product "$(pn)"), \
150      $(error Product "$(pn)" ambiguous: matches $(p)) \
151    ) \
152  )
153endef
154define resolve-short-product-name
155$(strip $(call _resolve-short-product-name,$(1)))
156endef
157