blob: e377549b70fbf949a552ad0f53fd60f28a39aa42 [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 Hsiehd0f2ab62012-03-23 17:35:11 +0800113 HOST_SDK_TOOLCHAIN_PREFIX := prebuilts/tools/gcc-sdk
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100114 # Don't do anything if the toolchain is not there
Andrew Hsiehd0f2ab62012-03-23 17:35:11 +0800115 ifneq (,$(strip $(wildcard $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc)))
116 MY_CC := $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc
117 MY_CXX := $(HOST_SDK_TOOLCHAIN_PREFIX)/g++
118 MY_AR := $(HOST_SDK_TOOLCHAIN_PREFIX)/ar
119 endif # $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc exists
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100120 endif # HOST_OS == linux
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800121
122 ifneq ($(USE_CCACHE),)
Ying Wang762d5de2012-01-09 11:53:58 -0800123 ccache := prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache
David 'Digit' Turner4ed818f2011-03-12 13:05:15 +0100124 ccache := $(strip $(wildcard $(ccache)))
Ying Wang7bf9d7f2010-10-07 15:12:11 -0700125 ifneq ($(ccache),$(firstword $(MY_CC)))
126 MY_CC := $(ccache) $(MY_CC)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700127 MY_CXX := $(ccache) $(MY_CXX)
Ying Wang7bf9d7f2010-10-07 15:12:11 -0700128 endif
129 ccache :=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800130 endif
131endif
132
133
134ifneq ($(combo_target)$(TARGET_SIMULATOR),HOST_true)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700135 ifneq ($(BUILD_HOST_64bit),)
136 MY_CFLAGS += -m64
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100137 MY_LDFLAGS += -m64
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700138 else
139 ifneq ($(HOST_ARCH),x86_64)
140 MY_CFLAGS += -m32
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100141 MY_LDFLAGS += -m32
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700142 endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800143 endif
Andrew Hsieh632a0e12012-04-28 00:48:53 +0800144
145 ifneq ($(BUILD_HOST_static),)
146 MY_LDLIBS += -static
147 endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800148endif
149
David 'Digit' Turner4e024bb2010-09-22 14:19:28 +0200150# Enable warning, except those related to missing field initializers
151# (the QEMU coding style loves using these).
152#
Raphael Moll9e319a92012-11-28 13:48:25 -0800153MY_CFLAGS += -Wall $(GCC_W_NO_MISSING_FIELD_INITIALIZERS)
David 'Digit' Turner4e024bb2010-09-22 14:19:28 +0200154
David 'Digit' Turnere2288402014-01-09 18:35:14 +0100155# Needed to build block.c on Linux/x86_64.
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100156MY_CFLAGS += -D_GNU_SOURCE=1
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800157
David 'Digit' Turner6e9d1d42013-12-13 17:29:58 +0100158MY_CFLAGS += -I$(LOCAL_PATH)/include
159
David 'Digit' Turner910aea92014-01-15 16:53:38 +0100160# Need to include "qapi-types.h" and other auto-generated files from
161# android-configure.sh
162MY_CFLAGS += -I$(LOCAL_PATH)/qapi-auto-generated
163
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100164ifneq (true,$(BUILD_STANDALONE_EMULATOR))
165my-host-tool = $(MY_$1)
166else
167my-host-tool = $(if $(strip $(LOCAL_HOST_BUILD)),$(BUILD_$1),$(MY_$1))
168endif
169
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100170# A useful function that can be used to start the declaration of a host
171# module. Avoids repeating the same stuff again and again.
172# Usage:
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800173#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100174# $(call start-emulator-library, <module-name>)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800175#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100176# ... declarations
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800177#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100178# $(call end-emulator-library)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800179#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100180start-emulator-library = \
181 $(eval include $(CLEAR_VARS)) \
182 $(eval LOCAL_NO_DEFAULT_COMPILER_FLAGS := true) \
David 'Digit' Turner317c9d52011-05-10 06:38:21 +0200183 $(eval LOCAL_MODULE := $1) \
David 'Digit' Turner42fc4492011-06-29 13:16:16 +0200184 $(eval LOCAL_MODULE_CLASS := STATIC_LIBRARIES)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800185
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100186# Used with start-emulator-library
187end-emulator-library = \
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100188 $(eval $(end-emulator-module-ev)) \
David 'Digit' Turner42fc4492011-06-29 13:16:16 +0200189 $(eval include $(BUILD_HOST_STATIC_LIBRARY))
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800190
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100191# A variant of start-emulator-library to start the definition of a host
192# program instead. Use with end-emulator-program
David 'Digit' Turner088edf82011-05-09 15:59:28 +0200193start-emulator-program = \
194 $(call start-emulator-library,$1) \
David 'Digit' Turner42fc4492011-06-29 13:16:16 +0200195 $(eval LOCAL_MODULE_CLASS := EXECUTABLES)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800196
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100197# A varient of end-emulator-library for host programs instead
198end-emulator-program = \
199 $(eval LOCAL_LDLIBS += $(QEMU_SYSTEM_LDLIBS)) \
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100200 $(eval $(end-emulator-module-ev)) \
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100201 $(eval include $(BUILD_HOST_EXECUTABLE))
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800202
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100203define end-emulator-module-ev
204LOCAL_CC := $$(call my-host-tool,CC)
205LOCAL_CXX := $$(call my-host-tool,CXX)
206LOCAL_AR := $$(call my-host-tool,AR)
207LOCAL_LD := $$(call my-host-tool,LD)
208LOCAL_CFLAGS := $$(call my-host-tool,CFLAGS) $$(LOCAL_CFLAGS)
209LOCAL_LDFLAGS := $$(call my-host-tool,LDFLAGS) $$(LOCAL_LDFLAGS)
210LOCAL_LDLIBS := $$(LOCAL_LDLIBS) $$(call my-host-tool,LDLIBS)
211endef
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700212
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700213# The common libraries
214#
215QEMU_SYSTEM_LDLIBS := -lm
216ifeq ($(HOST_OS),windows)
217 QEMU_SYSTEM_LDLIBS += -mno-cygwin -mwindows -mconsole
218endif
219
220ifeq ($(HOST_OS),freebsd)
221 QEMU_SYSTEM_LDLIBS += -L/usr/local/lib -lpthread -lX11 -lutil
222endif
223
224ifeq ($(HOST_OS),linux)
225 QEMU_SYSTEM_LDLIBS += -lutil -lrt
226endif
227
228ifeq ($(HOST_OS),windows)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700229 # amd64-mingw32msvc- toolchain still name it ws2_32. May change it once amd64-mingw32msvc-
230 # is stabilized
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700231 QEMU_SYSTEM_LDLIBS += -lwinmm -lws2_32 -liphlpapi
232else
233 QEMU_SYSTEM_LDLIBS += -lpthread
234endif
235
David 'Digit' Turner393c0f12010-07-28 12:20:56 -0700236ifeq ($(HOST_OS),darwin)
Vladimir Chtchetkine955a9972011-10-12 15:40:17 -0700237 QEMU_SYSTEM_LDLIBS += -Wl,-framework,Cocoa,-framework,QTKit,-framework,CoreVideo
Andrew Hsiehc2f0b962012-08-09 18:21:33 +0800238
239 # SDK 10.6+ doesn't have __dyld_func_lookup anymore. Dynamic library lookup symbols
240 # are instead resolved at runtime
241 OSX_VERSION_MAJOR := $(shell echo $(mac_sdk_version) | cut -d . -f 2)
242 OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6 := $(shell [ $(OSX_VERSION_MAJOR) -ge 6 ] && echo true)
243 ifeq ($(OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6),true)
Al Sutton49dd3f32012-01-04 15:19:05 -0800244 QEMU_SYSTEM_LDLIBS += -undefined dynamic_lookup
Al Suttonc3c9c6f2011-12-21 13:16:22 -0800245 endif
David 'Digit' Turner393c0f12010-07-28 12:20:56 -0700246endif
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700247
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100248# This defines EMULATOR_BUILD_64BITS to indicate that 64-bit binaries
249# must be generated by the build system. For now, only do it for
250# Linux and Darwin, since we the sources do not compile with Mingw-w64
251# yet due to differing procedure call ABI conventions.
252EMULATOR_BUILD_64BITS := $(strip $(filter linux darwin,$(HOST_OS)))
253
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100254include $(LOCAL_PATH)/Makefile.common
255
Raphael Mollcdbea232012-05-04 15:04:27 -0700256ifeq ($(HOST_OS),windows)
257 # on Windows, link the icon file as well into the executable
258 # unfortunately, our build system doesn't help us much, so we need
259 # to use some weird pathnames to make this work...
260
261 # Locate windres executable
262 WINDRES := windres
263 ifneq ($(USE_MINGW),)
264 # When building the Windows emulator under Linux, use the MinGW one
265 WINDRES := i586-mingw32msvc-windres
266 endif
267
268 # Usage: $(eval $(call insert-windows-icon))
269 define insert-windows-icon
270 LOCAL_PREBUILT_OBJ_FILES += images/emulator_icon.o
271 endef
272
273# This seems to be the only way to add an object file that was not generated from
274# a C/C++/Java source file to our build system. and very unfortunately,
275# $(TOPDIR)/$(LOCALPATH) will always be prepended to this value, which forces
276# us to put the object file in the source directory.
277$(LOCAL_PATH)/images/emulator_icon.o: $(LOCAL_PATH)/images/android_icon.rc
278 $(WINDRES) $< -I $(LOCAL_PATH)/images -o $@
279endif
280
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100281# We want to build all variants of the emulator binaries. This makes
282# it easier to catch target-specific regressions during emulator development.
283EMULATOR_TARGET_ARCH := arm
284include $(LOCAL_PATH)/Makefile.target
285
286EMULATOR_TARGET_ARCH := x86
287include $(LOCAL_PATH)/Makefile.target
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700288
Bhanu Chetlapalli741dc132012-05-08 17:16:03 -0700289EMULATOR_TARGET_ARCH := mips
290include $(LOCAL_PATH)/Makefile.target
291
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800292##############################################################################
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100293##############################################################################
294###
David 'Digit' Turner2d238fd2011-03-25 10:34:47 +0100295### emulator: LAUNCHER FOR TARGET-SPECIFIC EMULATOR
296###
297###
298$(call start-emulator-program, emulator)
299
300LOCAL_SRC_FILES := android/main-emulator.c
301LOCAL_STATIC_LIBRARIES := emulator-common
302
Raphael Mollcdbea232012-05-04 15:04:27 -0700303ifeq ($(HOST_OS),windows)
304$(eval $(call insert-windows-icon))
305endif
306
David 'Digit' Turner2d238fd2011-03-25 10:34:47 +0100307$(call end-emulator-program)
308
David 'Digit' Turner57deae32014-01-21 03:30:13 +0100309include $(LOCAL_PATH)/Makefile.tests
310
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100311##############################################################################
312##############################################################################
313###
314### GPU emulation libraries
315###
316### Build directly from sources when using the standalone build.
317###
318ifeq (true,$(BUILD_STANDALONE_EMULATOR))
319 ifeq (,$(strip $(wildcard $(EMULATOR_EMUGL_SOURCES_DIR))))
320 $(error Cannot find GPU emulation sources directory: $(EMULATOR_EMUGL_SOURCES_DIR))
321 endif
322
323 BUILD_EMULATOR_OPENGL := true
324 include $(EMULATOR_EMUGL_SOURCES_DIR)/Android.mk
325endif
326
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100327## VOILA!!
David 'Digit' Turnerf59442f2010-10-08 16:22:10 +0200328
Andrew Hsiehef0a2332012-08-23 17:39:26 +0800329endif # BUILD_EMULATOR == true || BUILD_STANDALONE_EMULATOR == true