1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
ifneq (,$(filter $(TARGET_ARCH),arm x86 mips))
LOCAL_PATH:= $(call my-dir)
# determine the target cpu
ifeq ($(TARGET_ARCH),arm)
EMULATOR_TARGET_CPU := target-arm
endif
ifeq ($(TARGET_ARCH),x86)
EMULATOR_TARGET_CPU := target-i386
endif
ifeq ($(TARGET_ARCH),mips)
EMULATOR_TARGET_CPU := target-mips
endif
# 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_AR := $(HOST_AR)
MY_OPTIM := -O2 -g -fno-PIC -falign-functions=0 -fomit-frame-pointer
ifeq ($(BUILD_DEBUG_EMULATOR),true)
MY_OPTIM := -O0 -g
endif
MY_CFLAGS := $(CONFIG_INCLUDES) $(MY_OPTIM)
# 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 :=
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
ifneq ($(BUILD_HOST_64bit),)
# 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 += -mdynamic-no-pic -D_DARWIN_C_SOURCE=1
# When building on Leopard or above, we need to use the 10.4 SDK
# or the generated binary will not run on Tiger.
DARWIN_VERSION := $(strip $(shell sw_vers -productVersion))
ifneq ($(filter 10.1 10.2 10.3 10.1.% 10.2.% 10.3.% 10.4 10.4.%,$(DARWIN_VERSION)),)
$(error Building the Android emulator requires OS X 10.5 or above)
endif
ifneq ($(filter 10.5 10.5.% 10.6 10.6.%,$(DARWIN_VERSION)),)
# We are on Leopard or Snow Leopard
OSX_VERSION=10.5
else
# We are on Lion or beyond, and 10.6 SDK is the minimum in Xcode 4.x
OSX_VERSION=10.6
endif
MACOSX_SDK := /Developer/SDKs/MacOSX$(OSX_VERSION).sdk
ifeq ($(strip $(wildcard $(MACOSX_SDK))),)
$(info Please install the $(OSX_VERSION) SDK on this machine at $(MACOSX_SDK))
$(error Aborting the build.)
endif
MY_CFLAGS += -isysroot $(MACOSX_SDK) -mmacosx-version-min=$(OSX_VERSION) -DMACOSX_DEPLOYMENT_TARGET=$(OSX_VERSION)
MY_LDLIBS += -isysroot $(MACOSX_SDK) -Wl,-syslibroot,$(MACOSX_SDK) -mmacosx-version-min=$(OSX_VERSION)
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 BUILD_HOST_64bit=1)
# 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/tools/gcc-sdk
# 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
QEMU_OPENGLES_INCLUDE := sdk/emulator/opengl/host/include
QEMU_OPENGLES_LIBS := $(HOST_OUT)
endif
ifneq ($(combo_target)$(TARGET_SIMULATOR),HOST_true)
ifneq ($(BUILD_HOST_64bit),)
MY_CFLAGS += -m64
MY_LDLIBS += -m64
else
ifneq ($(HOST_ARCH),x86_64)
MY_CFLAGS += -m32
MY_LDLIBS += -m32
endif
endif
ifneq ($(BUILD_HOST_static),)
MY_LDLIBS += -static
endif
endif
# Enable warning, except those related to missing field initializers
# (the QEMU coding style loves using these).
#
MY_CFLAGS += -Wall -Wno-missing-field-initializers
# Needed to build fpu/softfloat-native.h properly
MY_CFLAGS += -D_GNU_SOURCE=1
# 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_CC := $(MY_CC)) \
$(eval LOCAL_CXX := $(MY_CXX)) \
$(eval LOCAL_CFLAGS := $(MY_CFLAGS)) \
$(eval LOCAL_AR := $(MY_AR)) \
$(eval LOCAL_LDLIBS := $(MY_LDLIBS)) \
$(eval LOCAL_MODULE_TAGS := debug) \
$(eval LOCAL_MODULE := $1) \
$(eval LOCAL_MODULE_CLASS := STATIC_LIBRARIES)
# Used with start-emulator-library
end-emulator-library = \
$(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 include $(BUILD_HOST_EXECUTABLE))
# The common libraries
#
QEMU_SYSTEM_LDLIBS := -lm
ifeq ($(HOST_OS),windows)
QEMU_SYSTEM_LDLIBS += -mno-cygwin -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
ifneq ($(filter 10.7 10.7.% 10.8 10.8.%,$(DARWIN_VERSION)),)
# 10.7+ with XCode4 needs to be explicitly told the dynamic library
# lookup symbols in the precompiled libSDL are resolved at
# runtime
QEMU_SYSTEM_LDLIBS += -undefined dynamic_lookup
endif
endif
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
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)
##############################################################################
##############################################################################
###
### emulator-ui: UI FRONT-END PROGRAM
###
###
$(call start-emulator-program, emulator-ui)
LOCAL_STATIC_LIBRARIES := \
emulator-common \
emulator-libui \
emulator-common \
LOCAL_CFLAGS += -DCONFIG_STANDALONE_UI=1
LOCAL_CFLAGS += $(EMULATOR_COMMON_CFLAGS) $(EMULATOR_LIBUI_CFLAGS)
LOCAL_LDLIBS += $(EMULATOR_COMMON_LDLIBS) $(EMULATOR_LIBUI_LDLIBS)
LOCAL_SRC_FILES := \
android/cmdline-option.c \
android/config.c \
android/help.c \
android/looper-generic.c \
android/snapshot.c \
android/main-common.c \
android/main.c \
android/opengles.c \
android/utils/setenv.c \
vl-android-ui.c \
android/protocol/core-connection.c \
android/protocol/attach-ui-impl.c \
android/protocol/fb-updates-impl.c \
android/protocol/ui-commands-impl.c \
android/protocol/core-commands-proxy.c \
android/protocol/user-events-proxy.c \
$(call gen-hw-config-defs,android/main-common.c)
LOCAL_SRC_FILES += $(SDLMAIN_SOURCES)
LOCAL_STATIC_LIBRARIES += $(SDL_STATIC_LIBRARIES)
$(call end-emulator-program)
## VOILA!!
endif # TARGET_ARCH == arm || TARGET_ARCH == x86 || TARGET_ARCH == mips
|