1ifneq ($(filter true% %true,$(BUILD_EMULATOR)$(BUILD_STANDALONE_EMULATOR)),) 2 3LOCAL_PATH:= $(call my-dir) 4 5# determine the host tag to use 6QEMU_HOST_TAG := $(HOST_PREBUILT_TAG) 7ifneq ($(USE_MINGW),) 8 QEMU_HOST_TAG := windows 9endif 10 11# This defines EMULATOR_BUILD_64BITS to indicate that 64-bit binaries 12# must be generated by the build system. For now, only do it for 13# Linux and Darwin, since we the sources do not compile with Mingw-w64 14# yet due to differing procedure call ABI conventions. 15EMULATOR_BUILD_64BITS := $(strip $(filter linux darwin,$(HOST_OS))) 16 17# Disable 64-bit build for Darwin platform builds. 18ifeq ($(HOST_OS),darwin) 19ifneq (true,$(BUILD_STANDALONE_EMULATOR)) 20EMULATOR_BUILD_64BITS := $(strip $(empty)) 21endif # BUILD_STANDALONE_EMULATOR != true 22endif # HOST_OS == darwin 23 24# A function that includes a file only if 32-bit binaries are necessary. 25# This is always the case, but later used with include-if-bitness-64. 26# $1: Build file to include. 27include-if-bitness-32 = $(eval include $1) 28 29# A function that includes a file only of EMULATOR_BUILD_64BITS is not empty. 30# $1: Build file to include. 31include-if-bitness-64 = $(if $(strip $(EMULATOR_BUILD_64BITS)),$(eval include $1)) 32 33# determine the location of platform-specific directories 34# 35CONFIG_DIRS := \ 36 $(LOCAL_PATH)/android/config/$(QEMU_HOST_TAG) 37 38ifeq ($(BUILD_STANDALONE_EMULATOR),true) 39 CONFIG_DIRS := $(LOCAL_PATH)/objs $(CONFIG_DIRS) 40endif 41 42CONFIG_INCLUDES := $(CONFIG_DIRS:%=-I%) 43 44MY_CC := $(HOST_CC) 45MY_CXX := $(HOST_CXX) 46MY_LD := $(HOST_LD) 47MY_AR := $(HOST_AR) 48 49MY_CFLAGS := $(CONFIG_INCLUDES) -g -falign-functions=0 50ifeq ($(BUILD_DEBUG_EMULATOR),true) 51 MY_CFLAGS += -O0 52else 53 MY_CFLAGS += -O2 54endif 55 56# Generate position-independent binaries. Don't add -fPIC when targetting 57# Windows, because newer toolchain complain loudly about it, since all 58# Windows code is position-independent. 59ifneq (windows,$(HOST_OS)) 60 MY_CFLAGS += -fPIC 61endif 62 63MY_CFLAGS32 := 64MY_CFLAGS64 := 65 66MY_LDLIBS := 67MY_LDLIBS32 := 68MY_LDLIBS64 := 69 70MY_LDFLAGS := 71MY_LDFLAGS32 := 72MY_LDFLAGS64 := 73 74ifeq ($(HOST_OS),freebsd) 75 MY_CFLAGS += -I /usr/local/include 76endif 77 78ifeq ($(HOST_OS),windows) 79 # we need Win32 features that are available since Windows 2000 Professional/Server (NT 5.0) 80 MY_CFLAGS += -DWINVER=0x501 81 MY_CFLAGS += -D_WIN32 82 # LARGEADDRESSAWARE gives more address space to 32-bit process 83 MY_LDFLAGS32 += -Xlinker --large-address-aware 84 ifneq ($(HOST_IS_64_BIT),) 85 # Microsoft 64-bit compiler define both _WIN32 and _WIN64 86 MY_CFLAGS += -D_WIN64 87 # amd64-mingw32msvc- toolchain still name it vfw32. May change it once amd64-mingw32msvc- 88 # is stabilized 89 MY_LDLIBS += -lvfw32 90 else 91 MY_LDLIBS += -lvfw32 92 endif 93endif 94 95ifeq ($(HOST_ARCH),ppc) 96 MY_CFLAGS += -D__powerpc__ 97endif 98 99ifeq ($(HOST_OS),darwin) 100 MY_CFLAGS += -D_DARWIN_C_SOURCE=1 101 ifneq ($(host_toolchain_header),) 102 MY_CFLAGS += -isystem $(host_toolchain_header) 103 else 104 ifneq (,$(mac_sdk_root)) 105 MY_CFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) -DMACOSX_DEPLOYMENT_TARGET=$(mac_sdk_version) 106 MY_LDLIBS += -isysroot $(mac_sdk_root) -Wl,-syslibroot,$(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) 107 108 # Clang complains about this flag being not useful anymore. 109 MY_CFLAGS := $(filter-out -falign-functions=0,$(MY_CFLAGS)) 110 endif 111 endif 112endif 113 114# NOTE: The following definitions are only used by the standalone build. 115MY_EXEEXT := 116MY_DLLEXT := .so 117ifeq ($(HOST_OS),windows) 118 MY_EXEEXT := .exe 119 MY_DLLEXT := .dll 120endif 121ifeq ($(HOST_OS),darwin) 122 MY_DLLEXT := .dylib 123endif 124 125# Some CFLAGS below use -Wno-missing-field-initializers but this is not 126# supported on GCC 3.x which is still present under Cygwin. 127# Find out by probing GCC for support of this flag. Note that the test 128# itself only works on GCC 4.x anyway. 129GCC_W_NO_MISSING_FIELD_INITIALIZERS := -Wno-missing-field-initializers 130ifeq ($(HOST_OS),windows) 131 ifeq (,$(shell gcc -Q --help=warnings 2>/dev/null | grep missing-field-initializers)) 132 $(info emulator: Ignoring unsupported GCC flag $(GCC_W_NO_MISSING_FIELD_INITIALIZERS)) 133 GCC_W_NO_MISSING_FIELD_INITIALIZERS := 134 endif 135endif 136 137# BUILD_STANDALONE_EMULATOR is only defined when building with 138# the android-rebuild.sh script. The script will also provide 139# adequate values for HOST_CC 140# 141ifneq ($(BUILD_STANDALONE_EMULATOR),true) 142 # On Linux, use our custom 32-bit host toolchain (unless HOST_IS_64_BIT=true) 143 # which contains the relevant headers and 32-bit libraries for audio (The host 64-bit 144 # Lucid doesn't provide these anymore, only their 64-bit versions). 145 ifeq ($(HOST_OS),linux) 146 HOST_SDK_TOOLCHAIN_PREFIX := prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/bin/x86_64-linux- 147 ifeq (,$(strip $(wildcard $(HOST_SDK_TOOLCHAIN_PREFIX)gcc))) 148 # fallback to the previous host toolchain if new one isn't available 149 HOST_SDK_TOOLCHAIN_PREFIX := prebuilts/tools/gcc-sdk/ 150 endif 151 # Don't do anything if the toolchain is not there 152 ifneq (,$(strip $(wildcard $(HOST_SDK_TOOLCHAIN_PREFIX)gcc))) 153 MY_CC := $(HOST_SDK_TOOLCHAIN_PREFIX)gcc 154 MY_CXX := $(HOST_SDK_TOOLCHAIN_PREFIX)g++ 155 MY_AR := $(HOST_SDK_TOOLCHAIN_PREFIX)ar 156 endif # $(HOST_SDK_TOOLCHAIN_PREFIX)gcc exists 157 endif # HOST_OS == linux 158 159 ifneq ($(USE_CCACHE),) 160 ccache := prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache 161 ccache := $(strip $(wildcard $(ccache))) 162 ifneq ($(ccache),$(firstword $(MY_CC))) 163 MY_CC := $(ccache) $(MY_CC) 164 MY_CXX := $(ccache) $(MY_CXX) 165 endif 166 ccache := 167 endif 168endif 169 170 171ifneq ($(combo_target)$(TARGET_SIMULATOR),HOST_true) 172 ifneq ($(HOST_IS_64_BIT),) 173 MY_CFLAGS += -m64 174 MY_LDFLAGS += -m64 175 else 176 ifneq ($(HOST_ARCH),x86_64) 177 MY_CFLAGS += -m32 178 MY_LDFLAGS += -m32 179 endif 180 endif 181 182 ifneq ($(BUILD_HOST_static),) 183 MY_LDLIBS += -static 184 endif 185endif 186 187ifeq ($(HOST_OS)-$(BUILD_STANDALONE_EMULATOR),windows-true) 188 # Ensure that printf() et al use GNU printf format specifiers as required 189 # by QEMU. This is important when using the newer Mingw64 cross-toolchain. 190 # See http://sourceforge.net/apps/trac/mingw-w64/wiki/gnu%20printf 191 MY_CFLAGS += -D__USE_MINGW_ANSI_STDIO=1 192endif 193 194# Enable warning, except those related to missing field initializers 195# (the QEMU coding style loves using these). 196# 197MY_CFLAGS += -Wall $(GCC_W_NO_MISSING_FIELD_INITIALIZERS) 198 199# When using clang and ccache, disable the spammy warnings about unused 200# parameters during compilation, and re-enable colored output. 201# 202# See http://petereisentraut.blogspot.fr/2011/05/ccache-and-clang.html 203ifneq (,$(filter %ccache,$(MY_CC))) 204 ifneq (,$(filter LLVM,$(shell $(HOST_CC) -v 2>&1))) 205 MY_CFLAGS := -Qunused-arguments -fcolor-diagnostics $(MY_CFLAGS) 206 endif 207endif 208 209# Needed to build block.c on Linux/x86_64. 210MY_CFLAGS += -D_GNU_SOURCE=1 211 212MY_CFLAGS += -I$(LOCAL_PATH)/include 213 214# Need to include "qapi-types.h" and other auto-generated files from 215# android-configure.sh 216MY_CFLAGS += -I$(LOCAL_PATH)/qapi-auto-generated 217 218ifneq (true,$(BUILD_STANDALONE_EMULATOR)) 219my-host-tool = $(MY_$1) 220else 221my-host-tool = $(if $(strip $(LOCAL_HOST_BUILD)),$(BUILD_$1),$(MY_$1)) 222endif 223 224# A useful function that can be used to start the declaration of a host 225# module. Avoids repeating the same stuff again and again. 226# Usage: 227# 228# $(call start-emulator-library, <module-name>) 229# 230# ... declarations 231# 232# $(call end-emulator-library) 233# 234start-emulator-library = \ 235 $(eval include $(CLEAR_VARS)) \ 236 $(eval LOCAL_NO_DEFAULT_COMPILER_FLAGS := true) \ 237 $(eval LOCAL_MODULE := $1) \ 238 $(eval LOCAL_MODULE_CLASS := STATIC_LIBRARIES) \ 239 $(eval LOCAL_MODULE_BITS := 32) 240 241start-emulator64-library = \ 242 $(call start-emulator-library, $1) \ 243 $(eval LOCAL_MODULE_BITS := 64) 244 245# Used with start-emulator-library 246end-emulator-library = \ 247 $(eval $(end-emulator-module-ev)) \ 248 $(call include-if-bitness-$(LOCAL_MODULE_BITS), $(BUILD_HOST_STATIC_LIBRARY)) 249 250# A variant of start-emulator-library to start the definition of a host 251# program instead. Use with end-emulator-program 252start-emulator-program = \ 253 $(call start-emulator-library,$1) \ 254 $(eval LOCAL_MODULE_CLASS := EXECUTABLES) 255 256start-emulator64-program = \ 257 $(call start-emulator-program, $1) \ 258 $(eval LOCAL_MODULE_BITS := 64) 259 260# A varient of end-emulator-library for host programs instead 261end-emulator-program = \ 262 $(eval LOCAL_LDLIBS += $(QEMU_SYSTEM_LDLIBS)) \ 263 $(eval $(end-emulator-module-ev)) \ 264 $(call include-if-bitness-$(LOCAL_MODULE_BITS), $(BUILD_HOST_EXECUTABLE)) 265 266define end-emulator-module-ev 267LOCAL_CC := $$(call my-host-tool,CC) 268LOCAL_CXX := $$(call my-host-tool,CXX) 269LOCAL_AR := $$(call my-host-tool,AR) 270LOCAL_LD := $$(call my-host-tool,LD) 271 272LOCAL_CFLAGS := \ 273 $$(call my-host-tool,CFLAGS$$(LOCAL_MODULE_BITS)) \ 274 $$(call my-host-tool,CFLAGS) \ 275 $$(LOCAL_CFLAGS) 276 277LOCAL_LDFLAGS := \ 278 $$(call my-host-tool,LDFLAGS$$(LOCAL_MODULE_BITS)) \ 279 $$(call my-host-tool,LDFLAGS) \ 280 $$(LOCAL_LDFLAGS) 281 282LOCAL_LDLIBS := \ 283 $$(LOCAL_LDLIBS) \ 284 $$(call my-host-tool,LDLIBS) \ 285 $$(call my-host-tool,LDLIBS$$(LOCAL_MODULE_BITS)) 286 287# Ensure only one of -m32 or -m64 is being used and place it first. 288LOCAL_CFLAGS := \ 289 -m$$(LOCAL_MODULE_BITS) \ 290 $$(filter-out -m32 -m64, $$(LOCAL_CFLAGS)) 291 292LOCAL_LDFLAGS := \ 293 -m$$(LOCAL_MODULE_BITS) \ 294 $$(filter-out -m32 -m64, $$(LOCAL_LDFLAGS)) 295 296endef 297 298# The common libraries 299# 300QEMU_SYSTEM_LDLIBS := -lm 301ifeq ($(HOST_OS),windows) 302 QEMU_SYSTEM_LDLIBS += -mwindows -mconsole 303endif 304 305ifeq ($(HOST_OS),freebsd) 306 QEMU_SYSTEM_LDLIBS += -L/usr/local/lib -lpthread -lX11 -lutil 307endif 308 309ifeq ($(HOST_OS),linux) 310 QEMU_SYSTEM_LDLIBS += -lutil -lrt 311endif 312 313ifeq ($(HOST_OS),windows) 314 # amd64-mingw32msvc- toolchain still name it ws2_32. May change it once amd64-mingw32msvc- 315 # is stabilized 316 QEMU_SYSTEM_LDLIBS += -lwinmm -lws2_32 -liphlpapi 317else 318 QEMU_SYSTEM_LDLIBS += -lpthread 319endif 320 321ifeq ($(HOST_OS),darwin) 322 QEMU_SYSTEM_LDLIBS += -Wl,-framework,Cocoa,-framework,QTKit,-framework,CoreVideo 323 324 # Required to avoid compilation errors when targetting i386 with newer 325 # XCode toolchain. 326 MY_LDFLAGS32 += -Wl,-read_only_relocs,suppress 327 328 # SDK 10.6+ doesn't have __dyld_func_lookup anymore. Dynamic library lookup symbols 329 # are instead resolved at runtime 330 OSX_VERSION_MAJOR := $(shell echo $(mac_sdk_version) | cut -d . -f 2) 331 OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6 := $(shell [ $(OSX_VERSION_MAJOR) -ge 6 ] && echo true) 332 ifeq ($(OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6),true) 333 QEMU_SYSTEM_LDLIBS += -undefined dynamic_lookup 334 endif 335endif 336 337# Build libext4_utils and related modules/ 338include $(LOCAL_PATH)/distrib/zlib-1.2.8/sources.make 339include $(LOCAL_PATH)/distrib/libsparse/sources.mk 340include $(LOCAL_PATH)/distrib/libselinux/sources.mk 341include $(LOCAL_PATH)/distrib/ext4_utils/sources.mk 342 343include $(LOCAL_PATH)/Makefile.common 344 345ifeq ($(HOST_OS),windows) 346 # on Windows, link the icon file as well into the executable 347 # unfortunately, our build system doesn't help us much, so we need 348 # to use some weird pathnames to make this work... 349 350 # Locate windres executable 351 WINDRES := windres 352 ifneq ($(USE_MINGW),) 353 # When building the Windows emulator under Linux, use the MinGW one 354 WINDRES := i586-mingw32msvc-windres 355 endif 356 357 # Usage: $(eval $(call insert-windows-icon)) 358 define insert-windows-icon 359 LOCAL_PREBUILT_OBJ_FILES += images/emulator_icon.o 360 endef 361 362# This seems to be the only way to add an object file that was not generated from 363# a C/C++/Java source file to our build system. and very unfortunately, 364# $(TOPDIR)/$(LOCALPATH) will always be prepended to this value, which forces 365# us to put the object file in the source directory. 366$(LOCAL_PATH)/images/emulator_icon.o: $(LOCAL_PATH)/images/android_icon.rc 367 $(WINDRES) $< -I $(LOCAL_PATH)/images -o $@ 368endif 369 370# We want to build all variants of the emulator binaries. This makes 371# it easier to catch target-specific regressions during emulator development. 372EMULATOR_TARGET_ARCH := arm 373include $(LOCAL_PATH)/Makefile.target 374 375# Note: the same binary handles x86 and x86_64 376EMULATOR_TARGET_ARCH := x86 377include $(LOCAL_PATH)/Makefile.target 378 379EMULATOR_TARGET_ARCH := mips 380include $(LOCAL_PATH)/Makefile.target 381 382EMULATOR_TARGET_ARCH := arm64 383include $(LOCAL_PATH)/Makefile.qemu-launcher 384 385############################################################################## 386############################################################################## 387### 388### emulator: LAUNCHER FOR TARGET-SPECIFIC EMULATOR 389### 390### 391$(call start-emulator-program, emulator) 392 393LOCAL_SRC_FILES := android/main-emulator.c 394LOCAL_STATIC_LIBRARIES := emulator-common 395 396ifeq ($(HOST_OS),windows) 397$(eval $(call insert-windows-icon)) 398endif 399 400$(call end-emulator-program) 401 402include $(LOCAL_PATH)/Makefile.tests 403 404############################################################################## 405############################################################################## 406### 407### GPU emulation libraries 408### 409### Build directly from sources when using the standalone build. 410### 411ifeq (true,$(BUILD_STANDALONE_EMULATOR)) 412 ifeq (,$(strip $(wildcard $(EMULATOR_EMUGL_SOURCES_DIR)))) 413 $(error Cannot find GPU emulation sources directory: $(EMULATOR_EMUGL_SOURCES_DIR)) 414 endif 415 416 # TODO(digit): Remove the line below. 417 BUILD_EMULATOR_OPENGL := true 418 BUILD_EMULATOR_HOST_OPENGL := true 419 include $(EMULATOR_EMUGL_SOURCES_DIR)/Android.mk 420endif 421 422## VOILA!! 423 424endif # BUILD_EMULATOR == true || BUILD_STANDALONE_EMULATOR == true 425