| 1 |
# -*- Makefile -*- |
| 2 |
|
| 3 |
# This file allows ACE and applications using ACE GNU Makefiles to be built for |
| 4 |
# Android by cross compiling on Linux. |
| 5 |
# |
| 6 |
# See here for latest documentation on how to invoke the NDK: |
| 7 |
# https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md |
| 8 |
|
| 9 |
# We always include config-android.h on Android platforms. |
| 10 |
ACE_PLATFORM_CONFIG ?= config-android.h |
| 11 |
|
| 12 |
# Common Linux Functionality |
| 13 |
include $(ACE_ROOT)/include/makeinclude/platform_linux_common.GNU |
| 14 |
|
| 15 |
# as of NDK r6 inlining is required |
| 16 |
inline ?= 1 |
| 17 |
|
| 18 |
#No rwho on Android |
| 19 |
rwho = 0 |
| 20 |
|
| 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. |
| 26 |
versioned_so = 3 |
| 27 |
|
| 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 |
| 30 |
|
| 31 |
# Make sure android_abi or ANDROID_ABI are defined and they are the same. |
| 32 |
ifndef android_abi |
| 33 |
ifdef ANDROID_ABI |
| 34 |
android_abi := $(ANDROID_ABI) |
| 35 |
else |
| 36 |
$(error android_abi or ANDROID_ABI must be defined) |
| 37 |
endif |
| 38 |
else |
| 39 |
ANDROID_ABI := $(android_abi) |
| 40 |
endif |
| 41 |
|
| 42 |
# Alias neon |
| 43 |
ifeq ($(android_abi), neon) |
| 44 |
android_abi := armeabi-v7a-with-neon |
| 45 |
endif |
| 46 |
|
| 47 |
android_neon ?= 1 |
| 48 |
ifeq ($(android_abi),armeabi-v7a-with-neon) |
| 49 |
android_abi := armeabi-v7a |
| 50 |
android_neon := 1 |
| 51 |
endif |
| 52 |
|
| 53 |
ifeq ($(android_abi),armeabi-v7a) |
| 54 |
CROSS_COMPILE := armv7a-linux-androideabi |
| 55 |
ifeq ($(android_neon),1) |
| 56 |
FLAGS_C_CC += -mfpu=neon |
| 57 |
else |
| 58 |
FLAGS_C_CC += -mfpu=vfpv3-d16 |
| 59 |
endif |
| 60 |
|
| 61 |
else ifeq ($(android_abi),arm64-v8a) |
| 62 |
CROSS_COMPILE := aarch64-linux-android |
| 63 |
|
| 64 |
else ifeq ($(android_abi),x86) |
| 65 |
CROSS_COMPILE := i686-linux-android |
| 66 |
|
| 67 |
else ifeq ($(android_abi),x86_64) |
| 68 |
CROSS_COMPILE := x86_64-linux-android |
| 69 |
endif |
| 70 |
|
| 71 |
ifndef CROSS_COMPILE |
| 72 |
$(error android_abi $(android_abi) is not valid) |
| 73 |
endif |
| 74 |
|
| 75 |
ifdef android_ndk |
| 76 |
ifndef android_api |
| 77 |
$(error android_ndk also requires defining android_api) |
| 78 |
endif |
| 79 |
|
| 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)- |
| 83 |
endif |
| 84 |
|
| 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 |
| 89 |
|
| 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 |
| 96 |
|
| 97 |
else # Standalone Toolchain |
| 98 |
CROSS_COMPILE := $(CROSS_COMPILE)- |
| 99 |
|
| 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- |
| 108 |
endif |
| 109 |
endif |
| 110 |
|
| 111 |
# Export so child processes can use tools from the same toolchain. |
| 112 |
export CROSS_COMPILE |
| 113 |
endif |
| 114 |
|
| 115 |
ifeq ($(threads),1) |
| 116 |
CPPFLAGS += -D_REENTRANT |
| 117 |
ifdef PLATFORM_AIO_SUPPORT |
| 118 |
CPPFLAGS += $(PLATFORM_AIO_SUPPORT) |
| 119 |
endif |
| 120 |
endif # threads |
| 121 |
|
| 122 |
# Use -pipes by default |
| 123 |
pipes ?= 1 |
| 124 |
|
| 125 |
# Use LLD, the LLVM linker as recommended by Google |
| 126 |
android_set_lld ?= 1 |
| 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 |
| 131 |
endif |
| 132 |
|
| 133 |
include $(ACE_ROOT)/include/makeinclude/platform_clang_common.GNU |
| 134 |
|
| 135 |
OCFLAGS ?= -O3 |
| 136 |
OCCFLAGS ?= -O3 |
| 137 |
|
| 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. |
| 144 |
ifeq ($(ssl),1) |
| 145 |
PLATFORM_SSL_LDFLAGS += --exclude-libs libcrypto.a,libssl.a |
| 146 |
endif |
| 147 |
|
| 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) |
| 152 |
define SHLIBBUILD |
| 153 |
$(file >$(SHOBJS_FILE), $^) |
| 154 |
$(SHR_FILTER) $(SOLINK.cc) $(SO_OUTPUT_FLAG) $@ @$(SHOBJS_FILE) $(LDFLAGS) $(ACE_SHLIBS) $(LIBS) |
| 155 |
endef |
| 156 |
endif |