-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile.android
432 lines (358 loc) · 13.8 KB
/
Makefile.android
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
ifneq ($(filter true% %true,$(BUILD_EMULATOR)$(BUILD_STANDALONE_EMULATOR)),)
LOCAL_PATH:= $(call my-dir)
# determine the host tag to use
QEMU_HOST_TAG := $(HOST_PREBUILT_TAG)
ifneq ($(USE_MINGW),)
QEMU_HOST_TAG := windows
endif
# This defines EMULATOR_BUILD_32BITS to indicate that 32-bit binaries
# must be generated by the build system. For now, only for Windows because
# the Win64 do not work yet properly (e.g. can't emulate 32-bit ARM), and
# Linux (because the 32-bit binaries are deprecated, but not obsolete).
EMULATOR_BUILD_32BITS := $(strip $(filter windows linux,$(HOST_OS)))
# This defines EMULATOR_BUILD_64BITS to indicate that 64-bit binaries
# must be generated by the build system. For now, only do it for
# Windows, Linux and Darwin.
EMULATOR_BUILD_64BITS := $(strip $(filter linux darwin windows,$(HOST_OS)))
# EMULATOR_PROGRAM_BITNESS is the bitness of the 'emulator' launcher program.
# It will be 32 if we allow 32-bit binaries to be built, 64 otherwise.
ifneq (,$(EMULATOR_BUILD_32BITS))
EMULATOR_PROGRAM_BITNESS := 32
else
EMULATOR_PROGRAM_BITNESS := 64
endif
# A function that includes a file only if 32-bit binaries are necessary,
# or if LOCAL_IGNORE_BITNESS is defined for the current module.
# $1: Build file to include.
include-if-bitness-32 = \
$(if $(strip $(LOCAL_IGNORE_BITNESS)$(filter true,$(LOCAL_HOST_BUILD))$(EMULATOR_BUILD_32BITS)),\
$(eval include $1))
# A function that includes a file only of EMULATOR_BUILD_64BITS is not empty.
# or if LOCAL_IGNORE_BITNESS is defined for the current module.
# $1: Build file to include.
include-if-bitness-64 = \
$(if $(strip $(LOCAL_IGNORE_BITNESS)$(filter true,$(LOCAL_HOST_BUILD))$(EMULATOR_BUILD_64BITS)),\
$(eval include $1))
# determine the location of platform-specific directories
#
QEMU_CONFIG_DIRS := \
$(LOCAL_PATH)/android/config/$(QEMU_HOST_TAG)
ifeq ($(BUILD_STANDALONE_EMULATOR),true)
QEMU_CONFIG_DIRS := $(LOCAL_PATH)/objs $(QEMU_CONFIG_DIRS)
endif
QEMU_CONFIG_INCLUDES := $(QEMU_CONFIG_DIRS:%=-I%)
MY_CC := $(HOST_CC)
MY_CXX := $(HOST_CXX)
MY_LD := $(HOST_LD)
MY_AR := $(HOST_AR)
MY_WINDRES := $(HOST_WINDRES)
MY_CFLAGS := -g -falign-functions=0
ifeq ($(BUILD_DEBUG_EMULATOR),true)
MY_CFLAGS += -O0
else
MY_CFLAGS += -O2
endif
# Generate position-independent binaries. Don't add -fPIC when targetting
# Windows, because newer toolchain complain loudly about it, since all
# Windows code is position-independent.
ifneq (windows,$(HOST_OS))
MY_CFLAGS += -fPIC
endif
MY_CFLAGS32 :=
MY_CFLAGS64 :=
MY_LDLIBS :=
MY_LDLIBS32 :=
MY_LDLIBS64 :=
MY_LDFLAGS :=
MY_LDFLAGS32 :=
MY_LDFLAGS64 :=
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
# LARGEADDRESSAWARE gives more address space to 32-bit process
MY_LDFLAGS32 += -Xlinker --large-address-aware
endif
ifeq ($(HOST_ARCH),ppc)
MY_CFLAGS += -D__powerpc__
endif
ifeq ($(HOST_OS),darwin)
MY_CFLAGS += -D_DARWIN_C_SOURCE=1
ifneq ($(host_toolchain_header),)
MY_CFLAGS += -isystem $(host_toolchain_header)
else
ifneq (,$(mac_sdk_root))
MY_CFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) -DMACOSX_DEPLOYMENT_TARGET=$(mac_sdk_version)
MY_LDLIBS += -isysroot $(mac_sdk_root) -Wl,-syslibroot,$(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version)
# Clang complains about this flag being not useful anymore.
MY_CFLAGS := $(filter-out -falign-functions=0,$(MY_CFLAGS))
endif
endif
endif
# NOTE: The following definitions are only used by the standalone build.
MY_EXEEXT :=
MY_DLLEXT := .so
ifeq ($(HOST_OS),windows)
MY_EXEEXT := .exe
MY_DLLEXT := .dll
endif
ifeq ($(HOST_OS),darwin)
MY_DLLEXT := .dylib
endif
# Some CFLAGS below use -Wno-missing-field-initializers but this is not
# supported on GCC 3.x which is still present under Cygwin.
# Find out by probing GCC for support of this flag. Note that the test
# itself only works on GCC 4.x anyway.
GCC_W_NO_MISSING_FIELD_INITIALIZERS := -Wno-missing-field-initializers
ifeq ($(HOST_OS),windows)
ifeq (,$(shell gcc -Q --help=warnings 2>/dev/null | grep missing-field-initializers))
$(info emulator: Ignoring unsupported GCC flag $(GCC_W_NO_MISSING_FIELD_INITIALIZERS))
GCC_W_NO_MISSING_FIELD_INITIALIZERS :=
endif
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 HOST_IS_64_BIT=true)
# 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/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/bin/x86_64-linux-
ifeq (,$(strip $(wildcard $(HOST_SDK_TOOLCHAIN_PREFIX)gcc)))
# fallback to the previous host toolchain if new one isn't available
HOST_SDK_TOOLCHAIN_PREFIX := prebuilts/tools/gcc-sdk/
endif
# 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
endif
ifneq ($(HOST_IS_64_BIT),)
MY_CFLAGS += -m64
MY_LDFLAGS += -m64
else
ifneq ($(HOST_ARCH),x86_64)
MY_CFLAGS += -m32
MY_LDFLAGS += -m32
endif
endif
ifneq ($(BUILD_HOST_static),)
MY_LDLIBS += -static
endif
ifeq ($(HOST_OS)-$(BUILD_STANDALONE_EMULATOR),windows-true)
# Ensure that printf() et al use GNU printf format specifiers as required
# by QEMU. This is important when using the newer Mingw64 cross-toolchain.
# See http://sourceforge.net/apps/trac/mingw-w64/wiki/gnu%20printf
MY_CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
endif
# Enable warning, except those related to missing field initializers
# (the QEMU coding style loves using these).
#
MY_CFLAGS += -Wall $(GCC_W_NO_MISSING_FIELD_INITIALIZERS)
# When using clang and ccache, disable the spammy warnings about unused
# parameters during compilation, and re-enable colored output.
#
# See http://petereisentraut.blogspot.fr/2011/05/ccache-and-clang.html
ifneq (,$(filter %ccache,$(MY_CC)))
ifneq (,$(filter LLVM,$(shell $(HOST_CC) -v 2>&1)))
MY_CFLAGS := -Qunused-arguments -fcolor-diagnostics $(MY_CFLAGS)
endif
endif
# Needed to build block.c on Linux/x86_64.
MY_CFLAGS += -D_GNU_SOURCE=1
ifneq (true,$(BUILD_STANDALONE_EMULATOR))
my-host-tool = $(MY_$1)
else
my-host-tool = $(if $(strip $(LOCAL_HOST_BUILD)),$(BUILD_$1),$(MY_$1))
endif
# 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_MODULE := $1) \
$(eval LOCAL_MODULE_CLASS := STATIC_LIBRARIES) \
$(eval LOCAL_MODULE_BITS := 32)
start-emulator64-library = \
$(call start-emulator-library, $1) \
$(eval LOCAL_MODULE_BITS := 64)
# Used with start-emulator-library
end-emulator-library = \
$(eval $(end-emulator-module-ev)) \
$(call include-if-bitness-$(LOCAL_MODULE_BITS), $(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)
start-emulator64-program = \
$(call start-emulator-program, $1) \
$(eval LOCAL_MODULE_BITS := 64)
# A varient of end-emulator-library for host programs instead
end-emulator-program = \
$(eval LOCAL_LDLIBS += $(QEMU_SYSTEM_LDLIBS)) \
$(eval $(end-emulator-module-ev)) \
$(call include-if-bitness-$(LOCAL_MODULE_BITS), $(BUILD_HOST_EXECUTABLE))
define end-emulator-module-ev
LOCAL_CC := $$(call my-host-tool,CC)
LOCAL_CXX := $$(call my-host-tool,CXX)
LOCAL_AR := $$(call my-host-tool,AR)
LOCAL_LD := $$(call my-host-tool,LD)
LOCAL_CFLAGS := \
$$(call my-host-tool,CFLAGS$$(LOCAL_MODULE_BITS)) \
$$(call my-host-tool,CFLAGS) \
$$(LOCAL_CFLAGS)
LOCAL_LDFLAGS := \
$$(call my-host-tool,LDFLAGS$$(LOCAL_MODULE_BITS)) \
$$(call my-host-tool,LDFLAGS) \
$$(LOCAL_LDFLAGS)
LOCAL_LDLIBS := \
$$(LOCAL_LDLIBS) \
$$(call my-host-tool,LDLIBS) \
$$(call my-host-tool,LDLIBS$$(LOCAL_MODULE_BITS))
# Ensure only one of -m32 or -m64 is being used and place it first.
LOCAL_CFLAGS := \
-m$$(LOCAL_MODULE_BITS) \
$$(filter-out -m32 -m64, $$(LOCAL_CFLAGS))
LOCAL_LDFLAGS := \
-m$$(LOCAL_MODULE_BITS) \
$$(filter-out -m32 -m64, $$(LOCAL_LDFLAGS))
endef
# The common libraries
#
QEMU_SYSTEM_LDLIBS := -lm
ifeq ($(HOST_OS),windows)
QEMU_SYSTEM_LDLIBS += -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
# Required to avoid compilation errors when targetting i386 with newer
# XCode toolchain.
MY_LDFLAGS32 += -Wl,-read_only_relocs,suppress
# SDK 10.6+ doesn't have __dyld_func_lookup anymore. Dynamic library lookup symbols
# are instead resolved at runtime
OSX_VERSION_MAJOR := $(shell echo $(mac_sdk_version) | cut -d . -f 2)
OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6 := $(shell [ $(OSX_VERSION_MAJOR) -ge 6 ] && echo true)
ifeq ($(OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6),true)
QEMU_SYSTEM_LDLIBS += -undefined dynamic_lookup
endif
endif
# Build libext4_utils and related modules/
include $(LOCAL_PATH)/distrib/zlib-1.2.8/sources.make
include $(LOCAL_PATH)/distrib/libsparse/sources.mk
include $(LOCAL_PATH)/distrib/libselinux/sources.mk
include $(LOCAL_PATH)/distrib/ext4_utils/sources.mk
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...
# Usage: $(eval $(call insert-windows-icon))
define insert-windows-icon
LOCAL_PREBUILT_OBJ_FILES += images/emulator_icon$(LOCAL_MODULE_BITS).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_icon32.o: $(LOCAL_PATH)/images/android_icon.rc
@echo "Windres (x86): $@"
$(MY_WINDRES) --target=pe-i386 $< -I $(LOCAL_PATH)/images -o $@
$(LOCAL_PATH)/images/emulator_icon64.o: $(LOCAL_PATH)/images/android_icon.rc
@echo "Windres (x86_64): $@"
$(MY_WINDRES) --target=pe-x86-64 $< -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
# Note: the same binary handles x86 and x86_64
EMULATOR_TARGET_ARCH := x86
include $(LOCAL_PATH)/Makefile.target
EMULATOR_TARGET_ARCH := mips
include $(LOCAL_PATH)/Makefile.target
EMULATOR_TARGET_ARCH := mips64
include $(LOCAL_PATH)/Makefile.qemu-launcher
EMULATOR_TARGET_ARCH := arm64
include $(LOCAL_PATH)/Makefile.qemu-launcher
##############################################################################
##############################################################################
###
### emulator: LAUNCHER FOR TARGET-SPECIFIC EMULATOR
###
# NOTE: Build as 32-bit or 64-bit executable, depending on the value of
# EMULATOR_PROGRAM_BITNESS.
ifeq (32,$(EMULATOR_PROGRAM_BITNESS))
$(call start-emulator-program, emulator)
else
$(call start-emulator64-program, emulator)
endif
LOCAL_SRC_FILES := android/main-emulator.c
ifeq (32,$(EMULATOR_PROGRAM_BITNESS))
LOCAL_STATIC_LIBRARIES := emulator-common
# Ensure this is always built, even if 32-bit binaries are disabled.
LOCAL_IGNORE_BITNESS := true
else
LOCAL_STATIC_LIBRARIES := emulator64-common
endif
LOCAL_LDLIBS += -lstdc++
ifeq ($(HOST_OS),windows)
$(eval $(call insert-windows-icon))
endif
$(call end-emulator-program)
include $(LOCAL_PATH)/Makefile.tests
##############################################################################
##############################################################################
###
### GPU emulation libraries
###
### Build directly from sources when using the standalone build.
###
ifeq (true,$(BUILD_STANDALONE_EMULATOR))
ifeq (,$(strip $(wildcard $(EMULATOR_EMUGL_SOURCES_DIR))))
$(error Cannot find GPU emulation sources directory: $(EMULATOR_EMUGL_SOURCES_DIR))
endif
# TODO(digit): Remove the line below.
BUILD_EMULATOR_OPENGL := true
BUILD_EMULATOR_HOST_OPENGL := true
include $(EMULATOR_EMUGL_SOURCES_DIR)/Android.mk
endif
## VOILA!!
endif # BUILD_EMULATOR == true || BUILD_STANDALONE_EMULATOR == true