3 # This file allows ACE and applications using ACE GNU Makefiles to be built for
4 # Android by cross compiling on Linux.
6 # See here for latest documentation on how to invoke the NDK:
7 # https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md
9 # We always include config-android.h on Android platforms.
10 ACE_PLATFORM_CONFIG ?= config-android.h
12 # Common Linux Functionality
13 include $(ACE_ROOT)/include/makeinclude/platform_linux_common.GNU
15 # as of NDK r6 inlining is required
21 # Android Studio does not seem to recognize so files with versions, but if
22 # trying to add gnuace-built libraries as imported libraries in CMake in a
23 # Android Studio project, at runtime apparently the Android loader needs the
24 # SONAME be set to the filename or else it was fail trying to load the so file
25 # path from the host computer.
28 # This section deals with selecting the architecture/compiler
29 # As of writing information on ABIs can be found at https://developer.android.com/ndk/guides/abis
31 # Make sure android_abi or ANDROID_ABI are defined and they are the same.
34 android_abi := $(ANDROID_ABI)
36 $(error android_abi or ANDROID_ABI must be defined)
39 ANDROID_ABI := $(android_abi)
43 ifeq ($(android_abi), neon)
44 android_abi := armeabi-v7a-with-neon
48 ifeq ($(android_abi),armeabi-v7a-with-neon)
49 android_abi := armeabi-v7a
53 ifeq ($(android_abi),armeabi-v7a)
54 CROSS_COMPILE := armv7a-linux-androideabi
55 ifeq ($(android_neon),1)
56 FLAGS_C_CC += -mfpu=neon
58 FLAGS_C_CC += -mfpu=vfpv3-d16
61 else ifeq ($(android_abi),arm64-v8a)
62 CROSS_COMPILE := aarch64-linux-android
64 else ifeq ($(android_abi),x86)
65 CROSS_COMPILE := i686-linux-android
67 else ifeq ($(android_abi),x86_64)
68 CROSS_COMPILE := x86_64-linux-android
72 $(error android_abi $(android_abi) is not valid)
77 $(error android_ndk also requires defining android_api)
80 android_ndk_tools ?= $(wildcard $(android_ndk)/toolchains/llvm/prebuilt/*/bin)
81 ifndef android_ndk_tool_prefix
82 android_ndk_tool_prefix := $(CROSS_COMPILE)$(android_api)-
85 # We don't want this being used again except to signal that this is a
86 # cross-compile build. If it is then the resulting command probably won't
87 # exist and cause an error.
88 CROSS_COMPILE := THIS_VALUE_SHOULD_NOT_BE_USED
90 # Ignore value of CROSS_COMPILE because ar doesn't match clang like in
91 # platform_clang_common.GNU.
92 override_cross_compile = 1
93 CC = $(android_ndk_tools)/$(android_ndk_tool_prefix)clang
94 CXX = $(android_ndk_tools)/$(android_ndk_tool_prefix)clang++
95 AR = $(android_ndk_tools)/llvm-ar
97 else # Standalone Toolchain
98 CROSS_COMPILE := $(CROSS_COMPILE)-
100 ifeq ($(android_abi),armeabi-v7a)
101 # According to Google the armv7a-linux-androideabi- prefix should be
102 # preferred because it produces more efficient code. However if it doesn't
103 # exist since we're using an older NDK we have to fallback to
104 # arm-linux-androideabi-. This isn't a problem when directly using the NDK
105 # because the NDKs we support for that have armv7a-* clangs.
106 ifeq (,$(shell command -v $(CROSS_COMPILE)clang $(ACE_NUL_STDERR)))
107 CROSS_COMPILE := arm-linux-androideabi-
111 # Export so child processes can use tools from the same toolchain.
116 CPPFLAGS += -D_REENTRANT
117 ifdef PLATFORM_AIO_SUPPORT
118 CPPFLAGS += $(PLATFORM_AIO_SUPPORT)
122 # Use -pipes by default
125 # Use LLD, the LLVM linker as recommended by Google
127 ifeq ($(android_set_lld),1)
128 # The other two arguments are explained by
129 # https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#additional-required-arguments
130 LDFLAGS += -fuse-ld=lld -Wl,--build-id=sha1 -Wl,--no-rosegment
133 include $(ACE_ROOT)/include/makeinclude/platform_clang_common.GNU
138 # Android preloads the (almost certainly incompatible) system SSL library
139 # (either OpenSSL or BoringSSL) for the Java Android API, so we must:
140 # 1. Statically link OpenSSL to this library
141 # 2. Keep our OpenSSL symbols internal
142 # Number 1 is described in ACE-INSTALL.html.
143 # We are doing number 2 here.
145 PLATFORM_SSL_LDFLAGS += --exclude-libs libcrypto.a,libssl.a
148 # link step to avoid 'command line too long' error on Windows
149 ifeq ($(OS), Windows_NT)
150 SHOBJS_FILE = $(VSHDIR)$(MAKEFILE)_object_list.tmp
151 CLEANUP_OBJS += $(SHOBJS_FILE)
153 $(file >$(SHOBJS_FILE), $^)
154 $(SHR_FILTER) $(SOLINK.cc) $(SO_OUTPUT_FLAG) $@ @$(SHOBJS_FILE) $(LDFLAGS) $(ACE_SHLIBS) $(LIBS)