blob: 267bffe07d83b1dd7c604509498302298106224f [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
Bhanu Chetlapalli741dc132012-05-08 17:16:03 -07003ifneq (,$(filter $(TARGET_ARCH),arm x86 mips))
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08004LOCAL_PATH:= $(call my-dir)
5
Jun Nakajima334ab472011-02-02 23:49:59 -08006# determine the target cpu
7ifeq ($(TARGET_ARCH),arm)
8EMULATOR_TARGET_CPU := target-arm
Bhanu Chetlapalli741dc132012-05-08 17:16:03 -07009endif
10ifeq ($(TARGET_ARCH),x86)
Jun Nakajima334ab472011-02-02 23:49:59 -080011EMULATOR_TARGET_CPU := target-i386
12endif
Bhanu Chetlapalli741dc132012-05-08 17:16:03 -070013ifeq ($(TARGET_ARCH),mips)
14EMULATOR_TARGET_CPU := target-mips
15endif
Jun Nakajima334ab472011-02-02 23:49:59 -080016
David 'Digit' Turner34d16512010-05-18 17:02:33 -070017# determine the host tag to use
18QEMU_HOST_TAG := $(HOST_PREBUILT_TAG)
19ifneq ($(USE_MINGW),)
20 QEMU_HOST_TAG := windows
21endif
22
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080023# determine the location of platform-specific directories
24#
25CONFIG_DIRS := \
David 'Digit' Turner34d16512010-05-18 17:02:33 -070026 $(LOCAL_PATH)/android/config/$(QEMU_HOST_TAG)
27
28ifeq ($(BUILD_STANDALONE_EMULATOR),true)
29 CONFIG_DIRS := $(LOCAL_PATH)/objs $(CONFIG_DIRS)
30endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080031
32CONFIG_INCLUDES := $(CONFIG_DIRS:%=-I%)
33
David 'Digit' Turner0a349b82011-03-02 12:49:26 +010034MY_CC := $(HOST_CC)
35MY_CXX := $(HOST_CXX)
36MY_AR := $(HOST_AR)
Kenny Root095cd0f2009-09-19 18:32:44 -050037
Lars Poeschel33da99a2012-08-22 09:42:42 +020038MY_CFLAGS := $(CONFIG_INCLUDES) -O2 -g -fno-PIC -falign-functions=0 -fomit-frame-pointer
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080039
David 'Digit' Turner466f5482009-07-30 15:50:19 +020040# Overwrite configuration for debug builds.
41#
42ifeq ($(BUILD_DEBUG_EMULATOR),true)
Iliyan Malchevd00f7c42012-03-30 10:54:20 -070043 MY_CFLAGS := $(CONFIG_INCLUDES)
44 MY_CFLAGS += -O0 -g
45 MY_CFLAGS += -fno-PIC -falign-functions=0
David 'Digit' Turner466f5482009-07-30 15:50:19 +020046endif
47
David 'Digit' Turnerb95f8922009-08-21 23:10:16 -070048MY_LDLIBS :=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080049
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080050ifeq ($(HOST_OS),freebsd)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -070051 MY_CFLAGS += -I /usr/local/include
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080052endif
53
54ifeq ($(HOST_OS),windows)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -070055 # 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 -080056 MY_CFLAGS += -DWINVER=0x501
Andrew Hsiehc7389bd2012-03-13 02:13:40 -070057 MY_CFLAGS += -D_WIN32
58 ifneq ($(BUILD_HOST_64bit),)
59 # Microsoft 64-bit compiler define both _WIN32 and _WIN64
60 MY_CFLAGS += -D_WIN64
61 # amd64-mingw32msvc- toolchain still name it vfw32. May change it once amd64-mingw32msvc-
62 # is stabilized
63 MY_LDLIBS += -lvfw32
64 else
65 MY_LDLIBS += -lvfw32
66 endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080067endif
68
69ifeq ($(HOST_ARCH),ppc)
70 MY_CFLAGS += -D__powerpc__
71endif
72
73ifeq ($(HOST_OS),darwin)
David 'Digit' Turner747f7d12011-01-06 22:24:26 +010074 MY_CFLAGS += -mdynamic-no-pic -D_DARWIN_C_SOURCE=1
Andrew Hsieha5d8f652012-11-09 21:18:22 -080075 ifneq ($(host_toolchain_header),)
76 MY_CFLAGS += -isystem $(host_toolchain_header)
77 endif
SangWook Han08c1bde2012-07-26 08:06:58 +090078 MY_CFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) -DMACOSX_DEPLOYMENT_TARGET=$(mac_sdk_version)
79 MY_LDLIBS += -isysroot $(mac_sdk_root) -Wl,-syslibroot,$(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version)
Andrew Hsiehc2f0b962012-08-09 18:21:33 +080080
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080081endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080082
83# BUILD_STANDALONE_EMULATOR is only defined when building with
84# the android-rebuild.sh script. The script will also provide
85# adequate values for HOST_CC
86#
87ifneq ($(BUILD_STANDALONE_EMULATOR),true)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -070088 # On Linux, use our custom 32-bit host toolchain (unless BUILD_HOST_64bit=1)
89 # which contains the relevant headers and 32-bit libraries for audio (The host 64-bit
90 # Lucid doesn't provide these anymore, only their 64-bit versions).
David 'Digit' Turneraff94b82011-02-07 18:10:54 +010091 ifeq ($(HOST_OS),linux)
Andrew Hsiehd0f2ab62012-03-23 17:35:11 +080092 HOST_SDK_TOOLCHAIN_PREFIX := prebuilts/tools/gcc-sdk
David 'Digit' Turneraff94b82011-02-07 18:10:54 +010093 # Don't do anything if the toolchain is not there
Andrew Hsiehd0f2ab62012-03-23 17:35:11 +080094 ifneq (,$(strip $(wildcard $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc)))
95 MY_CC := $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc
96 MY_CXX := $(HOST_SDK_TOOLCHAIN_PREFIX)/g++
97 MY_AR := $(HOST_SDK_TOOLCHAIN_PREFIX)/ar
98 endif # $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc exists
David 'Digit' Turneraff94b82011-02-07 18:10:54 +010099 endif # HOST_OS == linux
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800100
101 ifneq ($(USE_CCACHE),)
Ying Wang762d5de2012-01-09 11:53:58 -0800102 ccache := prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache
David 'Digit' Turner4ed818f2011-03-12 13:05:15 +0100103 ccache := $(strip $(wildcard $(ccache)))
Ying Wang7bf9d7f2010-10-07 15:12:11 -0700104 ifneq ($(ccache),$(firstword $(MY_CC)))
105 MY_CC := $(ccache) $(MY_CC)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700106 MY_CXX := $(ccache) $(MY_CXX)
Ying Wang7bf9d7f2010-10-07 15:12:11 -0700107 endif
108 ccache :=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800109 endif
Jesse Hall183e9272012-04-26 15:13:27 -0700110
111 QEMU_OPENGLES_INCLUDE := sdk/emulator/opengl/host/include
112 QEMU_OPENGLES_LIBS := $(HOST_OUT)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800113endif
114
115
116ifneq ($(combo_target)$(TARGET_SIMULATOR),HOST_true)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700117 ifneq ($(BUILD_HOST_64bit),)
118 MY_CFLAGS += -m64
119 MY_LDLIBS += -m64
120 else
121 ifneq ($(HOST_ARCH),x86_64)
122 MY_CFLAGS += -m32
123 MY_LDLIBS += -m32
124 endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800125 endif
Andrew Hsieh632a0e12012-04-28 00:48:53 +0800126
127 ifneq ($(BUILD_HOST_static),)
128 MY_LDLIBS += -static
129 endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800130endif
131
David 'Digit' Turner4e024bb2010-09-22 14:19:28 +0200132# Enable warning, except those related to missing field initializers
133# (the QEMU coding style loves using these).
134#
135MY_CFLAGS += -Wall -Wno-missing-field-initializers
136
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100137# Needed to build fpu/softfloat-native.h properly
138MY_CFLAGS += -D_GNU_SOURCE=1
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800139
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100140# A useful function that can be used to start the declaration of a host
141# module. Avoids repeating the same stuff again and again.
142# Usage:
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800143#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100144# $(call start-emulator-library, <module-name>)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800145#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100146# ... declarations
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800147#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100148# $(call end-emulator-library)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800149#
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100150start-emulator-library = \
151 $(eval include $(CLEAR_VARS)) \
152 $(eval LOCAL_NO_DEFAULT_COMPILER_FLAGS := true) \
153 $(eval LOCAL_CC := $(MY_CC)) \
David 'Digit' Turnerb580d262011-03-02 09:49:06 +0100154 $(eval LOCAL_CXX := $(MY_CXX)) \
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100155 $(eval LOCAL_CFLAGS := $(MY_CFLAGS)) \
David 'Digit' Turnerb580d262011-03-02 09:49:06 +0100156 $(eval LOCAL_AR := $(MY_AR)) \
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100157 $(eval LOCAL_LDLIBS := $(MY_LDLIBS)) \
David 'Digit' Turner317c9d52011-05-10 06:38:21 +0200158 $(eval LOCAL_MODULE := $1) \
David 'Digit' Turner42fc4492011-06-29 13:16:16 +0200159 $(eval LOCAL_MODULE_CLASS := STATIC_LIBRARIES)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800160
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100161# Used with start-emulator-library
162end-emulator-library = \
David 'Digit' Turner42fc4492011-06-29 13:16:16 +0200163 $(eval include $(BUILD_HOST_STATIC_LIBRARY))
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800164
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100165# A variant of start-emulator-library to start the definition of a host
166# program instead. Use with end-emulator-program
David 'Digit' Turner088edf82011-05-09 15:59:28 +0200167start-emulator-program = \
168 $(call start-emulator-library,$1) \
David 'Digit' Turner42fc4492011-06-29 13:16:16 +0200169 $(eval LOCAL_MODULE_CLASS := EXECUTABLES)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800170
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100171# A varient of end-emulator-library for host programs instead
172end-emulator-program = \
173 $(eval LOCAL_LDLIBS += $(QEMU_SYSTEM_LDLIBS)) \
174 $(eval include $(BUILD_HOST_EXECUTABLE))
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800175
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700176
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700177# The common libraries
178#
179QEMU_SYSTEM_LDLIBS := -lm
180ifeq ($(HOST_OS),windows)
181 QEMU_SYSTEM_LDLIBS += -mno-cygwin -mwindows -mconsole
182endif
183
184ifeq ($(HOST_OS),freebsd)
185 QEMU_SYSTEM_LDLIBS += -L/usr/local/lib -lpthread -lX11 -lutil
186endif
187
188ifeq ($(HOST_OS),linux)
189 QEMU_SYSTEM_LDLIBS += -lutil -lrt
190endif
191
192ifeq ($(HOST_OS),windows)
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700193 # amd64-mingw32msvc- toolchain still name it ws2_32. May change it once amd64-mingw32msvc-
194 # is stabilized
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700195 QEMU_SYSTEM_LDLIBS += -lwinmm -lws2_32 -liphlpapi
196else
197 QEMU_SYSTEM_LDLIBS += -lpthread
198endif
199
David 'Digit' Turner393c0f12010-07-28 12:20:56 -0700200ifeq ($(HOST_OS),darwin)
Vladimir Chtchetkine955a9972011-10-12 15:40:17 -0700201 QEMU_SYSTEM_LDLIBS += -Wl,-framework,Cocoa,-framework,QTKit,-framework,CoreVideo
Andrew Hsiehc2f0b962012-08-09 18:21:33 +0800202
203 # SDK 10.6+ doesn't have __dyld_func_lookup anymore. Dynamic library lookup symbols
204 # are instead resolved at runtime
205 OSX_VERSION_MAJOR := $(shell echo $(mac_sdk_version) | cut -d . -f 2)
206 OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6 := $(shell [ $(OSX_VERSION_MAJOR) -ge 6 ] && echo true)
207 ifeq ($(OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6),true)
Al Sutton49dd3f32012-01-04 15:19:05 -0800208 QEMU_SYSTEM_LDLIBS += -undefined dynamic_lookup
Al Suttonc3c9c6f2011-12-21 13:16:22 -0800209 endif
David 'Digit' Turner393c0f12010-07-28 12:20:56 -0700210endif
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700211
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100212include $(LOCAL_PATH)/Makefile.common
213
Raphael Mollcdbea232012-05-04 15:04:27 -0700214ifeq ($(HOST_OS),windows)
215 # on Windows, link the icon file as well into the executable
216 # unfortunately, our build system doesn't help us much, so we need
217 # to use some weird pathnames to make this work...
218
219 # Locate windres executable
220 WINDRES := windres
221 ifneq ($(USE_MINGW),)
222 # When building the Windows emulator under Linux, use the MinGW one
223 WINDRES := i586-mingw32msvc-windres
224 endif
225
226 # Usage: $(eval $(call insert-windows-icon))
227 define insert-windows-icon
228 LOCAL_PREBUILT_OBJ_FILES += images/emulator_icon.o
229 endef
230
231# This seems to be the only way to add an object file that was not generated from
232# a C/C++/Java source file to our build system. and very unfortunately,
233# $(TOPDIR)/$(LOCALPATH) will always be prepended to this value, which forces
234# us to put the object file in the source directory.
235$(LOCAL_PATH)/images/emulator_icon.o: $(LOCAL_PATH)/images/android_icon.rc
236 $(WINDRES) $< -I $(LOCAL_PATH)/images -o $@
237endif
238
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100239# We want to build all variants of the emulator binaries. This makes
240# it easier to catch target-specific regressions during emulator development.
241EMULATOR_TARGET_ARCH := arm
242include $(LOCAL_PATH)/Makefile.target
243
244EMULATOR_TARGET_ARCH := x86
245include $(LOCAL_PATH)/Makefile.target
Vladimir Chtchetkineba1f57f2010-07-27 14:14:15 -0700246
Bhanu Chetlapalli741dc132012-05-08 17:16:03 -0700247EMULATOR_TARGET_ARCH := mips
248include $(LOCAL_PATH)/Makefile.target
249
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800250##############################################################################
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100251##############################################################################
252###
David 'Digit' Turner2d238fd2011-03-25 10:34:47 +0100253### emulator: LAUNCHER FOR TARGET-SPECIFIC EMULATOR
254###
255###
256$(call start-emulator-program, emulator)
257
258LOCAL_SRC_FILES := android/main-emulator.c
259LOCAL_STATIC_LIBRARIES := emulator-common
260
Raphael Mollcdbea232012-05-04 15:04:27 -0700261ifeq ($(HOST_OS),windows)
262$(eval $(call insert-windows-icon))
263endif
264
David 'Digit' Turner2d238fd2011-03-25 10:34:47 +0100265$(call end-emulator-program)
266
267##############################################################################
268##############################################################################
269###
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100270### emulator-ui: UI FRONT-END PROGRAM
271###
272###
273$(call start-emulator-program, emulator-ui)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800274
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100275LOCAL_STATIC_LIBRARIES := \
276 emulator-common \
277 emulator-libui \
278 emulator-common \
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800279
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100280LOCAL_CFLAGS += -DCONFIG_STANDALONE_UI=1
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800281
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100282LOCAL_CFLAGS += $(EMULATOR_COMMON_CFLAGS) $(EMULATOR_LIBUI_CFLAGS)
283LOCAL_LDLIBS += $(EMULATOR_COMMON_LDLIBS) $(EMULATOR_LIBUI_LDLIBS)
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800284
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100285LOCAL_SRC_FILES := \
286 android/cmdline-option.c \
287 android/config.c \
288 android/help.c \
289 android/looper-generic.c \
290 android/snapshot.c \
291 android/main-common.c \
292 android/main.c \
David 'Digit' Turnercb88e792011-08-26 01:35:14 +0200293 android/opengles.c \
David 'Digit' Turnerf816a752011-06-23 18:40:11 +0200294 android/utils/setenv.c \
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100295 vl-android-ui.c \
296 android/protocol/core-connection.c \
297 android/protocol/attach-ui-impl.c \
298 android/protocol/fb-updates-impl.c \
299 android/protocol/ui-commands-impl.c \
300 android/protocol/core-commands-proxy.c \
301 android/protocol/user-events-proxy.c \
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800302
David 'Digit' Turner42fc4492011-06-29 13:16:16 +0200303$(call gen-hw-config-defs,android/main-common.c)
304
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800305LOCAL_SRC_FILES += $(SDLMAIN_SOURCES)
306
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800307LOCAL_STATIC_LIBRARIES += $(SDL_STATIC_LIBRARIES)
308
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100309$(call end-emulator-program)
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -0800310
David 'Digit' Turneraff94b82011-02-07 18:10:54 +0100311## VOILA!!
David 'Digit' Turnerf59442f2010-10-08 16:22:10 +0200312
Bhanu Chetlapalli741dc132012-05-08 17:16:03 -0700313endif # TARGET_ARCH == arm || TARGET_ARCH == x86 || TARGET_ARCH == mips
Andrew Hsiehef0a2332012-08-23 17:39:26 +0800314endif # BUILD_EMULATOR == true || BUILD_STANDALONE_EMULATOR == true