blob: d25f3574a7d39dfebc94ce8a60ae2b6a5be60620 [file] [log] [blame]
ifneq ($(filter true% %true,$(BUILD_EMULATOR)$(BUILD_STANDALONE_EMULATOR)),)
LOCAL_PATH:= $(call my-dir)
# determine the host tag to use
QEMU_HOST_TAG := $(HOST_PREBUILT_TAG)
ifneq ($(USE_MINGW),)
QEMU_HOST_TAG := windows
endif
# determine the location of platform-specific directories
#
CONFIG_DIRS := \
$(LOCAL_PATH)/android/config/$(QEMU_HOST_TAG)
ifeq ($(BUILD_STANDALONE_EMULATOR),true)
CONFIG_DIRS := $(LOCAL_PATH)/objs $(CONFIG_DIRS)
endif
CONFIG_INCLUDES := $(CONFIG_DIRS:%=-I%)
MY_CC := $(HOST_CC)
MY_CXX := $(HOST_CXX)
MY_LD := $(HOST_LD)
MY_AR := $(HOST_AR)
MY_CFLAGS := $(CONFIG_INCLUDES) -O2 -g -fno-PIC -falign-functions=0 -fomit-frame-pointer
# Overwrite configuration for debug builds.
#
ifeq ($(BUILD_DEBUG_EMULATOR),true)
MY_CFLAGS := $(CONFIG_INCLUDES)
MY_CFLAGS += -O0 -g
MY_CFLAGS += -fno-PIC -falign-functions=0
endif
MY_LDLIBS :=
MY_LDFLAGS :=
ifeq ($(HOST_OS),freebsd)
MY_CFLAGS += -I /usr/local/include
endif
ifeq ($(HOST_OS),windows)
# we need Win32 features that are available since Windows 2000 Professional/Server (NT 5.0)
MY_CFLAGS += -DWINVER=0x501
MY_CFLAGS += -D_WIN32
# LARGEADDRESSAWARE gives more address space to 32-bit process
MY_LDLIBS += -Xlinker --large-address-aware
ifneq ($(HOST_IS_64_BIT),)
# Microsoft 64-bit compiler define both _WIN32 and _WIN64
MY_CFLAGS += -D_WIN64
# amd64-mingw32msvc- toolchain still name it vfw32. May change it once amd64-mingw32msvc-
# is stabilized
MY_LDLIBS += -lvfw32
else
MY_LDLIBS += -lvfw32
endif
endif
ifeq ($(HOST_ARCH),ppc)
MY_CFLAGS += -D__powerpc__
endif
ifeq ($(HOST_OS),darwin)
MY_CFLAGS += -D_DARWIN_C_SOURCE=1
ifneq ($(host_toolchain_header),)
MY_CFLAGS += -mdynamic-no-pic
MY_CFLAGS += -isystem $(host_toolchain_header)
else
ifneq (,$(mac_sdk_root))
MY_CFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) -DMACOSX_DEPLOYMENT_TARGET=$(mac_sdk_version)
MY_LDLIBS += -isysroot $(mac_sdk_root) -Wl,-syslibroot,$(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version)
# Clang complains about this flag being not useful anymore.
MY_CFLAGS := $(filter-out -falign-functions=0,$(MY_CFLAGS))
endif
endif
endif
# NOTE: The following definitions are only used by the standalone build.
MY_EXEEXT :=
MY_DLLEXT := .so
ifeq ($(HOST_OS),windows)
MY_EXEEXT := .exe
MY_DLLEXT := .dll
endif
ifeq ($(HOST_OS),darwin)
MY_DLLEXT := .dylib
endif
# Some CFLAGS below use -Wno-missing-field-initializers but this is not
# supported on GCC 3.x which is still present under Cygwin.
# Find out by probing GCC for support of this flag. Note that the test
# itself only works on GCC 4.x anyway.
GCC_W_NO_MISSING_FIELD_INITIALIZERS := -Wno-missing-field-initializers
ifeq ($(HOST_OS),windows)
ifeq (,$(shell gcc -Q --help=warnings 2>/dev/null | grep missing-field-initializers))
$(info emulator: Ignoring unsupported GCC flag $(GCC_W_NO_MISSING_FIELD_INITIALIZERS))
GCC_W_NO_MISSING_FIELD_INITIALIZERS :=
endif
endif
# BUILD_STANDALONE_EMULATOR is only defined when building with
# the android-rebuild.sh script. The script will also provide
# adequate values for HOST_CC
#
ifneq ($(BUILD_STANDALONE_EMULATOR),true)
# On Linux, use our custom 32-bit host toolchain (unless HOST_IS_64_BIT=true)
# which contains the relevant headers and 32-bit libraries for audio (The host 64-bit
# Lucid doesn't provide these anymore, only their 64-bit versions).
ifeq ($(HOST_OS),linux)
HOST_SDK_TOOLCHAIN_PREFIX := prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/bin/x86_64-linux-
ifeq (,$(strip $(wildcard $(HOST_SDK_TOOLCHAIN_PREFIX)gcc)))
# fallback to the previous host toolchain if new one isn't available
HOST_SDK_TOOLCHAIN_PREFIX := prebuilts/tools/gcc-sdk/
endif
# Don't do anything if the toolchain is not there
ifneq (,$(strip $(wildcard $(HOST_SDK_TOOLCHAIN_PREFIX)gcc)))
MY_CC := $(HOST_SDK_TOOLCHAIN_PREFIX)gcc
MY_CXX := $(HOST_SDK_TOOLCHAIN_PREFIX)g++
MY_AR := $(HOST_SDK_TOOLCHAIN_PREFIX)ar
endif # $(HOST_SDK_TOOLCHAIN_PREFIX)gcc exists
endif # HOST_OS == linux
ifneq ($(USE_CCACHE),)
ccache := prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache
ccache := $(strip $(wildcard $(ccache)))
ifneq ($(ccache),$(firstword $(MY_CC)))
MY_CC := $(ccache) $(MY_CC)
MY_CXX := $(ccache) $(MY_CXX)
endif
ccache :=
endif
endif
ifneq ($(combo_target)$(TARGET_SIMULATOR),HOST_true)
ifneq ($(HOST_IS_64_BIT),)
MY_CFLAGS += -m64
MY_LDFLAGS += -m64
else
ifneq ($(HOST_ARCH),x86_64)
MY_CFLAGS += -m32
MY_LDFLAGS += -m32
endif
endif
ifneq ($(BUILD_HOST_static),)
MY_LDLIBS += -static
endif
endif
ifeq ($(HOST_OS)-$(BUILD_STANDALONE_EMULATOR),windows-true)
# Ensure that printf() et al use GNU printf format specifiers as required
# by QEMU. This is important when using the newer Mingw64 cross-toolchain.
# See http://sourceforge.net/apps/trac/mingw-w64/wiki/gnu%20printf
MY_CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
endif
# Enable warning, except those related to missing field initializers
# (the QEMU coding style loves using these).
#
MY_CFLAGS += -Wall $(GCC_W_NO_MISSING_FIELD_INITIALIZERS)
# Needed to build block.c on Linux/x86_64.
MY_CFLAGS += -D_GNU_SOURCE=1
MY_CFLAGS += -I$(LOCAL_PATH)/include
# Need to include "qapi-types.h" and other auto-generated files from
# android-configure.sh
MY_CFLAGS += -I$(LOCAL_PATH)/qapi-auto-generated
ifneq (true,$(BUILD_STANDALONE_EMULATOR))
my-host-tool = $(MY_$1)
else
my-host-tool = $(if $(strip $(LOCAL_HOST_BUILD)),$(BUILD_$1),$(MY_$1))
endif
# A useful function that can be used to start the declaration of a host
# module. Avoids repeating the same stuff again and again.
# Usage:
#
# $(call start-emulator-library, <module-name>)
#
# ... declarations
#
# $(call end-emulator-library)
#
start-emulator-library = \
$(eval include $(CLEAR_VARS)) \
$(eval LOCAL_NO_DEFAULT_COMPILER_FLAGS := true) \
$(eval LOCAL_MODULE := $1) \
$(eval LOCAL_MODULE_CLASS := STATIC_LIBRARIES)
# Used with start-emulator-library
end-emulator-library = \
$(eval $(end-emulator-module-ev)) \
$(eval include $(BUILD_HOST_STATIC_LIBRARY))
# A variant of start-emulator-library to start the definition of a host
# program instead. Use with end-emulator-program
start-emulator-program = \
$(call start-emulator-library,$1) \
$(eval LOCAL_MODULE_CLASS := EXECUTABLES)
# A varient of end-emulator-library for host programs instead
end-emulator-program = \
$(eval LOCAL_LDLIBS += $(QEMU_SYSTEM_LDLIBS)) \
$(eval $(end-emulator-module-ev)) \
$(eval include $(BUILD_HOST_EXECUTABLE))
define end-emulator-module-ev
LOCAL_CC := $$(call my-host-tool,CC)
LOCAL_CXX := $$(call my-host-tool,CXX)
LOCAL_AR := $$(call my-host-tool,AR)
LOCAL_LD := $$(call my-host-tool,LD)
LOCAL_CFLAGS := $$(call my-host-tool,CFLAGS) $$(LOCAL_CFLAGS)
LOCAL_LDFLAGS := $$(call my-host-tool,LDFLAGS) $$(LOCAL_LDFLAGS)
LOCAL_LDLIBS := $$(LOCAL_LDLIBS) $$(call my-host-tool,LDLIBS)
endef
# The common libraries
#
QEMU_SYSTEM_LDLIBS := -lm
ifeq ($(HOST_OS),windows)
QEMU_SYSTEM_LDLIBS += -mwindows -mconsole
endif
ifeq ($(HOST_OS),freebsd)
QEMU_SYSTEM_LDLIBS += -L/usr/local/lib -lpthread -lX11 -lutil
endif
ifeq ($(HOST_OS),linux)
QEMU_SYSTEM_LDLIBS += -lutil -lrt
endif
ifeq ($(HOST_OS),windows)
# amd64-mingw32msvc- toolchain still name it ws2_32. May change it once amd64-mingw32msvc-
# is stabilized
QEMU_SYSTEM_LDLIBS += -lwinmm -lws2_32 -liphlpapi
else
QEMU_SYSTEM_LDLIBS += -lpthread
endif
ifeq ($(HOST_OS),darwin)
QEMU_SYSTEM_LDLIBS += -Wl,-framework,Cocoa,-framework,QTKit,-framework,CoreVideo
# SDK 10.6+ doesn't have __dyld_func_lookup anymore. Dynamic library lookup symbols
# are instead resolved at runtime
OSX_VERSION_MAJOR := $(shell echo $(mac_sdk_version) | cut -d . -f 2)
OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6 := $(shell [ $(OSX_VERSION_MAJOR) -ge 6 ] && echo true)
ifeq ($(OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6),true)
QEMU_SYSTEM_LDLIBS += -undefined dynamic_lookup
endif
endif
# This defines EMULATOR_BUILD_64BITS to indicate that 64-bit binaries
# must be generated by the build system. For now, only do it for
# Linux and Darwin, since we the sources do not compile with Mingw-w64
# yet due to differing procedure call ABI conventions.
EMULATOR_BUILD_64BITS := $(strip $(filter linux darwin,$(HOST_OS)))
# Disable 64-bit build for Darwin platform builds.
ifeq ($(HOST_OS),darwin)
ifneq (true,$(BUILD_STANDALONE_EMULATOR))
EMULATOR_BUILD_64BITS := $(strip $(empty))
endif # BUILD_STANDALONE_EMULATOR != true
endif # HOST_OS == darwin
include $(LOCAL_PATH)/Makefile.common
ifeq ($(HOST_OS),windows)
# on Windows, link the icon file as well into the executable
# unfortunately, our build system doesn't help us much, so we need
# to use some weird pathnames to make this work...
# Locate windres executable
WINDRES := windres
ifneq ($(USE_MINGW),)
# When building the Windows emulator under Linux, use the MinGW one
WINDRES := i586-mingw32msvc-windres
endif
# Usage: $(eval $(call insert-windows-icon))
define insert-windows-icon
LOCAL_PREBUILT_OBJ_FILES += images/emulator_icon.o
endef
# This seems to be the only way to add an object file that was not generated from
# a C/C++/Java source file to our build system. and very unfortunately,
# $(TOPDIR)/$(LOCALPATH) will always be prepended to this value, which forces
# us to put the object file in the source directory.
$(LOCAL_PATH)/images/emulator_icon.o: $(LOCAL_PATH)/images/android_icon.rc
$(WINDRES) $< -I $(LOCAL_PATH)/images -o $@
endif
# We want to build all variants of the emulator binaries. This makes
# it easier to catch target-specific regressions during emulator development.
EMULATOR_TARGET_ARCH := arm
include $(LOCAL_PATH)/Makefile.target
# Note: the same binary handles x86 and x86_64
EMULATOR_TARGET_ARCH := x86
include $(LOCAL_PATH)/Makefile.target
EMULATOR_TARGET_ARCH := mips
include $(LOCAL_PATH)/Makefile.target
##############################################################################
##############################################################################
###
### emulator: LAUNCHER FOR TARGET-SPECIFIC EMULATOR
###
###
$(call start-emulator-program, emulator)
LOCAL_SRC_FILES := android/main-emulator.c
LOCAL_STATIC_LIBRARIES := emulator-common
ifeq ($(HOST_OS),windows)
$(eval $(call insert-windows-icon))
endif
$(call end-emulator-program)
include $(LOCAL_PATH)/Makefile.tests
##############################################################################
##############################################################################
###
### GPU emulation libraries
###
### Build directly from sources when using the standalone build.
###
ifeq (true,$(BUILD_STANDALONE_EMULATOR))
ifeq (,$(strip $(wildcard $(EMULATOR_EMUGL_SOURCES_DIR))))
$(error Cannot find GPU emulation sources directory: $(EMULATOR_EMUGL_SOURCES_DIR))
endif
# TODO(digit): Remove the line below.
BUILD_EMULATOR_OPENGL := true
BUILD_EMULATOR_HOST_OPENGL := true
include $(EMULATOR_EMUGL_SOURCES_DIR)/Android.mk
endif
## VOILA!!
endif # BUILD_EMULATOR == true || BUILD_STANDALONE_EMULATOR == true