envsetup.mk revision 2cd8a74b2d380e9c01efb922b57c9293738adbda
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) 61ifdef 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# HOST_ARCH 71ifneq (,$(findstring x86_64,$(UNAME))) 72 HOST_ARCH := x86_64 73 HOST_2ND_ARCH := x86 74 HOST_IS_64_BIT := true 75else 76ifneq (,$(findstring x86,$(UNAME))) 77$(error Building on a 32-bit x86 host is not supported: $(UNAME)!) 78endif 79endif 80 81BUILD_ARCH := $(HOST_ARCH) 82BUILD_2ND_ARCH := $(HOST_2ND_ARCH) 83 84ifeq ($(HOST_ARCH),) 85$(error Unable to determine HOST_ARCH from uname -sm: $(UNAME)!) 86endif 87 88# the host build defaults to release, and it must be release or debug 89ifeq ($(HOST_BUILD_TYPE),) 90HOST_BUILD_TYPE := release 91endif 92 93ifneq ($(HOST_BUILD_TYPE),release) 94ifneq ($(HOST_BUILD_TYPE),debug) 95$(error HOST_BUILD_TYPE must be either release or debug, not '$(HOST_BUILD_TYPE)') 96endif 97endif 98 99# We don't want to move all the prebuilt host tools to a $(HOST_OS)-x86_64 dir. 100HOST_PREBUILT_ARCH := x86 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_PREBUILT_ARCH) 107endif 108 109# TARGET_COPY_OUT_* are all relative to the staging directory, ie PRODUCT_OUT. 110# Define them here so they can be used in product config files. 111TARGET_COPY_OUT_SYSTEM := system 112TARGET_COPY_OUT_DATA := data 113TARGET_COPY_OUT_OEM := oem 114TARGET_COPY_OUT_ROOT := root 115TARGET_COPY_OUT_RECOVERY := recovery 116########################################### 117# Define TARGET_COPY_OUT_VENDOR to a placeholder, for at this point 118# we don't know if the device wants to build a separate vendor.img 119# or just build vendor stuff into system.img. 120# A device can set up TARGET_COPY_OUT_VENDOR to "vendor" in its 121# BoardConfig.mk. 122# We'll substitute with the real value after loading BoardConfig.mk. 123_vendor_path_placeholder := ||VENDOR-PATH-PH|| 124TARGET_COPY_OUT_VENDOR := $(_vendor_path_placeholder) 125########################################### 126 127# Read the product specs so we can get TARGET_DEVICE and other 128# variables that we need in order to locate the output files. 129include $(BUILD_SYSTEM)/product_config.mk 130 131build_variant := $(filter-out eng user userdebug,$(TARGET_BUILD_VARIANT)) 132ifneq ($(build_variant)-$(words $(TARGET_BUILD_VARIANT)),-1) 133$(warning bad TARGET_BUILD_VARIANT: $(TARGET_BUILD_VARIANT)) 134$(error must be empty or one of: eng user userdebug) 135endif 136 137# Build host as 32-bit for SDK build. 138ifneq ($(filter $(MAKECMDGOALS),win_sdk sdk),) 139HOST_PREFER_32_BIT := true 140endif 141ifdef USE_MINGW 142# We only build sdk host tools in the MinGW windows build. 143# Build it as 32-bit as well. 144HOST_PREFER_32_BIT := true 145endif 146SDK_HOST_ARCH := x86 147 148# Boards may be defined under $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE) 149# or under vendor/*/$(TARGET_DEVICE). Search in both places, but 150# make sure only one exists. 151# Real boards should always be associated with an OEM vendor. 152board_config_mk := \ 153 $(strip $(wildcard \ 154 $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/BoardConfig.mk \ 155 $(shell test -d device && find device -maxdepth 4 -path '*/$(TARGET_DEVICE)/BoardConfig.mk') \ 156 $(shell test -d vendor && find vendor -maxdepth 4 -path '*/$(TARGET_DEVICE)/BoardConfig.mk') \ 157 )) 158ifeq ($(board_config_mk),) 159 $(error No config file found for TARGET_DEVICE $(TARGET_DEVICE)) 160endif 161ifneq ($(words $(board_config_mk)),1) 162 $(error Multiple board config files for TARGET_DEVICE $(TARGET_DEVICE): $(board_config_mk)) 163endif 164include $(board_config_mk) 165ifeq ($(TARGET_ARCH),) 166 $(error TARGET_ARCH not defined by board config: $(board_config_mk)) 167endif 168TARGET_DEVICE_DIR := $(patsubst %/,%,$(dir $(board_config_mk))) 169board_config_mk := 170 171########################################### 172# Now we can substitute with the real value of TARGET_COPY_OUT_VENDOR 173ifeq ($(TARGET_COPY_OUT_VENDOR),$(_vendor_path_placeholder)) 174TARGET_COPY_OUT_VENDOR := system/vendor 175else ifeq ($(filter vendor system/vendor,$(TARGET_COPY_OUT_VENDOR)),) 176$(error TARGET_COPY_OUT_VENDOR must be either 'vendor' or 'system/vendor', seeing '$(TARGET_COPY_OUT_VENDOR)'.) 177endif 178PRODUCT_COPY_FILES := $(subst $(_vendor_path_placeholder),$(TARGET_COPY_OUT_VENDOR),$(PRODUCT_COPY_FILES)) 179########################################### 180 181 182# --------------------------------------------------------------- 183# Set up configuration for target machine. 184# The following must be set: 185# TARGET_OS = { linux } 186# TARGET_ARCH = { arm | x86 | mips } 187 188TARGET_OS := linux 189# TARGET_ARCH should be set by BoardConfig.mk and will be checked later 190ifneq ($(filter %64,$(TARGET_ARCH)),) 191TARGET_IS_64_BIT := true 192endif 193 194# the target build type defaults to release 195ifneq ($(TARGET_BUILD_TYPE),debug) 196TARGET_BUILD_TYPE := release 197endif 198 199# --------------------------------------------------------------- 200# figure out the output directories 201 202ifeq (,$(strip $(OUT_DIR))) 203ifeq (,$(strip $(OUT_DIR_COMMON_BASE))) 204OUT_DIR := $(TOPDIR)out 205else 206OUT_DIR := $(OUT_DIR_COMMON_BASE)/$(notdir $(PWD)) 207endif 208endif 209 210DEBUG_OUT_DIR := $(OUT_DIR)/debug 211 212# Move the host or target under the debug/ directory 213# if necessary. 214TARGET_OUT_ROOT_release := $(OUT_DIR)/target 215TARGET_OUT_ROOT_debug := $(DEBUG_OUT_DIR)/target 216TARGET_OUT_ROOT := $(TARGET_OUT_ROOT_$(TARGET_BUILD_TYPE)) 217 218HOST_OUT_ROOT_release := $(OUT_DIR)/host 219HOST_OUT_ROOT_debug := $(DEBUG_OUT_DIR)/host 220HOST_OUT_ROOT := $(HOST_OUT_ROOT_$(HOST_BUILD_TYPE)) 221 222# We want to avoid two host bin directories in multilib build. 223HOST_OUT_release := $(HOST_OUT_ROOT_release)/$(HOST_OS)-$(HOST_PREBUILT_ARCH) 224HOST_OUT_debug := $(HOST_OUT_ROOT_debug)/$(HOST_OS)-$(HOST_PREBUILT_ARCH) 225HOST_OUT := $(HOST_OUT_$(HOST_BUILD_TYPE)) 226 227BUILD_OUT := $(OUT_DIR)/host/$(BUILD_OS)-$(HOST_PREBUILT_ARCH) 228 229TARGET_PRODUCT_OUT_ROOT := $(TARGET_OUT_ROOT)/product 230 231TARGET_COMMON_OUT_ROOT := $(TARGET_OUT_ROOT)/common 232HOST_COMMON_OUT_ROOT := $(HOST_OUT_ROOT)/common 233 234PRODUCT_OUT := $(TARGET_PRODUCT_OUT_ROOT)/$(TARGET_DEVICE) 235 236OUT_DOCS := $(TARGET_COMMON_OUT_ROOT)/docs 237 238BUILD_OUT_EXECUTABLES := $(BUILD_OUT)/bin 239 240HOST_OUT_EXECUTABLES := $(HOST_OUT)/bin 241HOST_OUT_SHARED_LIBRARIES := $(HOST_OUT)/lib64 242HOST_OUT_JAVA_LIBRARIES := $(HOST_OUT)/framework 243HOST_OUT_SDK_ADDON := $(HOST_OUT)/sdk_addon 244 245HOST_OUT_INTERMEDIATES := $(HOST_OUT)/obj 246HOST_OUT_HEADERS := $(HOST_OUT_INTERMEDIATES)/include 247HOST_OUT_INTERMEDIATE_LIBRARIES := $(HOST_OUT_INTERMEDIATES)/lib 248HOST_OUT_NOTICE_FILES := $(HOST_OUT_INTERMEDIATES)/NOTICE_FILES 249HOST_OUT_COMMON_INTERMEDIATES := $(HOST_COMMON_OUT_ROOT)/obj 250HOST_OUT_FAKE := $(HOST_OUT)/fake_packages 251 252HOST_OUT_GEN := $(HOST_OUT)/gen 253HOST_OUT_COMMON_GEN := $(HOST_COMMON_OUT_ROOT)/gen 254 255# Out for HOST_2ND_ARCH 256HOST_2ND_ARCH_VAR_PREFIX := 2ND_ 257HOST_2ND_ARCH_MODULE_SUFFIX := _32 258$(HOST_2ND_ARCH_VAR_PREFIX)HOST_OUT_INTERMEDIATES := $(HOST_OUT)/obj32 259$(HOST_2ND_ARCH_VAR_PREFIX)HOST_OUT_INTERMEDIATE_LIBRARIES := $($(HOST_2ND_ARCH_VAR_PREFIX)HOST_OUT_INTERMEDIATES)/lib 260$(HOST_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES := $(HOST_OUT)/lib 261$(HOST_2ND_ARCH_VAR_PREFIX)HOST_OUT_EXECUTABLES := $(HOST_OUT_EXECUTABLES) 262 263# The default host library path. 264# It always points to the path where we build libraries in the default bitness. 265ifeq ($(HOST_PREFER_32_BIT),true) 266HOST_LIBRARY_PATH := $($(HOST_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES) 267else 268HOST_LIBRARY_PATH := $(HOST_OUT_SHARED_LIBRARIES) 269endif 270 271TARGET_OUT_INTERMEDIATES := $(PRODUCT_OUT)/obj 272TARGET_OUT_HEADERS := $(TARGET_OUT_INTERMEDIATES)/include 273TARGET_OUT_INTERMEDIATE_LIBRARIES := $(TARGET_OUT_INTERMEDIATES)/lib 274TARGET_OUT_COMMON_INTERMEDIATES := $(TARGET_COMMON_OUT_ROOT)/obj 275 276TARGET_OUT_GEN := $(PRODUCT_OUT)/gen 277TARGET_OUT_COMMON_GEN := $(TARGET_COMMON_OUT_ROOT)/gen 278 279TARGET_OUT := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_SYSTEM) 280TARGET_OUT_EXECUTABLES := $(TARGET_OUT)/bin 281TARGET_OUT_OPTIONAL_EXECUTABLES := $(TARGET_OUT)/xbin 282ifeq ($(TARGET_IS_64_BIT),true) 283# /system/lib always contains 32-bit libraries, 284# and /system/lib64 (if present) always contains 64-bit libraries. 285TARGET_OUT_SHARED_LIBRARIES := $(TARGET_OUT)/lib64 286else 287TARGET_OUT_SHARED_LIBRARIES := $(TARGET_OUT)/lib 288endif 289TARGET_OUT_JAVA_LIBRARIES := $(TARGET_OUT)/framework 290TARGET_OUT_APPS := $(TARGET_OUT)/app 291TARGET_OUT_APPS_PRIVILEGED := $(TARGET_OUT)/priv-app 292TARGET_OUT_KEYLAYOUT := $(TARGET_OUT)/usr/keylayout 293TARGET_OUT_KEYCHARS := $(TARGET_OUT)/usr/keychars 294TARGET_OUT_ETC := $(TARGET_OUT)/etc 295TARGET_OUT_NOTICE_FILES := $(TARGET_OUT_INTERMEDIATES)/NOTICE_FILES 296TARGET_OUT_FAKE := $(PRODUCT_OUT)/fake_packages 297 298# Out for TARGET_2ND_ARCH 299TARGET_2ND_ARCH_VAR_PREFIX := $(HOST_2ND_ARCH_VAR_PREFIX) 300TARGET_2ND_ARCH_MODULE_SUFFIX := $(HOST_2ND_ARCH_MODULE_SUFFIX) 301$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES := $(PRODUCT_OUT)/obj_$(TARGET_2ND_ARCH) 302$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES := $($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES)/lib 303$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES := $(TARGET_OUT)/lib 304$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_EXECUTABLES := $(TARGET_OUT_EXECUTABLES) 305$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_APPS := $(TARGET_OUT_APPS) 306$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_APPS_PRIVILEGED := $(TARGET_OUT_APPS_PRIVILEGED) 307 308TARGET_OUT_DATA := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_DATA) 309TARGET_OUT_DATA_EXECUTABLES := $(TARGET_OUT_EXECUTABLES) 310TARGET_OUT_DATA_SHARED_LIBRARIES := $(TARGET_OUT_SHARED_LIBRARIES) 311TARGET_OUT_DATA_JAVA_LIBRARIES := $(TARGET_OUT_DATA)/framework 312TARGET_OUT_DATA_APPS := $(TARGET_OUT_DATA)/app 313TARGET_OUT_DATA_KEYLAYOUT := $(TARGET_OUT_KEYLAYOUT) 314TARGET_OUT_DATA_KEYCHARS := $(TARGET_OUT_KEYCHARS) 315TARGET_OUT_DATA_ETC := $(TARGET_OUT_ETC) 316ifeq ($(TARGET_IS_64_BIT),true) 317TARGET_OUT_DATA_NATIVE_TESTS := $(TARGET_OUT_DATA)/nativetest64 318else 319TARGET_OUT_DATA_NATIVE_TESTS := $(TARGET_OUT_DATA)/nativetest 320endif 321TARGET_OUT_DATA_FAKE := $(TARGET_OUT_DATA)/fake_packages 322 323$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_DATA_EXECUTABLES := $(TARGET_OUT_DATA_EXECUTABLES) 324$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_DATA_SHARED_LIBRARIES := $($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES) 325$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_DATA_APPS := $(TARGET_OUT_DATA_APPS) 326$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_DATA_NATIVE_TESTS := $(TARGET_OUT_DATA)/nativetest 327 328TARGET_OUT_CACHE := $(PRODUCT_OUT)/cache 329 330TARGET_OUT_VENDOR := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_VENDOR) 331TARGET_OUT_VENDOR_EXECUTABLES := $(TARGET_OUT_VENDOR)/bin 332TARGET_OUT_VENDOR_OPTIONAL_EXECUTABLES := $(TARGET_OUT_VENDOR)/xbin 333ifeq ($(TARGET_IS_64_BIT),true) 334TARGET_OUT_VENDOR_SHARED_LIBRARIES := $(TARGET_OUT_VENDOR)/lib64 335else 336TARGET_OUT_VENDOR_SHARED_LIBRARIES := $(TARGET_OUT_VENDOR)/lib 337endif 338TARGET_OUT_VENDOR_JAVA_LIBRARIES := $(TARGET_OUT_VENDOR)/framework 339TARGET_OUT_VENDOR_APPS := $(TARGET_OUT_VENDOR)/app 340TARGET_OUT_VENDOR_ETC := $(TARGET_OUT_VENDOR)/etc 341 342$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_EXECUTABLES := $(TARGET_OUT_VENDOR_EXECUTABLES) 343$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES := $(TARGET_OUT_VENDOR)/lib 344$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_APPS := $(TARGET_OUT_VENDOR_APPS) 345 346TARGET_OUT_OEM := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_OEM) 347TARGET_OUT_OEM_EXECUTABLES := $(TARGET_OUT_OEM)/bin 348ifneq ($(filter %64,$(TARGET_ARCH)),) 349TARGET_OUT_OEM_SHARED_LIBRARIES := $(TARGET_OUT_OEM)/lib64 350else 351TARGET_OUT_OEM_SHARED_LIBRARIES := $(TARGET_OUT_OEM)/lib 352endif 353# We don't expect Java libraries in the oem.img. 354# TARGET_OUT_OEM_JAVA_LIBRARIES:= $(TARGET_OUT_OEM)/framework 355TARGET_OUT_OEM_APPS := $(TARGET_OUT_OEM)/app 356TARGET_OUT_OEM_ETC := $(TARGET_OUT_OEM)/etc 357 358$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_OEM_EXECUTABLES := $(TARGET_OUT_OEM_EXECUTABLES) 359$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_OEM_SHARED_LIBRARIES := $(TARGET_OUT_OEM)/lib 360$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_OEM_APPS := $(TARGET_OUT_OEM_APPS) 361 362TARGET_OUT_UNSTRIPPED := $(PRODUCT_OUT)/symbols 363TARGET_OUT_EXECUTABLES_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)/system/bin 364TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)/system/lib 365TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)/$(TARGET_COPY_OUT_VENDOR)/lib 366TARGET_ROOT_OUT_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED) 367TARGET_ROOT_OUT_SBIN_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)/sbin 368TARGET_ROOT_OUT_BIN_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPED)/bin 369 370TARGET_ROOT_OUT := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_ROOT) 371TARGET_ROOT_OUT_BIN := $(TARGET_ROOT_OUT)/bin 372TARGET_ROOT_OUT_SBIN := $(TARGET_ROOT_OUT)/sbin 373TARGET_ROOT_OUT_ETC := $(TARGET_ROOT_OUT)/etc 374TARGET_ROOT_OUT_USR := $(TARGET_ROOT_OUT)/usr 375 376TARGET_RECOVERY_OUT := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_RECOVERY) 377TARGET_RECOVERY_ROOT_OUT := $(TARGET_RECOVERY_OUT)/root 378 379TARGET_SYSLOADER_OUT := $(PRODUCT_OUT)/sysloader 380TARGET_SYSLOADER_ROOT_OUT := $(TARGET_SYSLOADER_OUT)/root 381TARGET_SYSLOADER_SYSTEM_OUT := $(TARGET_SYSLOADER_OUT)/root/system 382 383TARGET_INSTALLER_OUT := $(PRODUCT_OUT)/installer 384TARGET_INSTALLER_DATA_OUT := $(TARGET_INSTALLER_OUT)/data 385TARGET_INSTALLER_ROOT_OUT := $(TARGET_INSTALLER_OUT)/root 386TARGET_INSTALLER_SYSTEM_OUT := $(TARGET_INSTALLER_OUT)/root/system 387 388COMMON_MODULE_CLASSES := TARGET-NOTICE_FILES HOST-NOTICE_FILES HOST-JAVA_LIBRARIES 389 390ifeq (,$(strip $(DIST_DIR))) 391 DIST_DIR := $(OUT_DIR)/dist 392endif 393 394ifeq ($(PRINT_BUILD_CONFIG),) 395PRINT_BUILD_CONFIG := true 396endif 397