envsetup.mk revision 88b607994a148f4af5bffee163e39ce8296750c6
1# Variables we check:
2#     HOST_BUILD_TYPE = { release debug }
3#     TARGET_SIMULATOR = { true <null> }
4#     TARGET_BUILD_TYPE = { release debug }
5# and we output a bunch of variables, see the case statement at
6# the bottom for the full list
7#     OUT_DIR is also set to "out" if it's not already set.
8#         this allows you to set it to somewhere else if you like
9
10# ---------------------------------------------------------------
11# If you update the build system such that the environment setup
12# or buildspec.mk need to be updated, increment this number, and
13# people who haven't re-run those will have to do so before they
14# can build.  Make sure to also update the corresponding value in
15# buildspec.mk.default and envsetup.sh.
16CORRECT_BUILD_ENV_SEQUENCE_NUMBER := 9
17
18# ---------------------------------------------------------------
19# The product defaults to generic on hardware and sim on sim
20# NOTE: This will be overridden in product_config.mk if make
21# was invoked with a PRODUCT-xxx-yyy goal.
22ifeq ($(TARGET_PRODUCT),)
23ifeq ($(TARGET_SIMULATOR),true)
24TARGET_PRODUCT := sim
25else
26TARGET_PRODUCT := generic
27endif
28endif
29
30
31# the variant -- the set of files that are included for a build
32ifeq ($(strip $(TARGET_BUILD_VARIANT)),)
33TARGET_BUILD_VARIANT := eng
34endif
35
36# Read the product specs so we an get TARGET_DEVICE and other
37# variables that we need in order to locate the output files.
38include $(BUILD_SYSTEM)/product_config.mk
39
40build_variant := $(filter-out eng user userdebug tests,$(TARGET_BUILD_VARIANT))
41ifneq ($(build_variant)-$(words $(TARGET_BUILD_VARIANT)),-1)
42$(warning bad TARGET_BUILD_VARIANT: $(TARGET_BUILD_VARIANT))
43$(error must be empty or one of: eng user userdebug tests)
44endif
45
46
47
48# ---------------------------------------------------------------
49# Set up configuration for host machine.  We don't do cross-
50# compiles except for arm, so the HOST is whatever we are
51# running on
52
53UNAME := $(shell uname -sm)
54
55# HOST_OS
56ifneq (,$(findstring Linux,$(UNAME)))
57	HOST_OS := linux
58endif
59ifneq (,$(findstring Darwin,$(UNAME)))
60	HOST_OS := darwin
61endif
62ifneq (,$(findstring Macintosh,$(UNAME)))
63	HOST_OS := darwin
64endif
65ifneq (,$(findstring CYGWIN,$(UNAME)))
66	HOST_OS := windows
67endif
68ifneq ($(USE_MINGW),)
69	HOST_OS := windows
70endif
71
72ifeq ($(HOST_OS),)
73$(error Unable to determine HOST_OS from uname -sm: $(UNAME)!)
74endif
75
76
77# HOST_ARCH
78ifneq (,$(findstring 86,$(UNAME)))
79	HOST_ARCH := x86
80endif
81
82ifneq (,$(findstring Power,$(UNAME)))
83	HOST_ARCH := ppc
84endif
85
86ifeq ($(HOST_ARCH),)
87$(error Unable to determine HOST_ARCH from uname -sm: $(UNAME)!)
88endif
89
90# the host build defaults to release, and it must be release or debug
91ifeq ($(HOST_BUILD_TYPE),)
92HOST_BUILD_TYPE := release
93endif
94
95ifneq ($(HOST_BUILD_TYPE),release)
96ifneq ($(HOST_BUILD_TYPE),debug)
97$(error HOST_BUILD_TYPE must be either release or debug, not '$(HOST_BUILD_TYPE)')
98endif
99endif
100
101# This is the standard way to name a directory containing prebuilt host
102# objects. E.g., prebuilt/$(HOST_PREBUILT_TAG)/cc
103ifeq ($(HOST_OS),windows)
104  HOST_PREBUILT_TAG := windows
105else
106  HOST_PREBUILT_TAG := $(HOST_OS)-$(HOST_ARCH)
107endif
108
109
110# ---------------------------------------------------------------
111# Set up configuration for target machine.
112# The following must be set:
113# 		TARGET_OS = { linux }
114# 		TARGET_ARCH = { arm | x86 }
115
116
117# if we're build the simulator, HOST_* is TARGET_* (except for BUILD_TYPE)
118# otherwise  it's <arch>-linux
119ifeq ($(TARGET_SIMULATOR),true)
120ifneq ($(HOST_OS),linux)
121$(error TARGET_SIMULATOR=true is only supported under Linux)
122endif
123TARGET_ARCH := $(HOST_ARCH)
124TARGET_OS := $(HOST_OS)
125else
126ifeq ($(TARGET_ARCH),)
127TARGET_ARCH := arm
128endif
129TARGET_OS := linux
130endif
131
132# the target build type defaults to release
133ifneq ($(TARGET_BUILD_TYPE),debug)
134TARGET_BUILD_TYPE := release
135endif
136
137# This is the standard way to name a directory containing prebuilt target
138# objects. E.g., prebuilt/$(TARGET_PREBUILT_TAG)/libc.so
139ifeq ($(TARGET_SIMULATOR),true)
140  TARGET_PREBUILT_TAG := $(TARGET_OS)-$(TARGET_ARCH)
141else
142  TARGET_PREBUILT_TAG := android-$(TARGET_ARCH)
143endif
144
145# ---------------------------------------------------------------
146# figure out the output directories
147
148ifeq (,$(strip $(OUT_DIR)))
149OUT_DIR := $(TOPDIR)out
150endif
151
152DEBUG_OUT_DIR := $(OUT_DIR)/debug
153
154# Move the host or target under the debug/ directory
155# if necessary.
156TARGET_OUT_ROOT_release := $(OUT_DIR)/target
157TARGET_OUT_ROOT_debug := $(DEBUG_OUT_DIR)/target
158TARGET_OUT_ROOT := $(TARGET_OUT_ROOT_$(TARGET_BUILD_TYPE))
159
160HOST_OUT_ROOT_release := $(OUT_DIR)/host
161HOST_OUT_ROOT_debug := $(DEBUG_OUT_DIR)/host
162HOST_OUT_ROOT := $(HOST_OUT_ROOT_$(HOST_BUILD_TYPE))
163
164HOST_OUT_release := $(HOST_OUT_ROOT_release)/$(HOST_OS)-$(HOST_ARCH)
165HOST_OUT_debug := $(HOST_OUT_ROOT_debug)/$(HOST_OS)-$(HOST_ARCH)
166HOST_OUT := $(HOST_OUT_$(HOST_BUILD_TYPE))
167
168ifeq ($(TARGET_SIMULATOR),true)
169  # Any arch- or os-specific parts of the simulator (everything
170  # under product/) are actually host-dependent.
171  # But, the debug type is controlled by TARGET_BUILD_TYPE and not
172  # HOST_BUILD_TYPE.
173  TARGET_PRODUCT_OUT_ROOT := $(HOST_OUT_$(TARGET_BUILD_TYPE))/product
174else
175  TARGET_PRODUCT_OUT_ROOT := $(TARGET_OUT_ROOT)/product
176endif
177
178TARGET_COMMON_OUT_ROOT := $(TARGET_OUT_ROOT)/common
179HOST_COMMON_OUT_ROOT := $(HOST_OUT_ROOT)/common
180
181PRODUCT_OUT := $(TARGET_PRODUCT_OUT_ROOT)/$(TARGET_DEVICE)
182
183OUT_DOCS := $(TARGET_COMMON_OUT_ROOT)/docs
184
185HOST_OUT_EXECUTABLES:= $(HOST_OUT)/bin
186HOST_OUT_SHARED_LIBRARIES:= $(HOST_OUT)/lib
187HOST_OUT_JAVA_LIBRARIES:= $(HOST_OUT)/framework
188
189HOST_OUT_INTERMEDIATES := $(HOST_OUT)/obj
190HOST_OUT_HEADERS:= $(HOST_OUT_INTERMEDIATES)/include
191HOST_OUT_INTERMEDIATE_LIBRARIES := $(HOST_OUT_INTERMEDIATES)/lib
192HOST_OUT_STATIC_LIBRARIES := $(HOST_OUT_INTERMEDIATE_LIBRARIES)
193HOST_OUT_NOTICE_FILES:=$(HOST_OUT_INTERMEDIATES)/NOTICE_FILES
194HOST_OUT_COMMON_INTERMEDIATES := $(HOST_COMMON_OUT_ROOT)/obj
195
196TARGET_OUT_INTERMEDIATES := $(PRODUCT_OUT)/obj
197TARGET_OUT_HEADERS:= $(TARGET_OUT_INTERMEDIATES)/include
198TARGET_OUT_INTERMEDIATE_LIBRARIES := $(TARGET_OUT_INTERMEDIATES)/lib
199TARGET_OUT_COMMON_INTERMEDIATES := $(TARGET_COMMON_OUT_ROOT)/obj
200
201TARGET_OUT := $(PRODUCT_OUT)/system
202TARGET_OUT_EXECUTABLES:= $(TARGET_OUT)/bin
203TARGET_OUT_OPTIONAL_EXECUTABLES:= $(TARGET_OUT)/xbin
204TARGET_OUT_SHARED_LIBRARIES:= $(TARGET_OUT)/lib
205TARGET_OUT_JAVA_LIBRARIES:= $(TARGET_OUT)/framework
206TARGET_OUT_APPS:= $(TARGET_OUT)/app
207TARGET_OUT_KEYLAYOUT := $(TARGET_OUT)/usr/keylayout
208TARGET_OUT_KEYCHARS := $(TARGET_OUT)/usr/keychars
209TARGET_OUT_ETC := $(TARGET_OUT)/etc
210TARGET_OUT_STATIC_LIBRARIES:= $(TARGET_OUT_INTERMEDIATES)/lib
211TARGET_OUT_NOTICE_FILES:=$(TARGET_OUT_INTERMEDIATES)/NOTICE_FILES
212
213TARGET_OUT_DATA := $(PRODUCT_OUT)/data
214TARGET_OUT_DATA_EXECUTABLES:= $(TARGET_OUT_EXECUTABLES)
215TARGET_OUT_DATA_SHARED_LIBRARIES:= $(TARGET_OUT_SHARED_LIBRARIES)
216TARGET_OUT_DATA_JAVA_LIBRARIES:= $(TARGET_OUT_JAVA_LIBRARIES)
217TARGET_OUT_DATA_APPS:= $(TARGET_OUT_DATA)/app
218TARGET_OUT_DATA_KEYLAYOUT := $(TARGET_OUT_KEYLAYOUT)
219TARGET_OUT_DATA_KEYCHARS := $(TARGET_OUT_KEYCHARS)
220TARGET_OUT_DATA_ETC := $(TARGET_OUT_ETC)
221TARGET_OUT_DATA_STATIC_LIBRARIES:= $(TARGET_OUT_STATIC_LIBRARIES)
222
223TARGET_OUT_UNSTRIPPED := $(PRODUCT_OUT)/symbols
224TARGET_OUT_EXECUTABLES_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)/system/bin
225TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)/system/lib
226TARGET_ROOT_OUT_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)
227TARGET_ROOT_OUT_SBIN_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)/sbin
228TARGET_ROOT_OUT_BIN_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)/bin
229
230TARGET_ROOT_OUT := $(PRODUCT_OUT)/root
231TARGET_ROOT_OUT_BIN := $(TARGET_ROOT_OUT)/bin
232TARGET_ROOT_OUT_SBIN := $(TARGET_ROOT_OUT)/sbin
233TARGET_ROOT_OUT_ETC := $(TARGET_ROOT_OUT)/etc
234TARGET_ROOT_OUT_USR := $(TARGET_ROOT_OUT)/usr
235
236TARGET_RECOVERY_OUT := $(PRODUCT_OUT)/recovery
237TARGET_RECOVERY_ROOT_OUT := $(TARGET_RECOVERY_OUT)/root
238
239TARGET_SYSLOADER_OUT := $(PRODUCT_OUT)/sysloader
240TARGET_SYSLOADER_ROOT_OUT := $(TARGET_SYSLOADER_OUT)/root
241TARGET_SYSLOADER_SYSTEM_OUT := $(TARGET_SYSLOADER_OUT)/root/system
242
243TARGET_INSTALLER_OUT := $(PRODUCT_OUT)/installer
244TARGET_INSTALLER_DATA_OUT := $(TARGET_INSTALLER_OUT)/data
245TARGET_INSTALLER_ROOT_OUT := $(TARGET_INSTALLER_OUT)/root
246TARGET_INSTALLER_SYSTEM_OUT := $(TARGET_INSTALLER_OUT)/root/system
247
248COMMON_MODULE_CLASSES := JAVA_LIBRARIES NOTICE_FILES
249
250ifeq (,$(strip $(DIST_DIR)))
251  DIST_DIR := $(OUT_DIR)/dist
252endif
253
254ifeq ($(PRINT_BUILD_CONFIG),)
255PRINT_BUILD_CONFIG := true
256endif
257
258# ---------------------------------------------------------------
259# the setpath shell function in envsetup.sh uses this to figure out
260# what to add to the path given the config we have chosen.
261ifeq ($(CALLED_FROM_SETUP),true)
262
263ABP:=$(PWD)/$(HOST_OUT_EXECUTABLES)
264
265ifeq ($(TARGET_SIMULATOR),true)
266	ABP:=$(ABP):$(TARGET_OUT_EXECUTABLES)
267else
268	# this should be copied to HOST_OUT_EXECUTABLES instead
269	ABP:=$(ABP):$(PWD)/prebuilt/$(HOST_PREBUILT_TAG)/toolchain/arm-eabi-4.2.1/bin
270endif
271ANDROID_BUILD_PATHS := $(ABP)
272ANDROID_PREBUILTS := prebuilt/$(HOST_PREBUILT_TAG)
273
274# The "dumpvar" stuff lets you say something like
275#
276#     CALLED_FROM_SETUP=true \
277#       make -f config/envsetup.make dumpvar-TARGET_OUT
278# or
279#     CALLED_FROM_SETUP=true \
280#       make -f config/envsetup.make dumpvar-abs-HOST_OUT_EXECUTABLES
281#
282# The plain (non-abs) version just dumps the value of the named variable.
283# The "abs" version will treat the variable as a path, and dumps an
284# absolute path to it.
285#
286dumpvar_goals := \
287	$(strip $(patsubst dumpvar-%,%,$(filter dumpvar-%,$(MAKECMDGOALS))))
288ifdef dumpvar_goals
289
290  ifneq ($(words $(dumpvar_goals)),1)
291    $(error Only one "dumpvar-" goal allowed. Saw "$(MAKECMDGOALS)")
292  endif
293
294  # If the goal is of the form "dumpvar-abs-VARNAME", then
295  # treat VARNAME as a path and return the absolute path to it.
296  absolute_dumpvar := $(strip $(filter abs-%,$(dumpvar_goals)))
297  ifdef absolute_dumpvar
298    dumpvar_goals := $(patsubst abs-%,%,$(dumpvar_goals))
299    DUMPVAR_VALUE := $(PWD)/$($(dumpvar_goals))
300    dumpvar_target := dumpvar-abs-$(dumpvar_goals)
301  else
302    DUMPVAR_VALUE := $($(dumpvar_goals))
303    dumpvar_target := dumpvar-$(dumpvar_goals)
304  endif
305
306.PHONY: $(dumpvar_target)
307$(dumpvar_target):
308	@echo $(DUMPVAR_VALUE)
309
310endif # dumpvar_goals
311
312ifneq ($(dumpvar_goals),report_config)
313PRINT_BUILD_CONFIG:=
314endif
315
316endif # CALLED_FROM_SETUP
317
318
319ifneq ($(PRINT_BUILD_CONFIG),)
320$(info ============================================)
321$(info   TARGET_PRODUCT=$(TARGET_PRODUCT))
322$(info   TARGET_BUILD_VARIANT=$(TARGET_BUILD_VARIANT))
323$(info   TARGET_SIMULATOR=$(TARGET_SIMULATOR))
324$(info   TARGET_BUILD_TYPE=$(TARGET_BUILD_TYPE))
325$(info   TARGET_ARCH=$(TARGET_ARCH))
326$(info   HOST_ARCH=$(HOST_ARCH))
327$(info   HOST_OS=$(HOST_OS))
328$(info   HOST_BUILD_TYPE=$(HOST_BUILD_TYPE))
329$(info   BUILD_ID=$(BUILD_ID))
330$(info ============================================)
331endif
332
333
334