product_config.mk revision 2f31293ba78695cb48ac5a1cab835197ace58d47
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
53# These are the valid values of TARGET_BUILD_VARIANT.  Also, if anything else is passed
54# as the variant in the PRODUCT-$TARGET_BUILD_PRODUCT-$TARGET_BUILD_VARIANT form,
55# it will be treated as a goal, and the eng variant will be used.
56INTERNAL_VALID_VARIANTS := user userdebug eng tests
57
58# ---------------------------------------------------------------
59# Provide "PRODUCT-<prodname>-<goal>" targets, which lets you build
60# a particular configuration without needing to set up the environment.
61#
62product_goals := $(strip $(filter PRODUCT-%,$(MAKECMDGOALS)))
63ifdef product_goals
64  # Scrape the product and build names out of the goal,
65  # which should be of the form PRODUCT-<productname>-<buildname>.
66  #
67  ifneq ($(words $(product_goals)),1)
68    $(error Only one PRODUCT-* goal may be specified; saw "$(product_goals)")
69  endif
70  goal_name := $(product_goals)
71  product_goals := $(patsubst PRODUCT-%,%,$(product_goals))
72  product_goals := $(subst -, ,$(product_goals))
73  ifneq ($(words $(product_goals)),2)
74    $(error Bad PRODUCT-* goal "$(goal_name)")
75  endif
76
77  # The product they want
78  TARGET_PRODUCT := $(word 1,$(product_goals))
79
80  # The variant they want
81  TARGET_BUILD_VARIANT := $(word 2,$(product_goals))
82
83  # The build server wants to do make PRODUCT-dream-installclean
84  # which really means TARGET_PRODUCT=dream make installclean.  
85  ifneq ($(filter-out $(INTERNAL_VALID_VARIANTS),$(TARGET_BUILD_VARIANT)),)
86	MAKECMDGOALS := $(MAKECMDGOALS) $(TARGET_BUILD_VARIANT)
87	TARGET_BUILD_VARIANT := eng
88    default_goal_substitution := 
89  else
90    default_goal_substitution := $(DEFAULT_GOAL)
91  endif
92
93  # Hack to make the linux build servers use dexpreopt.
94  # OSX is still a little flaky.  Most engineers don't use this
95  # type of target ("make PRODUCT-blah-user"), so this should
96  # only tend to happen when using buildbot.
97  # TODO: remove this and fix the matching lines in build/core/main.mk
98  # once dexpreopt works better on OSX.
99  ifeq ($(TARGET_BUILD_VARIANT),user)
100    WITH_DEXPREOPT_buildbot := true
101  endif
102
103  # Replace the PRODUCT-* goal with the build goal that it refers to.
104  # Note that this will ensure that it appears in the same relative
105  # position, in case it matters.
106  #
107  # Note that modifying this will not affect the goals that make will
108  # attempt to build, but it's important because we inspect this value
109  # in certain situations (like for "make sdk").  
110  #
111  MAKECMDGOALS := $(patsubst $(goal_name),$(default_goal_substitution),$(MAKECMDGOALS))
112
113  # Define a rule for the PRODUCT-* goal, and make it depend on the
114  # patched-up command-line goals as well as any other goals that we
115  # want to force.
116  #
117.PHONY: $(goal_name)
118$(goal_name): $(MAKECMDGOALS)
119endif
120# else: Use the value set in the environment or buildspec.mk.
121
122# ---------------------------------------------------------------
123# Include the product definitions.
124# We need to do this to translate TARGET_PRODUCT into its
125# underlying TARGET_DEVICE before we start defining any rules.
126#
127include $(BUILD_SYSTEM)/node_fns.mk
128include $(BUILD_SYSTEM)/product.mk
129include $(BUILD_SYSTEM)/device.mk
130
131# Read in all of the product definitions specified by the AndroidProducts.mk
132# files in the tree.
133#
134#TODO: when we start allowing direct pointers to product files,
135#    guarantee that they're in this list.
136$(call import-products, $(get-all-product-makefiles))
137$(check-all-products)
138#$(dump-products)
139#$(error done)
140
141# Convert a short name like "sooner" into the path to the product
142# file defining that product.
143#
144INTERNAL_PRODUCT := $(call resolve-short-product-name, $(TARGET_PRODUCT))
145#$(error TARGET_PRODUCT $(TARGET_PRODUCT) --> $(INTERNAL_PRODUCT))
146
147# Find the device that this product maps to.
148TARGET_DEVICE := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_DEVICE)
149
150# Figure out which resoure configuration options to use for this
151# product.
152PRODUCT_LOCALES := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_LOCALES))
153# TODO: also keep track of things like "port", "land" in product files.
154
155# If CUSTOM_LOCALES contains any locales not already included
156# in PRODUCT_LOCALES, add them to PRODUCT_LOCALES.
157extra_locales := $(filter-out $(PRODUCT_LOCALES),$(CUSTOM_LOCALES))
158ifneq (,$(extra_locales))
159  $(info Adding CUSTOM_LOCALES [$(extra_locales)] to PRODUCT_LOCALES [$(PRODUCT_LOCALES)])
160  PRODUCT_LOCALES += $(extra_locales)
161  extra_locales :=
162endif
163
164# Assemble the list of options.
165PRODUCT_AAPT_CONFIG := $(PRODUCT_LOCALES)
166
167# Convert spaces to commas.
168comma := ,
169PRODUCT_AAPT_CONFIG := \
170	$(subst $(space),$(comma),$(strip $(PRODUCT_AAPT_CONFIG)))
171
172PRODUCT_BRAND := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_BRAND))
173
174PRODUCT_MODEL := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_MODEL))
175ifndef PRODUCT_MODEL
176  PRODUCT_MODEL := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_NAME)) 
177endif
178
179PRODUCT_MANUFACTURER := \
180	$(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_MANUFACTURER))
181ifndef PRODUCT_MANUFACTURER
182  PRODUCT_MANUFACTURER := unknown
183endif
184
185# Which policy should this product use
186PRODUCT_POLICY := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_POLICY))
187
188# A list of words like <source path>:<destination path>.  The file at
189# the source path should be copied to the destination path when building
190# this product.  <destination path> is relative to $(PRODUCT_OUT), so
191# it should look like, e.g., "system/etc/file.xml".  The rules
192# for these copy steps are defined in config/Makefile.
193PRODUCT_COPY_FILES := \
194	$(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_COPY_FILES))
195
196# The HTML file containing the contributors to the project.
197PRODUCT_CONTRIBUTORS_FILE := \
198	$(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_CONTRIBUTORS_FILE))
199
200# A list of property assignments, like "key = value", with zero or more
201# whitespace characters on either side of the '='.
202PRODUCT_PROPERTY_OVERRIDES := \
203	$(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PROPERTY_OVERRIDES))
204
205# Should we use the default resources or add any product specific overlays
206PRODUCT_PACKAGE_OVERLAYS := \
207	$(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGE_OVERLAYS))
208DEVICE_PACKAGE_OVERLAYS := \
209        $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).DEVICE_PACKAGE_OVERLAYS))
210
211# An list of whitespace-separated words.
212PRODUCT_TAGS := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_TAGS))
213
214# Add the product-defined properties to the build properties.
215ADDITIONAL_BUILD_PROPERTIES := \
216	$(ADDITIONAL_BUILD_PROPERTIES) \
217	$(PRODUCT_PROPERTY_OVERRIDES)
218
219# Get the list of OTA public keys for the product.
220OTA_PUBLIC_KEYS := \
221	$(sort \
222	    $(OTA_PUBLIC_KEYS) \
223	    $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_OTA_PUBLIC_KEYS) \
224	 )
225
226# HACK: Not all products define OTA keys yet, and the -user build
227# will fail if no keys are defined.
228# TODO: Let a product opt out of needing OTA keys, and stop defaulting to
229#       the test key as soon as possible.
230ifeq (,$(strip $(OTA_PUBLIC_KEYS)))
231  ifeq (,$(CALLED_FROM_SETUP))
232    $(warning WARNING: adding test OTA key)
233  endif
234  OTA_PUBLIC_KEYS := $(SRC_TARGET_DIR)/product/security/testkey.x509.pem
235endif
236
237# ---------------------------------------------------------------
238# Force the simulator to be the simulator, and make BUILD_TYPE
239# default to debug.
240ifeq ($(TARGET_PRODUCT),sim)
241  TARGET_SIMULATOR := true
242  ifeq (,$(strip $(TARGET_BUILD_TYPE)))
243    TARGET_BUILD_TYPE := debug
244  endif
245  # dexpreopt doesn't work when building the simulator
246  DISABLE_DEXPREOPT := true
247endif
248