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