blob: a60c424711d0a609a8f07c5e5599017e675d14f4 [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)
24MY_AR := $(HOST_AR)
Kenny Root095cd0f2009-09-19 18:32:44 -050025
Lars Poeschel33da99a2012-08-22 09:42:42 +020026MY_CFLAGS := $(CONFIG_INCLUDES) -O2 -g -fno-PIC -falign-functions=0 -fomit-frame-pointer
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080027
David 'Digit' Turner466f5482009-07-30 15:50:19 +020028# Overwrite configuration for debug builds.
29#
30ifeq ($(BUILD_DEBUG_EMULATOR),true)
Iliyan Malchevd00f7c42012-03-30 10:54:20 -070031 MY_CFLAGS := $(CONFIG_INCLUDES)
32 MY_CFLAGS += -O0 -g
33 MY_CFLAGS += -fno-PIC -falign-functions=0
David 'Digit' Turner466f5482009-07-30 15:50:19 +020034endif
35
David 'Digit' Turnerb95f8922009-08-21 23:10:16 -070036MY_LDLIBS :=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080037
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080038ifeq ($(HOST_OS),freebsd)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -070039 MY_CFLAGS += -I /usr/local/include
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080040endif
41
42ifeq ($(HOST_OS),windows)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -070043 # 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 -080044 MY_CFLAGS += -DWINVER=0x501
Andrew Hsiehc7389bd2012-03-13 02:13:40 -070045 MY_CFLAGS += -D_WIN32
Hadi Muliawan3d0cbda2013-07-22 11:50:57 -070046 # LARGEADDRESSAWARE gives more address space to 32-bit process
47 MY_LDLIBS += -Xlinker --large-address-aware
Andrew Hsiehc7389bd2012-03-13 02:13:40 -070048 ifneq ($(BUILD_HOST_64bit),)
49 # Microsoft 64-bit compiler define both _WIN32 and _WIN64
50 MY_CFLAGS += -D_WIN64
51 # amd64-mingw32msvc- toolchain still name it vfw32. May change it once amd64-mingw32msvc-
52 # is stabilized
53 MY_LDLIBS += -lvfw32
54 else
55 MY_LDLIBS += -lvfw32
56 endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080057endif
58
59ifeq ($(HOST_ARCH),ppc)
60 MY_CFLAGS += -D__powerpc__
61endif
62
63ifeq ($(HOST_OS),darwin)
David 'Digit' Turnera07421f2014-01-18 14:26:43 +010064 MY_CFLAGS += -D_DARWIN_C_SOURCE=1
Andrew Hsieha5d8f652012-11-09 21:18:22 -080065 ifneq ($(host_toolchain_header),)
David 'Digit' Turnera07421f2014-01-18 14:26:43 +010066 MY_CFLAGS += -mdynamic-no-pic
Andrew Hsieha5d8f652012-11-09 21:18:22 -080067 MY_CFLAGS += -isystem $(host_toolchain_header)
David 'Digit' Turnera07421f2014-01-18 14:26:43 +010068 else
69 ifneq (,$(mac_sdk_root))
70 MY_CFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) -DMACOSX_DEPLOYMENT_TARGET=$(mac_sdk_version)
71 MY_LDLIBS += -isysroot $(mac_sdk_root) -Wl,-syslibroot,$(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version)
Andrew Hsiehc2f0b962012-08-09 18:21:33 +080072
David 'Digit' Turnera07421f2014-01-18 14:26:43 +010073 # Clang complains about this flag being not useful anymore.
74 MY_CFLAGS := $(filter-out -falign-functions=0,$(MY_CFLAGS))
75 endif
76 endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080077endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080078
Raphael Moll9e319a92012-11-28 13:48:25 -080079# Some CFLAGS below use -Wno-missing-field-initializers but this is not
80# supported on GCC 3.x which is still present under Cygwin.
81# Find out by probing GCC for support of this flag. Note that the test
82# itself only works on GCC 4.x anyway.
83GCC_W_NO_MISSING_FIELD_INITIALIZERS := -Wno-missing-field-initializers
84ifeq ($(HOST_OS),windows)
Raphael Moll9e319a92012-11-28 13:48:25 -080085 ifeq (,$(shell gcc -Q --help=warnings 2>/dev/null | grep missing-field-initializers))
86 $(info emulator: Ignoring unsupported GCC flag $(GCC_W_NO_MISSING_FIELD_INITIALIZERS))
87 GCC_W_NO_MISSING_FIELD_INITIALIZERS :=
88 endif
Raphael Moll9e319a92012-11-28 13:48:25 -080089endif
90
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080091# BUILD_STANDALONE_EMULATOR is only defined when building with
92# the android-rebuild.sh script. The script will also provide
93# adequate values for HOST_CC
94#
95ifneq ($(BUILD_STANDALONE_EMULATOR),true)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -070096 # On Linux, use our custom 32-bit host toolchain (unless BUILD_HOST_64bit=1)
97 # which contains the relevant headers and 32-bit libraries for audio (The host 64-bit
98 # Lucid doesn't provide these anymore, only their 64-bit versions).
David 'Digit' Turneraff94b82011-02-07 18:10:54 +010099 ifeq ($(HOST_OS),linux)
Andrew Hsiehd0f2ab62012-03-23 17:35:11 +0800100 HOST_SDK_TOOLCHAIN_PREFIX := prebuilts/tools/gcc-sdk
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100101 # Don't do anything if the toolchain is not there
Andrew Hsiehd0f2ab62012-03-23 17:35:11 +0800102 ifneq (,$(strip $(wildcard $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc)))
103 MY_CC := $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc
104 MY_CXX := $(HOST_SDK_TOOLCHAIN_PREFIX)/g++
105 MY_AR := $(HOST_SDK_TOOLCHAIN_PREFIX)/ar
106 endif # $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc exists
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100107 endif # HOST_OS == linux
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800108
109 ifneq ($(USE_CCACHE),)
Ying Wang762d5de2012-01-09 11:53:58 -0800110 ccache := prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache
David 'Digit' Turner4ed818f2011-03-12 13:05:15 +0100111 ccache := $(strip $(wildcard $(ccache)))
Ying Wang7bf9d7f2010-10-07 15:12:11 -0700112 ifneq ($(ccache),$(firstword $(MY_CC)))
113 MY_CC := $(ccache) $(MY_CC)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700114 MY_CXX := $(ccache) $(MY_CXX)
Ying Wang7bf9d7f2010-10-07 15:12:11 -0700115 endif
116 ccache :=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800117 endif
118endif
119
120
121ifneq ($(combo_target)$(TARGET_SIMULATOR),HOST_true)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700122 ifneq ($(BUILD_HOST_64bit),)
123 MY_CFLAGS += -m64
124 MY_LDLIBS += -m64
125 else
126 ifneq ($(HOST_ARCH),x86_64)
127 MY_CFLAGS += -m32
128 MY_LDLIBS += -m32
129 endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800130 endif
Andrew Hsieh632a0e12012-04-28 00:48:53 +0800131
132 ifneq ($(BUILD_HOST_static),)
133 MY_LDLIBS += -static
134 endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800135endif
136
David 'Digit' Turner4e024bb2010-09-22 14:19:28 +0200137# Enable warning, except those related to missing field initializers
138# (the QEMU coding style loves using these).
139#
Raphael Moll9e319a92012-11-28 13:48:25 -0800140MY_CFLAGS += -Wall $(GCC_W_NO_MISSING_FIELD_INITIALIZERS)
David 'Digit' Turner4e024bb2010-09-22 14:19:28 +0200141
David 'Digit' Turnere2288402014-01-09 18:35:14 +0100142# Needed to build block.c on Linux/x86_64.
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100143MY_CFLAGS += -D_GNU_SOURCE=1
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800144
David 'Digit' Turner6e9d1d42013-12-13 17:29:58 +0100145MY_CFLAGS += -I$(LOCAL_PATH)/include
146
David 'Digit' Turner910aea92014-01-15 16:53:38 +0100147# Need to include "qapi-types.h" and other auto-generated files from
148# android-configure.sh
149MY_CFLAGS += -I$(LOCAL_PATH)/qapi-auto-generated
150
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100151# A useful function that can be used to start the declaration of a host
152# module. Avoids repeating the same stuff again and again.
153# Usage:
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800154#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100155# $(call start-emulator-library, <module-name>)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800156#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100157# ... declarations
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800158#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100159# $(call end-emulator-library)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800160#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100161start-emulator-library = \
162 $(eval include $(CLEAR_VARS)) \
163 $(eval LOCAL_NO_DEFAULT_COMPILER_FLAGS := true) \
164 $(eval LOCAL_CC := $(MY_CC)) \
David 'Digit' Turnerb580d262011-03-02 09:49:06 +0100165 $(eval LOCAL_CXX := $(MY_CXX)) \
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100166 $(eval LOCAL_CFLAGS := $(MY_CFLAGS)) \
David 'Digit' Turnerb580d262011-03-02 09:49:06 +0100167 $(eval LOCAL_AR := $(MY_AR)) \
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100168 $(eval LOCAL_LDLIBS := $(MY_LDLIBS)) \
David 'Digit' Turner317c9d52011-05-10 06:38:21 +0200169 $(eval LOCAL_MODULE := $1) \
David 'Digit' Turner42fc4492011-06-29 13:16:16 +0200170 $(eval LOCAL_MODULE_CLASS := STATIC_LIBRARIES)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800171
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100172# Used with start-emulator-library
173end-emulator-library = \
David 'Digit' Turner42fc4492011-06-29 13:16:16 +0200174 $(eval include $(BUILD_HOST_STATIC_LIBRARY))
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800175
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100176# A variant of start-emulator-library to start the definition of a host
177# program instead. Use with end-emulator-program
David 'Digit' Turner088edf82011-05-09 15:59:28 +0200178start-emulator-program = \
179 $(call start-emulator-library,$1) \
David 'Digit' Turner42fc4492011-06-29 13:16:16 +0200180 $(eval LOCAL_MODULE_CLASS := EXECUTABLES)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800181
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100182# A varient of end-emulator-library for host programs instead
183end-emulator-program = \
184 $(eval LOCAL_LDLIBS += $(QEMU_SYSTEM_LDLIBS)) \
185 $(eval include $(BUILD_HOST_EXECUTABLE))
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800186
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700187
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700188# The common libraries
189#
190QEMU_SYSTEM_LDLIBS := -lm
191ifeq ($(HOST_OS),windows)
192 QEMU_SYSTEM_LDLIBS += -mno-cygwin -mwindows -mconsole
193endif
194
195ifeq ($(HOST_OS),freebsd)
196 QEMU_SYSTEM_LDLIBS += -L/usr/local/lib -lpthread -lX11 -lutil
197endif
198
199ifeq ($(HOST_OS),linux)
200 QEMU_SYSTEM_LDLIBS += -lutil -lrt
201endif
202
203ifeq ($(HOST_OS),windows)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700204 # amd64-mingw32msvc- toolchain still name it ws2_32. May change it once amd64-mingw32msvc-
205 # is stabilized
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700206 QEMU_SYSTEM_LDLIBS += -lwinmm -lws2_32 -liphlpapi
207else
208 QEMU_SYSTEM_LDLIBS += -lpthread
209endif
210
David 'Digit' Turner393c0f12010-07-28 12:20:56 -0700211ifeq ($(HOST_OS),darwin)
Vladimir Chtchetkine955a9972011-10-12 15:40:17 -0700212 QEMU_SYSTEM_LDLIBS += -Wl,-framework,Cocoa,-framework,QTKit,-framework,CoreVideo
Andrew Hsiehc2f0b962012-08-09 18:21:33 +0800213
214 # SDK 10.6+ doesn't have __dyld_func_lookup anymore. Dynamic library lookup symbols
215 # are instead resolved at runtime
216 OSX_VERSION_MAJOR := $(shell echo $(mac_sdk_version) | cut -d . -f 2)
217 OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6 := $(shell [ $(OSX_VERSION_MAJOR) -ge 6 ] && echo true)
218 ifeq ($(OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6),true)
Al Sutton49dd3f32012-01-04 15:19:05 -0800219 QEMU_SYSTEM_LDLIBS += -undefined dynamic_lookup
Al Suttonc3c9c6f2011-12-21 13:16:22 -0800220 endif
David 'Digit' Turner393c0f12010-07-28 12:20:56 -0700221endif
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700222
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100223# This defines EMULATOR_BUILD_64BITS to indicate that 64-bit binaries
224# must be generated by the build system. For now, only do it for
225# Linux and Darwin, since we the sources do not compile with Mingw-w64
226# yet due to differing procedure call ABI conventions.
227EMULATOR_BUILD_64BITS := $(strip $(filter linux darwin,$(HOST_OS)))
228
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100229include $(LOCAL_PATH)/Makefile.common
230
Raphael Mollcdbea232012-05-04 15:04:27 -0700231ifeq ($(HOST_OS),windows)
232 # on Windows, link the icon file as well into the executable
233 # unfortunately, our build system doesn't help us much, so we need
234 # to use some weird pathnames to make this work...
235
236 # Locate windres executable
237 WINDRES := windres
238 ifneq ($(USE_MINGW),)
239 # When building the Windows emulator under Linux, use the MinGW one
240 WINDRES := i586-mingw32msvc-windres
241 endif
242
243 # Usage: $(eval $(call insert-windows-icon))
244 define insert-windows-icon
245 LOCAL_PREBUILT_OBJ_FILES += images/emulator_icon.o
246 endef
247
248# This seems to be the only way to add an object file that was not generated from
249# a C/C++/Java source file to our build system. and very unfortunately,
250# $(TOPDIR)/$(LOCALPATH) will always be prepended to this value, which forces
251# us to put the object file in the source directory.
252$(LOCAL_PATH)/images/emulator_icon.o: $(LOCAL_PATH)/images/android_icon.rc
253 $(WINDRES) $< -I $(LOCAL_PATH)/images -o $@
254endif
255
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100256# We want to build all variants of the emulator binaries. This makes
257# it easier to catch target-specific regressions during emulator development.
258EMULATOR_TARGET_ARCH := arm
259include $(LOCAL_PATH)/Makefile.target
260
261EMULATOR_TARGET_ARCH := x86
262include $(LOCAL_PATH)/Makefile.target
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700263
Bhanu Chetlapalli741dc132012-05-08 17:16:03 -0700264EMULATOR_TARGET_ARCH := mips
265include $(LOCAL_PATH)/Makefile.target
266
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800267##############################################################################
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100268##############################################################################
269###
David 'Digit' Turner2d238fd2011-03-25 10:34:47 +0100270### emulator: LAUNCHER FOR TARGET-SPECIFIC EMULATOR
271###
272###
273$(call start-emulator-program, emulator)
274
275LOCAL_SRC_FILES := android/main-emulator.c
276LOCAL_STATIC_LIBRARIES := emulator-common
277
Raphael Mollcdbea232012-05-04 15:04:27 -0700278ifeq ($(HOST_OS),windows)
279$(eval $(call insert-windows-icon))
280endif
281
David 'Digit' Turner2d238fd2011-03-25 10:34:47 +0100282$(call end-emulator-program)
283
David 'Digit' Turner57deae32014-01-21 03:30:13 +0100284include $(LOCAL_PATH)/Makefile.tests
285
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100286## VOILA!!
David 'Digit' Turnerf59442f2010-10-08 16:22:10 +0200287
Andrew Hsiehef0a2332012-08-23 17:39:26 +0800288endif # BUILD_EMULATOR == true || BUILD_STANDALONE_EMULATOR == true