blob: f5fa53a555132d73aa796377ddd767175be229b5 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001#
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
The Android Open Source Project2f312932009-03-09 11:52:11 -070053# 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
The Android Open Source Project88b60792009-03-03 19:28:42 -080058# ---------------------------------------------------------------
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
The Android Open Source Project88b60792009-03-03 19:28:42 -080083 # The build server wants to do make PRODUCT-dream-installclean
84 # which really means TARGET_PRODUCT=dream make installclean.
The Android Open Source Project2f312932009-03-09 11:52:11 -070085 ifneq ($(filter-out $(INTERNAL_VALID_VARIANTS),$(TARGET_BUILD_VARIANT)),)
The Android Open Source Project88b60792009-03-03 19:28:42 -080086 MAKECMDGOALS := $(MAKECMDGOALS) $(TARGET_BUILD_VARIANT)
87 TARGET_BUILD_VARIANT := eng
88 default_goal_substitution :=
89 else
90 default_goal_substitution := $(DEFAULT_GOAL)
91 endif
The Android Open Source Project88b60792009-03-03 19:28:42 -080092
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))
Dave Bortd14f6d92009-03-24 20:50:42 -0700159 ifneq ($(CALLED_FROM_SETUP),true)
160 # Don't spam stdout, because envsetup.sh may be scraping values from it.
161 $(info Adding CUSTOM_LOCALES [$(extra_locales)] to PRODUCT_LOCALES [$(PRODUCT_LOCALES)])
162 endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800163 PRODUCT_LOCALES += $(extra_locales)
164 extra_locales :=
165endif
166
167# Assemble the list of options.
168PRODUCT_AAPT_CONFIG := $(PRODUCT_LOCALES)
169
170# Convert spaces to commas.
171comma := ,
172PRODUCT_AAPT_CONFIG := \
173 $(subst $(space),$(comma),$(strip $(PRODUCT_AAPT_CONFIG)))
174
175PRODUCT_BRAND := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_BRAND))
176
177PRODUCT_MODEL := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_MODEL))
178ifndef PRODUCT_MODEL
179 PRODUCT_MODEL := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_NAME))
180endif
181
182PRODUCT_MANUFACTURER := \
183 $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_MANUFACTURER))
184ifndef PRODUCT_MANUFACTURER
185 PRODUCT_MANUFACTURER := unknown
186endif
187
188# Which policy should this product use
189PRODUCT_POLICY := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_POLICY))
190
191# A list of words like <source path>:<destination path>. The file at
192# the source path should be copied to the destination path when building
193# this product. <destination path> is relative to $(PRODUCT_OUT), so
194# it should look like, e.g., "system/etc/file.xml". The rules
195# for these copy steps are defined in config/Makefile.
196PRODUCT_COPY_FILES := \
197 $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_COPY_FILES))
198
199# The HTML file containing the contributors to the project.
200PRODUCT_CONTRIBUTORS_FILE := \
201 $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_CONTRIBUTORS_FILE))
202
203# A list of property assignments, like "key = value", with zero or more
204# whitespace characters on either side of the '='.
205PRODUCT_PROPERTY_OVERRIDES := \
206 $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PROPERTY_OVERRIDES))
207
208# Should we use the default resources or add any product specific overlays
209PRODUCT_PACKAGE_OVERLAYS := \
210 $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGE_OVERLAYS))
211DEVICE_PACKAGE_OVERLAYS := \
212 $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).DEVICE_PACKAGE_OVERLAYS))
213
214# An list of whitespace-separated words.
215PRODUCT_TAGS := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_TAGS))
216
217# Add the product-defined properties to the build properties.
218ADDITIONAL_BUILD_PROPERTIES := \
219 $(ADDITIONAL_BUILD_PROPERTIES) \
220 $(PRODUCT_PROPERTY_OVERRIDES)
221
222# Get the list of OTA public keys for the product.
223OTA_PUBLIC_KEYS := \
224 $(sort \
225 $(OTA_PUBLIC_KEYS) \
226 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_OTA_PUBLIC_KEYS) \
227 )
228
229# HACK: Not all products define OTA keys yet, and the -user build
230# will fail if no keys are defined.
231# TODO: Let a product opt out of needing OTA keys, and stop defaulting to
232# the test key as soon as possible.
233ifeq (,$(strip $(OTA_PUBLIC_KEYS)))
234 ifeq (,$(CALLED_FROM_SETUP))
235 $(warning WARNING: adding test OTA key)
236 endif
237 OTA_PUBLIC_KEYS := $(SRC_TARGET_DIR)/product/security/testkey.x509.pem
238endif
239
240# ---------------------------------------------------------------
241# Force the simulator to be the simulator, and make BUILD_TYPE
242# default to debug.
243ifeq ($(TARGET_PRODUCT),sim)
244 TARGET_SIMULATOR := true
245 ifeq (,$(strip $(TARGET_BUILD_TYPE)))
246 TARGET_BUILD_TYPE := debug
247 endif
248 # dexpreopt doesn't work when building the simulator
249 DISABLE_DEXPREOPT := true
250endif