envsetup.mk revision b4d757b1b2677ee154992a8dd5607abe49107bdf
1# Variables we check:
2#     HOST_BUILD_TYPE = { release debug }
3#     TARGET_BUILD_TYPE = { release debug }
4# and we output a bunch of variables, see the case statement at
5# the bottom for the full list
6#     OUT_DIR is also set to "out" if it's not already set.
7#         this allows you to set it to somewhere else if you like
8
9# Set up version information.
10include $(BUILD_SYSTEM)/version_defaults.mk
11
12# ---------------------------------------------------------------
13# If you update the build system such that the environment setup
14# or buildspec.mk need to be updated, increment this number, and
15# people who haven't re-run those will have to do so before they
16# can build.  Make sure to also update the corresponding value in
17# buildspec.mk.default and envsetup.sh.
18CORRECT_BUILD_ENV_SEQUENCE_NUMBER := 10
19
20# ---------------------------------------------------------------
21# The product defaults to generic on hardware
22# NOTE: This will be overridden in product_config.mk if make
23# was invoked with a PRODUCT-xxx-yyy goal.
24ifeq ($(TARGET_PRODUCT),)
25TARGET_PRODUCT := full
26endif
27
28
29# the variant -- the set of files that are included for a build
30ifeq ($(strip $(TARGET_BUILD_VARIANT)),)
31TARGET_BUILD_VARIANT := eng
32endif
33
34# ---------------------------------------------------------------
35# Set up configuration for host machine.  We don't do cross-
36# compiles except for arm/mips, so the HOST is whatever we are
37# running on
38
39UNAME := $(shell uname -sm)
40
41# HOST_OS
42ifneq (,$(findstring Linux,$(UNAME)))
43	HOST_OS := linux
44endif
45ifneq (,$(findstring Darwin,$(UNAME)))
46	HOST_OS := darwin
47endif
48ifneq (,$(findstring Macintosh,$(UNAME)))
49	HOST_OS := darwin
50endif
51ifneq (,$(findstring CYGWIN,$(UNAME)))
52	HOST_OS := windows
53endif
54
55# BUILD_OS is the real host doing the build.
56BUILD_OS := $(HOST_OS)
57
58# Under Linux, if USE_MINGW is set, we change HOST_OS to Windows to build the
59# Windows SDK. Only a subset of tools and SDK will manage to build properly.
60ifeq ($(HOST_OS),linux)
61ifneq ($(USE_MINGW),)
62	HOST_OS := windows
63endif
64endif
65
66ifeq ($(HOST_OS),)
67$(error Unable to determine HOST_OS from uname -sm: $(UNAME)!)
68endif
69
70
71# HOST_ARCH
72ifneq (,$(findstring 86,$(UNAME)))
73	HOST_ARCH := x86
74endif
75
76ifneq (,$(findstring Power,$(UNAME)))
77	HOST_ARCH := ppc
78endif
79
80BUILD_ARCH := $(HOST_ARCH)
81
82ifeq ($(HOST_ARCH),)
83$(error Unable to determine HOST_ARCH from uname -sm: $(UNAME)!)
84endif
85
86# the host build defaults to release, and it must be release or debug
87ifeq ($(HOST_BUILD_TYPE),)
88HOST_BUILD_TYPE := release
89endif
90
91ifneq ($(HOST_BUILD_TYPE),release)
92ifneq ($(HOST_BUILD_TYPE),debug)
93$(error HOST_BUILD_TYPE must be either release or debug, not '$(HOST_BUILD_TYPE)')
94endif
95endif
96
97# This is the standard way to name a directory containing prebuilt host
98# objects. E.g., prebuilt/$(HOST_PREBUILT_TAG)/cc
99ifeq ($(HOST_OS),windows)
100  HOST_PREBUILT_TAG := windows
101else
102  HOST_PREBUILT_TAG := $(HOST_OS)-$(HOST_ARCH)
103endif
104
105# TARGET_COPY_OUT_* are all relative to the staging directory, ie PRODUCT_OUT.
106# Define them here so they can be used in product config files.
107TARGET_COPY_OUT_SYSTEM := system
108TARGET_COPY_OUT_DATA := data
109TARGET_COPY_OUT_VENDOR := system/vendor
110TARGET_COPY_OUT_ROOT := root
111TARGET_COPY_OUT_RECOVERY := recovery
112
113# Read the product specs so we an get TARGET_DEVICE and other
114# variables that we need in order to locate the output files.
115include $(BUILD_SYSTEM)/product_config.mk
116
117build_variant := $(filter-out eng user userdebug,$(TARGET_BUILD_VARIANT))
118ifneq ($(build_variant)-$(words $(TARGET_BUILD_VARIANT)),-1)
119$(warning bad TARGET_BUILD_VARIANT: $(TARGET_BUILD_VARIANT))
120$(error must be empty or one of: eng user userdebug)
121endif
122
123# Boards may be defined under $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)
124# or under vendor/*/$(TARGET_DEVICE).  Search in both places, but
125# make sure only one exists.
126# Real boards should always be associated with an OEM vendor.
127board_config_mk := \
128	$(strip $(wildcard \
129		$(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/BoardConfig.mk \
130		$(shell test -d device && find device -maxdepth 4 -path '*/$(TARGET_DEVICE)/BoardConfig.mk') \
131		$(shell test -d vendor && find vendor -maxdepth 4 -path '*/$(TARGET_DEVICE)/BoardConfig.mk') \
132	))
133ifeq ($(board_config_mk),)
134  $(error No config file found for TARGET_DEVICE $(TARGET_DEVICE))
135endif
136ifneq ($(words $(board_config_mk)),1)
137  $(error Multiple board config files for TARGET_DEVICE $(TARGET_DEVICE): $(board_config_mk))
138endif
139include $(board_config_mk)
140ifeq ($(TARGET_ARCH),)
141  $(error TARGET_ARCH not defined by board config: $(board_config_mk))
142endif
143TARGET_DEVICE_DIR := $(patsubst %/,%,$(dir $(board_config_mk)))
144board_config_mk :=
145
146# "ro.product.cpu.abilist" is a comma separated list of ABIs (in order
147# of preference) that the target supports. If a TARGET_CPU_ABI_LIST
148# is specified by the board configuration, we use that. If not, we
149# build a list out of the TARGET_CPU_ABIs specified by the config.
150ifeq (,$(TARGET_CPU_ABI_LIST))
151  TARGET_CPU_ABI_LIST := $(TARGET_CPU_ABI)
152  ifneq (,$(TARGET_CPU_ABI2))
153    TARGET_CPU_ABI_LIST += ,$(TARGET_CPU_ABI2)
154  endif
155  ifneq (,$(TARGET_2ND_CPU_ABI))
156    TARGET_CPU_ABI_LIST += ,$(TARGET_2ND_CPU_ABI)
157  endif
158  ifneq (,$(TARGET_2ND_CPU_ABI2))
159    TARGET_CPU_ABI_LIST += ,$(TARGET_2ND_CPU_ABI2)
160  endif
161
162  # Strip whitespace from the ABI list string.
163  empty :=
164  space := $(empty) $(empty)
165  TARGET_CPU_ABI_LIST := $(subst $(space),,$(TARGET_CPU_ABI_LIST))
166endif
167
168# ---------------------------------------------------------------
169# Set up configuration for target machine.
170# The following must be set:
171# 		TARGET_OS = { linux }
172# 		TARGET_ARCH = { arm | x86 | mips }
173
174TARGET_OS := linux
175# TARGET_ARCH should be set by BoardConfig.mk and will be checked later
176
177# the target build type defaults to release
178ifneq ($(TARGET_BUILD_TYPE),debug)
179TARGET_BUILD_TYPE := release
180endif
181
182# ---------------------------------------------------------------
183# figure out the output directories
184
185ifeq (,$(strip $(OUT_DIR)))
186ifeq (,$(strip $(OUT_DIR_COMMON_BASE)))
187OUT_DIR := $(TOPDIR)out
188else
189OUT_DIR := $(OUT_DIR_COMMON_BASE)/$(notdir $(PWD))
190endif
191endif
192
193DEBUG_OUT_DIR := $(OUT_DIR)/debug
194
195# Move the host or target under the debug/ directory
196# if necessary.
197TARGET_OUT_ROOT_release := $(OUT_DIR)/target
198TARGET_OUT_ROOT_debug := $(DEBUG_OUT_DIR)/target
199TARGET_OUT_ROOT := $(TARGET_OUT_ROOT_$(TARGET_BUILD_TYPE))
200
201HOST_OUT_ROOT_release := $(OUT_DIR)/host
202HOST_OUT_ROOT_debug := $(DEBUG_OUT_DIR)/host
203HOST_OUT_ROOT := $(HOST_OUT_ROOT_$(HOST_BUILD_TYPE))
204
205HOST_OUT_release := $(HOST_OUT_ROOT_release)/$(HOST_OS)-$(HOST_ARCH)
206HOST_OUT_debug := $(HOST_OUT_ROOT_debug)/$(HOST_OS)-$(HOST_ARCH)
207HOST_OUT := $(HOST_OUT_$(HOST_BUILD_TYPE))
208
209BUILD_OUT := $(OUT_DIR)/host/$(BUILD_OS)-$(BUILD_ARCH)
210
211TARGET_PRODUCT_OUT_ROOT := $(TARGET_OUT_ROOT)/product
212
213TARGET_COMMON_OUT_ROOT := $(TARGET_OUT_ROOT)/common
214HOST_COMMON_OUT_ROOT := $(HOST_OUT_ROOT)/common
215
216PRODUCT_OUT := $(TARGET_PRODUCT_OUT_ROOT)/$(TARGET_DEVICE)
217
218OUT_DOCS := $(TARGET_COMMON_OUT_ROOT)/docs
219
220BUILD_OUT_EXECUTABLES := $(BUILD_OUT)/bin
221
222HOST_OUT_EXECUTABLES := $(HOST_OUT)/bin
223HOST_OUT_SHARED_LIBRARIES := $(HOST_OUT)/lib
224HOST_OUT_JAVA_LIBRARIES := $(HOST_OUT)/framework
225HOST_OUT_SDK_ADDON := $(HOST_OUT)/sdk_addon
226
227HOST_OUT_INTERMEDIATES := $(HOST_OUT)/obj
228HOST_OUT_HEADERS := $(HOST_OUT_INTERMEDIATES)/include
229HOST_OUT_INTERMEDIATE_LIBRARIES := $(HOST_OUT_INTERMEDIATES)/lib
230HOST_OUT_NOTICE_FILES := $(HOST_OUT_INTERMEDIATES)/NOTICE_FILES
231HOST_OUT_COMMON_INTERMEDIATES := $(HOST_COMMON_OUT_ROOT)/obj
232HOST_OUT_FAKE := $(HOST_OUT)/fake_packages
233
234HOST_OUT_GEN := $(HOST_OUT)/gen
235HOST_OUT_COMMON_GEN := $(HOST_COMMON_OUT_ROOT)/gen
236
237TARGET_OUT_INTERMEDIATES := $(PRODUCT_OUT)/obj
238TARGET_OUT_HEADERS := $(TARGET_OUT_INTERMEDIATES)/include
239TARGET_OUT_INTERMEDIATE_LIBRARIES := $(TARGET_OUT_INTERMEDIATES)/lib
240TARGET_OUT_COMMON_INTERMEDIATES := $(TARGET_COMMON_OUT_ROOT)/obj
241
242TARGET_OUT_GEN := $(PRODUCT_OUT)/gen
243TARGET_OUT_COMMON_GEN := $(TARGET_COMMON_OUT_ROOT)/gen
244
245TARGET_OUT := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_SYSTEM)
246TARGET_OUT_EXECUTABLES := $(TARGET_OUT)/bin
247TARGET_OUT_OPTIONAL_EXECUTABLES := $(TARGET_OUT)/xbin
248ifneq ($(filter %64,$(TARGET_ARCH)),)
249# /system/lib always contains 32-bit libraries,
250# and /system/lib64 (if present) always contains 64-bit libraries.
251TARGET_OUT_SHARED_LIBRARIES := $(TARGET_OUT)/lib64
252else
253TARGET_OUT_SHARED_LIBRARIES := $(TARGET_OUT)/lib
254endif
255TARGET_OUT_JAVA_LIBRARIES := $(TARGET_OUT)/framework
256TARGET_OUT_APPS := $(TARGET_OUT)/app
257TARGET_OUT_APPS_PRIVILEGED := $(TARGET_OUT)/priv-app
258TARGET_OUT_KEYLAYOUT := $(TARGET_OUT)/usr/keylayout
259TARGET_OUT_KEYCHARS := $(TARGET_OUT)/usr/keychars
260TARGET_OUT_ETC := $(TARGET_OUT)/etc
261TARGET_OUT_NOTICE_FILES := $(TARGET_OUT_INTERMEDIATES)/NOTICE_FILES
262TARGET_OUT_FAKE := $(PRODUCT_OUT)/fake_packages
263
264# Out for TARGET_2ND_ARCH
265TARGET_2ND_ARCH_VAR_PREFIX := 2ND_
266TARGET_2ND_ARCH_MODULE_SUFFIX := _32
267$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES := $(PRODUCT_OUT)/obj_$(TARGET_2ND_ARCH)
268$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES := $($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES)/lib
269$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES := $(TARGET_OUT)/lib
270$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_EXECUTABLES := $(TARGET_OUT_EXECUTABLES)
271$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_APPS := $(TARGET_OUT_APPS)
272$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_APPS_PRIVILEGED := $(TARGET_OUT_APPS_PRIVILEGED)
273
274TARGET_OUT_DATA := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_DATA)
275TARGET_OUT_DATA_EXECUTABLES := $(TARGET_OUT_EXECUTABLES)
276TARGET_OUT_DATA_SHARED_LIBRARIES := $(TARGET_OUT_SHARED_LIBRARIES)
277TARGET_OUT_DATA_JAVA_LIBRARIES := $(TARGET_OUT_DATA)/framework
278TARGET_OUT_DATA_APPS := $(TARGET_OUT_DATA)/app
279TARGET_OUT_DATA_KEYLAYOUT := $(TARGET_OUT_KEYLAYOUT)
280TARGET_OUT_DATA_KEYCHARS := $(TARGET_OUT_KEYCHARS)
281TARGET_OUT_DATA_ETC := $(TARGET_OUT_ETC)
282TARGET_OUT_DATA_NATIVE_TESTS := $(TARGET_OUT_DATA)/nativetest
283TARGET_OUT_DATA_FAKE := $(TARGET_OUT_DATA)/fake_packages
284
285$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_DATA_EXECUTABLES := $(TARGET_OUT_DATA_EXECUTABLES)
286$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_DATA_SHARED_LIBRARIES := $($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES)
287$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_DATA_APPS := $(TARGET_OUT_DATA_APPS)
288
289TARGET_OUT_CACHE := $(PRODUCT_OUT)/cache
290
291TARGET_OUT_VENDOR := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_VENDOR)
292TARGET_OUT_VENDOR_EXECUTABLES := $(TARGET_OUT_VENDOR)/bin
293TARGET_OUT_VENDOR_OPTIONAL_EXECUTABLES := $(TARGET_OUT_VENDOR)/xbin
294ifneq ($(filter %64,$(TARGET_ARCH)),)
295TARGET_OUT_VENDOR_SHARED_LIBRARIES := $(TARGET_OUT_VENDOR)/lib64
296else
297TARGET_OUT_VENDOR_SHARED_LIBRARIES := $(TARGET_OUT_VENDOR)/lib
298endif
299TARGET_OUT_VENDOR_JAVA_LIBRARIES := $(TARGET_OUT_VENDOR)/framework
300TARGET_OUT_VENDOR_APPS := $(TARGET_OUT_VENDOR)/app
301TARGET_OUT_VENDOR_ETC := $(TARGET_OUT_VENDOR)/etc
302
303$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_EXECUTABLES := $(TARGET_OUT_VENDOR_EXECUTABLES)
304$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES := $(TARGET_OUT_VENDOR)/lib
305$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_APPS := $(TARGET_OUT_VENDOR_APPS)
306
307TARGET_OUT_UNSTRIPPED := $(PRODUCT_OUT)/symbols
308TARGET_OUT_EXECUTABLES_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)/system/bin
309TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)/system/lib
310TARGET_ROOT_OUT_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)
311TARGET_ROOT_OUT_SBIN_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)/sbin
312TARGET_ROOT_OUT_BIN_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)/bin
313
314TARGET_ROOT_OUT := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_ROOT)
315TARGET_ROOT_OUT_BIN := $(TARGET_ROOT_OUT)/bin
316TARGET_ROOT_OUT_SBIN := $(TARGET_ROOT_OUT)/sbin
317TARGET_ROOT_OUT_ETC := $(TARGET_ROOT_OUT)/etc
318TARGET_ROOT_OUT_USR := $(TARGET_ROOT_OUT)/usr
319
320TARGET_RECOVERY_OUT := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_RECOVERY)
321TARGET_RECOVERY_ROOT_OUT := $(TARGET_RECOVERY_OUT)/root
322
323TARGET_SYSLOADER_OUT := $(PRODUCT_OUT)/sysloader
324TARGET_SYSLOADER_ROOT_OUT := $(TARGET_SYSLOADER_OUT)/root
325TARGET_SYSLOADER_SYSTEM_OUT := $(TARGET_SYSLOADER_OUT)/root/system
326
327TARGET_INSTALLER_OUT := $(PRODUCT_OUT)/installer
328TARGET_INSTALLER_DATA_OUT := $(TARGET_INSTALLER_OUT)/data
329TARGET_INSTALLER_ROOT_OUT := $(TARGET_INSTALLER_OUT)/root
330TARGET_INSTALLER_SYSTEM_OUT := $(TARGET_INSTALLER_OUT)/root/system
331
332TARGET_FACTORY_RAMDISK_OUT := $(PRODUCT_OUT)/factory_ramdisk
333
334COMMON_MODULE_CLASSES := TARGET-NOTICE_FILES HOST-NOTICE_FILES HOST-JAVA_LIBRARIES
335
336ifeq (,$(strip $(DIST_DIR)))
337  DIST_DIR := $(OUT_DIR)/dist
338endif
339
340ifeq ($(PRINT_BUILD_CONFIG),)
341PRINT_BUILD_CONFIG := true
342endif
343