blob: 739143ada67017e608db78eab52c5fa1796fdd07 [file] [log] [blame]
Andrew Hsiehef0a2332012-08-23 17:39:26 +08001ifneq ($(filter true% %true,$(BUILD_EMULATOR)$(BUILD_STANDALONE_EMULATOR)),)
Joe Onoratoedb86c32012-07-25 14:28:40 -07002
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08003LOCAL_PATH:= $(call my-dir)
4
David 'Digit' Turner34d16512010-05-18 17:02:33 -07005# determine the host tag to use
6QEMU_HOST_TAG := $(HOST_PREBUILT_TAG)
7ifneq ($(USE_MINGW),)
8 QEMU_HOST_TAG := windows
9endif
10
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080011# determine the location of platform-specific directories
12#
13CONFIG_DIRS := \
David 'Digit' Turner34d16512010-05-18 17:02:33 -070014 $(LOCAL_PATH)/android/config/$(QEMU_HOST_TAG)
15
16ifeq ($(BUILD_STANDALONE_EMULATOR),true)
17 CONFIG_DIRS := $(LOCAL_PATH)/objs $(CONFIG_DIRS)
18endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080019
20CONFIG_INCLUDES := $(CONFIG_DIRS:%=-I%)
21
David 'Digit' Turner0a349b82011-03-02 12:49:26 +010022MY_CC := $(HOST_CC)
23MY_CXX := $(HOST_CXX)
David 'Digit' Turner1af82152014-03-03 20:41:37 +010024MY_LD := $(HOST_LD)
David 'Digit' Turner0a349b82011-03-02 12:49:26 +010025MY_AR := $(HOST_AR)
Kenny Root095cd0f2009-09-19 18:32:44 -050026
Lars Poeschel33da99a2012-08-22 09:42:42 +020027MY_CFLAGS := $(CONFIG_INCLUDES) -O2 -g -fno-PIC -falign-functions=0 -fomit-frame-pointer
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080028
David 'Digit' Turner466f5482009-07-30 15:50:19 +020029# Overwrite configuration for debug builds.
30#
31ifeq ($(BUILD_DEBUG_EMULATOR),true)
Iliyan Malchevd00f7c42012-03-30 10:54:20 -070032 MY_CFLAGS := $(CONFIG_INCLUDES)
33 MY_CFLAGS += -O0 -g
34 MY_CFLAGS += -fno-PIC -falign-functions=0
David 'Digit' Turner466f5482009-07-30 15:50:19 +020035endif
36
David 'Digit' Turnerb95f8922009-08-21 23:10:16 -070037MY_LDLIBS :=
David 'Digit' Turner1af82152014-03-03 20:41:37 +010038MY_LDFLAGS :=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080039
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080040ifeq ($(HOST_OS),freebsd)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -070041 MY_CFLAGS += -I /usr/local/include
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080042endif
43
44ifeq ($(HOST_OS),windows)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -070045 # we need Win32 features that are available since Windows 2000 Professional/Server (NT 5.0)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080046 MY_CFLAGS += -DWINVER=0x501
Andrew Hsiehc7389bd2012-03-13 02:13:40 -070047 MY_CFLAGS += -D_WIN32
Hadi Muliawan3d0cbda2013-07-22 11:50:57 -070048 # LARGEADDRESSAWARE gives more address space to 32-bit process
49 MY_LDLIBS += -Xlinker --large-address-aware
Andrew Hsiehc7389bd2012-03-13 02:13:40 -070050 ifneq ($(BUILD_HOST_64bit),)
51 # Microsoft 64-bit compiler define both _WIN32 and _WIN64
52 MY_CFLAGS += -D_WIN64
53 # amd64-mingw32msvc- toolchain still name it vfw32. May change it once amd64-mingw32msvc-
54 # is stabilized
55 MY_LDLIBS += -lvfw32
56 else
57 MY_LDLIBS += -lvfw32
58 endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080059endif
60
61ifeq ($(HOST_ARCH),ppc)
62 MY_CFLAGS += -D__powerpc__
63endif
64
65ifeq ($(HOST_OS),darwin)
David 'Digit' Turnera07421f2014-01-18 14:26:43 +010066 MY_CFLAGS += -D_DARWIN_C_SOURCE=1
Andrew Hsieha5d8f652012-11-09 21:18:22 -080067 ifneq ($(host_toolchain_header),)
David 'Digit' Turnera07421f2014-01-18 14:26:43 +010068 MY_CFLAGS += -mdynamic-no-pic
Andrew Hsieha5d8f652012-11-09 21:18:22 -080069 MY_CFLAGS += -isystem $(host_toolchain_header)
David 'Digit' Turnera07421f2014-01-18 14:26:43 +010070 else
71 ifneq (,$(mac_sdk_root))
72 MY_CFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) -DMACOSX_DEPLOYMENT_TARGET=$(mac_sdk_version)
73 MY_LDLIBS += -isysroot $(mac_sdk_root) -Wl,-syslibroot,$(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version)
Andrew Hsiehc2f0b962012-08-09 18:21:33 +080074
David 'Digit' Turnera07421f2014-01-18 14:26:43 +010075 # Clang complains about this flag being not useful anymore.
76 MY_CFLAGS := $(filter-out -falign-functions=0,$(MY_CFLAGS))
77 endif
78 endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080079endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080080
David 'Digit' Turner1af82152014-03-03 20:41:37 +010081# NOTE: The following definitions are only used by the standalone build.
82MY_EXEEXT :=
83MY_DLLEXT := .so
84ifeq ($(HOST_OS),windows)
85 MY_EXEEXT := .exe
86 MY_DLLEXT := .dll
87endif
88ifeq ($(HOST_OS),darwin)
89 MY_DLLEXT := .dylib
90endif
91
Raphael Moll9e319a92012-11-28 13:48:25 -080092# Some CFLAGS below use -Wno-missing-field-initializers but this is not
93# supported on GCC 3.x which is still present under Cygwin.
94# Find out by probing GCC for support of this flag. Note that the test
95# itself only works on GCC 4.x anyway.
96GCC_W_NO_MISSING_FIELD_INITIALIZERS := -Wno-missing-field-initializers
97ifeq ($(HOST_OS),windows)
Raphael Moll9e319a92012-11-28 13:48:25 -080098 ifeq (,$(shell gcc -Q --help=warnings 2>/dev/null | grep missing-field-initializers))
99 $(info emulator: Ignoring unsupported GCC flag $(GCC_W_NO_MISSING_FIELD_INITIALIZERS))
100 GCC_W_NO_MISSING_FIELD_INITIALIZERS :=
101 endif
Raphael Moll9e319a92012-11-28 13:48:25 -0800102endif
103
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800104# BUILD_STANDALONE_EMULATOR is only defined when building with
105# the android-rebuild.sh script. The script will also provide
106# adequate values for HOST_CC
107#
108ifneq ($(BUILD_STANDALONE_EMULATOR),true)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700109 # On Linux, use our custom 32-bit host toolchain (unless BUILD_HOST_64bit=1)
110 # which contains the relevant headers and 32-bit libraries for audio (The host 64-bit
111 # Lucid doesn't provide these anymore, only their 64-bit versions).
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100112 ifeq ($(HOST_OS),linux)
Andrew Hsieh7db680c2014-03-13 04:18:13 -0700113 HOST_SDK_TOOLCHAIN_PREFIX := prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/bin/x86_64-linux-
114 ifeq (,$(strip $(wildcard $(HOST_SDK_TOOLCHAIN_PREFIX)gcc)))
115 # fallback to the previous host toolchain if new one isn't available
116 HOST_SDK_TOOLCHAIN_PREFIX := prebuilts/tools/gcc-sdk/
117 endif
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100118 # Don't do anything if the toolchain is not there
Andrew Hsieh7db680c2014-03-13 04:18:13 -0700119 ifneq (,$(strip $(wildcard $(HOST_SDK_TOOLCHAIN_PREFIX)gcc)))
120 MY_CC := $(HOST_SDK_TOOLCHAIN_PREFIX)gcc
121 MY_CXX := $(HOST_SDK_TOOLCHAIN_PREFIX)g++
122 MY_AR := $(HOST_SDK_TOOLCHAIN_PREFIX)ar
123 endif # $(HOST_SDK_TOOLCHAIN_PREFIX)gcc exists
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100124 endif # HOST_OS == linux
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800125
126 ifneq ($(USE_CCACHE),)
Ying Wang762d5de2012-01-09 11:53:58 -0800127 ccache := prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache
David 'Digit' Turner4ed818f2011-03-12 13:05:15 +0100128 ccache := $(strip $(wildcard $(ccache)))
Ying Wang7bf9d7f2010-10-07 15:12:11 -0700129 ifneq ($(ccache),$(firstword $(MY_CC)))
130 MY_CC := $(ccache) $(MY_CC)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700131 MY_CXX := $(ccache) $(MY_CXX)
Ying Wang7bf9d7f2010-10-07 15:12:11 -0700132 endif
133 ccache :=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800134 endif
135endif
136
137
138ifneq ($(combo_target)$(TARGET_SIMULATOR),HOST_true)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700139 ifneq ($(BUILD_HOST_64bit),)
140 MY_CFLAGS += -m64
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100141 MY_LDFLAGS += -m64
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700142 else
143 ifneq ($(HOST_ARCH),x86_64)
144 MY_CFLAGS += -m32
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100145 MY_LDFLAGS += -m32
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700146 endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800147 endif
Andrew Hsieh632a0e12012-04-28 00:48:53 +0800148
149 ifneq ($(BUILD_HOST_static),)
150 MY_LDLIBS += -static
151 endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800152endif
153
David 'Digit' Turner4e024bb2010-09-22 14:19:28 +0200154# Enable warning, except those related to missing field initializers
155# (the QEMU coding style loves using these).
156#
Raphael Moll9e319a92012-11-28 13:48:25 -0800157MY_CFLAGS += -Wall $(GCC_W_NO_MISSING_FIELD_INITIALIZERS)
David 'Digit' Turner4e024bb2010-09-22 14:19:28 +0200158
David 'Digit' Turnere2288402014-01-09 18:35:14 +0100159# Needed to build block.c on Linux/x86_64.
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100160MY_CFLAGS += -D_GNU_SOURCE=1
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800161
David 'Digit' Turner6e9d1d42013-12-13 17:29:58 +0100162MY_CFLAGS += -I$(LOCAL_PATH)/include
163
David 'Digit' Turner910aea92014-01-15 16:53:38 +0100164# Need to include "qapi-types.h" and other auto-generated files from
165# android-configure.sh
166MY_CFLAGS += -I$(LOCAL_PATH)/qapi-auto-generated
167
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100168ifneq (true,$(BUILD_STANDALONE_EMULATOR))
169my-host-tool = $(MY_$1)
170else
171my-host-tool = $(if $(strip $(LOCAL_HOST_BUILD)),$(BUILD_$1),$(MY_$1))
172endif
173
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100174# A useful function that can be used to start the declaration of a host
175# module. Avoids repeating the same stuff again and again.
176# Usage:
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800177#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100178# $(call start-emulator-library, <module-name>)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800179#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100180# ... declarations
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800181#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100182# $(call end-emulator-library)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800183#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100184start-emulator-library = \
185 $(eval include $(CLEAR_VARS)) \
186 $(eval LOCAL_NO_DEFAULT_COMPILER_FLAGS := true) \
David 'Digit' Turner317c9d52011-05-10 06:38:21 +0200187 $(eval LOCAL_MODULE := $1) \
David 'Digit' Turner42fc4492011-06-29 13:16:16 +0200188 $(eval LOCAL_MODULE_CLASS := STATIC_LIBRARIES)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800189
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100190# Used with start-emulator-library
191end-emulator-library = \
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100192 $(eval $(end-emulator-module-ev)) \
David 'Digit' Turner42fc4492011-06-29 13:16:16 +0200193 $(eval include $(BUILD_HOST_STATIC_LIBRARY))
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800194
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100195# A variant of start-emulator-library to start the definition of a host
196# program instead. Use with end-emulator-program
David 'Digit' Turner088edf82011-05-09 15:59:28 +0200197start-emulator-program = \
198 $(call start-emulator-library,$1) \
David 'Digit' Turner42fc4492011-06-29 13:16:16 +0200199 $(eval LOCAL_MODULE_CLASS := EXECUTABLES)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800200
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100201# A varient of end-emulator-library for host programs instead
202end-emulator-program = \
203 $(eval LOCAL_LDLIBS += $(QEMU_SYSTEM_LDLIBS)) \
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100204 $(eval $(end-emulator-module-ev)) \
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100205 $(eval include $(BUILD_HOST_EXECUTABLE))
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800206
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100207define end-emulator-module-ev
208LOCAL_CC := $$(call my-host-tool,CC)
209LOCAL_CXX := $$(call my-host-tool,CXX)
210LOCAL_AR := $$(call my-host-tool,AR)
211LOCAL_LD := $$(call my-host-tool,LD)
212LOCAL_CFLAGS := $$(call my-host-tool,CFLAGS) $$(LOCAL_CFLAGS)
213LOCAL_LDFLAGS := $$(call my-host-tool,LDFLAGS) $$(LOCAL_LDFLAGS)
214LOCAL_LDLIBS := $$(LOCAL_LDLIBS) $$(call my-host-tool,LDLIBS)
215endef
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700216
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700217# The common libraries
218#
219QEMU_SYSTEM_LDLIBS := -lm
220ifeq ($(HOST_OS),windows)
221 QEMU_SYSTEM_LDLIBS += -mno-cygwin -mwindows -mconsole
222endif
223
224ifeq ($(HOST_OS),freebsd)
225 QEMU_SYSTEM_LDLIBS += -L/usr/local/lib -lpthread -lX11 -lutil
226endif
227
228ifeq ($(HOST_OS),linux)
229 QEMU_SYSTEM_LDLIBS += -lutil -lrt
230endif
231
232ifeq ($(HOST_OS),windows)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700233 # amd64-mingw32msvc- toolchain still name it ws2_32. May change it once amd64-mingw32msvc-
234 # is stabilized
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700235 QEMU_SYSTEM_LDLIBS += -lwinmm -lws2_32 -liphlpapi
236else
237 QEMU_SYSTEM_LDLIBS += -lpthread
238endif
239
David 'Digit' Turner393c0f12010-07-28 12:20:56 -0700240ifeq ($(HOST_OS),darwin)
Vladimir Chtchetkine955a9972011-10-12 15:40:17 -0700241 QEMU_SYSTEM_LDLIBS += -Wl,-framework,Cocoa,-framework,QTKit,-framework,CoreVideo
Andrew Hsiehc2f0b962012-08-09 18:21:33 +0800242
243 # SDK 10.6+ doesn't have __dyld_func_lookup anymore. Dynamic library lookup symbols
244 # are instead resolved at runtime
245 OSX_VERSION_MAJOR := $(shell echo $(mac_sdk_version) | cut -d . -f 2)
246 OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6 := $(shell [ $(OSX_VERSION_MAJOR) -ge 6 ] && echo true)
247 ifeq ($(OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6),true)
Al Sutton49dd3f32012-01-04 15:19:05 -0800248 QEMU_SYSTEM_LDLIBS += -undefined dynamic_lookup
Al Suttonc3c9c6f2011-12-21 13:16:22 -0800249 endif
David 'Digit' Turner393c0f12010-07-28 12:20:56 -0700250endif
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700251
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100252# This defines EMULATOR_BUILD_64BITS to indicate that 64-bit binaries
253# must be generated by the build system. For now, only do it for
254# Linux and Darwin, since we the sources do not compile with Mingw-w64
255# yet due to differing procedure call ABI conventions.
256EMULATOR_BUILD_64BITS := $(strip $(filter linux darwin,$(HOST_OS)))
257
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100258include $(LOCAL_PATH)/Makefile.common
259
Raphael Mollcdbea232012-05-04 15:04:27 -0700260ifeq ($(HOST_OS),windows)
261 # on Windows, link the icon file as well into the executable
262 # unfortunately, our build system doesn't help us much, so we need
263 # to use some weird pathnames to make this work...
264
265 # Locate windres executable
266 WINDRES := windres
267 ifneq ($(USE_MINGW),)
268 # When building the Windows emulator under Linux, use the MinGW one
269 WINDRES := i586-mingw32msvc-windres
270 endif
271
272 # Usage: $(eval $(call insert-windows-icon))
273 define insert-windows-icon
274 LOCAL_PREBUILT_OBJ_FILES += images/emulator_icon.o
275 endef
276
277# This seems to be the only way to add an object file that was not generated from
278# a C/C++/Java source file to our build system. and very unfortunately,
279# $(TOPDIR)/$(LOCALPATH) will always be prepended to this value, which forces
280# us to put the object file in the source directory.
281$(LOCAL_PATH)/images/emulator_icon.o: $(LOCAL_PATH)/images/android_icon.rc
282 $(WINDRES) $< -I $(LOCAL_PATH)/images -o $@
283endif
284
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100285# We want to build all variants of the emulator binaries. This makes
286# it easier to catch target-specific regressions during emulator development.
287EMULATOR_TARGET_ARCH := arm
288include $(LOCAL_PATH)/Makefile.target
289
290EMULATOR_TARGET_ARCH := x86
291include $(LOCAL_PATH)/Makefile.target
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700292
Bhanu Chetlapalli741dc132012-05-08 17:16:03 -0700293EMULATOR_TARGET_ARCH := mips
294include $(LOCAL_PATH)/Makefile.target
295
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800296##############################################################################
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100297##############################################################################
298###
David 'Digit' Turner2d238fd2011-03-25 10:34:47 +0100299### emulator: LAUNCHER FOR TARGET-SPECIFIC EMULATOR
300###
301###
302$(call start-emulator-program, emulator)
303
304LOCAL_SRC_FILES := android/main-emulator.c
305LOCAL_STATIC_LIBRARIES := emulator-common
306
Raphael Mollcdbea232012-05-04 15:04:27 -0700307ifeq ($(HOST_OS),windows)
308$(eval $(call insert-windows-icon))
309endif
310
David 'Digit' Turner2d238fd2011-03-25 10:34:47 +0100311$(call end-emulator-program)
312
David 'Digit' Turner57deae32014-01-21 03:30:13 +0100313include $(LOCAL_PATH)/Makefile.tests
314
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100315##############################################################################
316##############################################################################
317###
318### GPU emulation libraries
319###
320### Build directly from sources when using the standalone build.
321###
322ifeq (true,$(BUILD_STANDALONE_EMULATOR))
323 ifeq (,$(strip $(wildcard $(EMULATOR_EMUGL_SOURCES_DIR))))
324 $(error Cannot find GPU emulation sources directory: $(EMULATOR_EMUGL_SOURCES_DIR))
325 endif
326
327 BUILD_EMULATOR_OPENGL := true
328 include $(EMULATOR_EMUGL_SOURCES_DIR)/Android.mk
329endif
330
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100331## VOILA!!
David 'Digit' Turnerf59442f2010-10-08 16:22:10 +0200332
Andrew Hsiehef0a2332012-08-23 17:39:26 +0800333endif # BUILD_EMULATOR == true || BUILD_STANDALONE_EMULATOR == true