8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-02 09:20:39 +01:00

Android port, both armv7a & aarch64

This commit is contained in:
AlexPeshkoff 2021-02-05 21:06:20 +03:00
parent 9183d2ca60
commit ecb17cef2a
15 changed files with 168 additions and 101 deletions

View File

@ -1,30 +1,18 @@
ifeq ($(NDK),)
$(error Must export NDK location before building for Android)
ifeq ($(NDK_TOOLCHAIN),)
$(error Must export standalone NDK_TOOLCHAIN location before building for Android - use NDK's build/tools/make-standalone-toolchain.sh to build)
endif
NDK_ROOT:=$(NDK)
#NDK_LOG:=1
include $(NDK)/build/core/init.mk
NDK_ROOT:=$(NDK_TOOLCHAIN)
TOOLCHAIN_DIR:=$(foreach chain, $(NDK_ALL_TOOLCHAINS), $(if $(findstring aarch64, $(chain)), $(chain), ))
# Filter out clang
TEMP_LIST_DIR := $(foreach chain, $(TOOLCHAIN_DIR), $(if $(findstring clang, $(chain)), , $(chain)))
ifdef TEMP_LIST_DIR
TOOLCHAIN_DIR := $(TEMP_LIST_DIR)
endif
# use freshmost compiler
TOOLCHAIN_DIR:=$(lastword $(TOOLCHAIN_DIR))
CROSS_SYSROOT:=$(NDK_TOOLCHAIN)/sysroot
CROSS_PREFIX24:=$(NDK_TOOLCHAIN)/bin/aarch64-linux-android24-
CROSS_PREFIX:=$(NDK_TOOLCHAIN)/bin/aarch64-linux-android-
ifeq ($(HOST_TAG64),)
HOST_TAG64:=linux-x86
endif
NDK_TOOLCHAIN_VERSION:=$(shell echo $(TOOLCHAIN_DIR) | awk -F - '{print $$NF;}')
CROSS_FLAGS:=--sysroot=$(CROSS_SYSROOT) \
-I$(CROSS_SYSROOT)/usr/include -I$(ROOT)/gen/cross
CROSS_PLATFORM:=$(NDK)/platforms/android-24/arch-arm64
CROSS_PREFIX:=$(NDK)/toolchains/$(TOOLCHAIN_DIR)/prebuilt/$(HOST_TAG64)/bin/aarch64-linux-android-
CXX:=$(CROSS_PREFIX)g++
CC:=$(CROSS_PREFIX)gcc
CXX:=$(CROSS_PREFIX24)clang++
CC:=$(CROSS_PREFIX24)clang
AR:=$(CROSS_PREFIX)ar
AS:=$(CROSS_PREFIX)as
LD:=$(CROSS_PREFIX)ld
@ -34,12 +22,15 @@ OBJDUMP:=$(CROSS_PREFIX)objdump
RANLIB:=$(CROSS_PREFIX)ranlib
STRIP:=$(CROSS_PREFIX)strip
COMMON_FLAGS=-ggdb -DFB_SEND_FLAGS=MSG_NOSIGNAL -DLINUX -DANDROID -DARM64 -pipe -MMD -fPIC -fmessage-length=0 \
-I$(ROOT)/extern/libtommath --sysroot=$(CROSS_PLATFORM) \
-I$(CROSS_PLATFORM)/usr/include -I$(ROOT)/gen/cross -fsigned-char \
-I$(NDK)/sources/cxx-stl/gnu-libstdc++/$(NDK_TOOLCHAIN_VERSION)/include \
-I$(NDK)/sources/cxx-stl/gnu-libstdc++/$(NDK_TOOLCHAIN_VERSION)/libs/arm64-v8a/include
export CXX
export CC
export AR
export CROSS_FLAGS
COMMON_FLAGS=-ggdb -DFB_SEND_FLAGS=MSG_NOSIGNAL -DLINUX -DANDROID -DARM64 -pipe -MMD -fPIC -fmessage-length=0 \
-I$(ROOT)/extern/libtommath -I$(ROOT)/extern/libtomcrypt/src/headers \
$(CROSS_FLAGS) -fsigned-char \
-Wno-inline-new-delete
OPTIMIZE_FLAGS=-fno-omit-frame-pointer
WARN_FLAGS=-Wall -Wno-switch -Wno-parentheses -Wno-unknown-pragmas -Wno-unused-variable
@ -49,9 +40,8 @@ DEV_FLAGS=$(COMMON_FLAGS) $(WARN_FLAGS)
CROSS_CONFIG=android.arm64
LDFLAGS += --sysroot=$(CROSS_PLATFORM) -L$(NDK)/sources/cxx-stl/gnu-libstdc++/$(NDK_TOOLCHAIN_VERSION)/libs/arm64-v8a \
-L$(NDK)/sources/cxx-stl/gnu-libstdc++/libs/arm64-v8a
DroidLibs := -lm -ldl -lsupc++
LDFLAGS += --sysroot=$(CROSS_SYSROOT) -static-libstdc++
DroidLibs := -lm -ldl $(DECLIB) $(RE2LIB)
LINK_LIBS = $(DroidLibs)
STATICLINK_LIBS = $(DroidLibs)

View File

@ -1,68 +1,17 @@
ifeq ($(NDK),)
$(error Must export NDK location before building for Android)
ifeq ($(NDK_TOOLCHAIN),)
$(error Must export standalone NDK_TOOLCHAIN location before building for Android - use NDK's build/tools/make-standalone-toolchain.sh to build)
endif
NDK_ROOT:=$(NDK)
#NDK_LOG:=1
include $(NDK)/build/core/init.mk
NDK_ROOT:=$(NDK_TOOLCHAIN)
TOOLCHAIN:=$(foreach chain, $(NDK_ALL_TOOLCHAINS), $(if $(findstring arm, $(chain)), $(chain), ))
# Filter out clang
TEMP_TC := $(foreach chain, $(TOOLCHAIN), $(if $(findstring clang, $(chain)), , $(chain)))
ifneq ($(strip $(TEMP_TC)),)
TOOLCHAIN := $(TEMP_TC)
endif
# use freshmost compiler
TOOLCHAIN:=$(lastword $(TOOLCHAIN))
TOOLCHAIN_ARCH:=
-include $(NDK)/build/core/toolchains/$(TOOLCHAIN)/config.mk
-include $(NDK)/build/core/toolchains/$(TOOLCHAIN)/setup.mk
ifeq ($(TOOLCHAIN_ARCH),arm)
TOOL_PATH:=$(NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin
CROSS_PREFIX:=$(TOOL_PATH)/$(TOOLCHAIN_NAME)-
#Now it's time to decide upon clang/clang++
CLANG_NAME:=$(subst arm-,armv7a-,$(TOOLCHAIN_NAME))
CLANG_NUM:=$(shell mi=256; for i in `seq 24 $$mi`; do [ -e $(TOOL_PATH)/$(CLANG_NAME)$$i-clang ] && [ $$i -le $$mi ] && mi=$$i; done; echo $$mi)
CXX:=$(TOOL_PATH)/$(CLANG_NAME)$(CLANG_NUM)-clang++
CC:=$(TOOL_PATH)/$(CLANG_NAME)$(CLANG_NUM)-clang
#CROSS_FLAGS:=--sysroot=$(NDK)/sysroot \
# -I$(ROOT)/gen/cross \
# -I$(NDK)/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1
CROSS_FLAGS:=--sysroot=$(NDK)/toolchains/llvm/prebuilt/linux-x86_64/sysroot \
-I$(ROOT)/gen/cross
else
#TOOLCHAIN_ARCH
ifeq ($(HOST_TAG64),)
HOST_TAG64:=linux-x86
endif
NDK_TOOLCHAIN_VERSION:=$(shell echo $(TOOLCHAIN_DIR) | awk -F - '{print $$NF;}')
CROSS_PLATFORM:=$(NDK)/platforms
ALEVEL:=$(shell for i in `seq 256`; do [ -d $(CROSS_PLATFORM)/android-$${i} ] && adir=$${i}; done; echo $${adir})
CROSS_PLATFORM:=$(CROSS_PLATFORM)/android-$(ALEVEL)/arch-arm
CROSS_PREFIX:=$(NDK)/toolchains/$(TOOLCHAIN_DIR)/prebuilt/$(HOST_TAG64)/bin/arm-linux-androideabi-
CXX:=$(CROSS_PREFIX)g++
CC:=$(CROSS_PREFIX)gcc
CROSS_FLAGS=--sysroot=$(CROSS_PLATFORM) \
-I$(CROSS_PLATFORM)/usr/include -I$(ROOT)/gen/cross \
-I$(NDK)/sources/cxx-stl/gnu-libstdc++/$(NDK_TOOLCHAIN_VERSION)/include \
-I$(NDK)/sources/cxx-stl/gnu-libstdc++/$(NDK_TOOLCHAIN_VERSION)/libs/armeabi/include
endif
#TOOLCHAIN_ARCH
CROSS_SYSROOT:=$(NDK_TOOLCHAIN)/sysroot
CROSS_PREFIX24:=$(NDK_TOOLCHAIN)/bin/armv7a-linux-androideabi24-
CROSS_PREFIX:=$(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-
CROSS_FLAGS:=--sysroot=$(CROSS_SYSROOT) \
-I$(CROSS_SYSROOT)/usr/include -I$(ROOT)/gen/cross
CXX:=$(CROSS_PREFIX24)clang++
CC:=$(CROSS_PREFIX24)clang
AR:=$(CROSS_PREFIX)ar
AS:=$(CROSS_PREFIX)as
LD:=$(CROSS_PREFIX)ld
@ -75,12 +24,12 @@ STRIP:=$(CROSS_PREFIX)strip
export CXX
export CC
export AR
export CROSS_FLAGS
COMMON_FLAGS=-ggdb -DFB_SEND_FLAGS=MSG_NOSIGNAL -DLINUX -DANDROID -DARM -pipe -MMD -fPIC -fmessage-length=0 \
-I$(ROOT)/extern/libtommath -I$(ROOT)/extern/libtomcrypt/src/headers \
$(CROSS_FLAGS) -fsigned-char
$(CROSS_FLAGS) -fsigned-char \
-Wno-inline-new-delete
OPTIMIZE_FLAGS=-fno-omit-frame-pointer
WARN_FLAGS=-Wall -Wno-switch -Wno-parentheses -Wno-unknown-pragmas -Wno-unused-variable
@ -90,13 +39,13 @@ DEV_FLAGS=$(COMMON_FLAGS) $(WARN_FLAGS)
CROSS_CONFIG=android.arme
LDFLAGS += --sysroot=$(CROSS_PLATFORM) -L$(NDK)/sources/cxx-stl/gnu-libstdc++/$(NDK_TOOLCHAIN_VERSION)/libs/armeabi \
-L$(NDK)/sources/cxx-stl/gnu-libstdc++/libs/armeabi
LDFLAGS += --sysroot=$(CROSS_PLATFORM) -static-libstdc++
DroidLibs := -lm -ldl $(DECLIB) $(RE2LIB)
UDR_SUPPORT_LIBS :=
LINK_LIBS = $(DroidLibs)
SO_LINK_LIBS = $(DroidLibs)
STATICLINK_LIBS = $(DroidLibs)
EXE_LINK_OPTIONS= $(LDFLAGS) $(UNDEF_FLAGS) $(LIB_PATH_OPTS) $(LINK_EMPTY_SYMBOLS) -pie
LIB_LINK_OPTIONS= $(LDFLAGS) -shared

3
extern/icu/android/Readme.txt vendored Normal file
View File

@ -0,0 +1,3 @@
This directory contains files needed for cross-build of IBM ICU 63.1 for Android
on amd64 linux host. Data file (icudt63l.dat) should be taken from windows build.

27
extern/icu/android/aarch64/config.sh vendored Executable file
View File

@ -0,0 +1,27 @@
#!/bin/sh
. ../env.sh
../source/configure --prefix=$(pwd)/prebuilt \
--host=aarch64-android-linux \
--enable-static=no \
--enable-shared \
--enable-extras=no \
--enable-strict=no \
--enable-icuio=no \
--enable-layout=no \
--enable-layoutex=no \
--enable-tools=no \
--enable-tests=no \
--enable-samples=no \
--enable-renaming \
--enable-dyload \
--with-cross-build=$CROSS_BUILD_DIR \
CFLAGS='-Os' \
CXXFLAGS='--std=c++11' \
LDFLAGS='-static-libstdc++' \
CC=aarch64-linux-android24-clang \
CXX=aarch64-linux-android24-clang++ \
AR=aarch64-linux-android-ar \
RANLIB=aarch64-linux-android-ranlib \
--with-data-packaging=archive

6
extern/icu/android/aarch64/mk.sh vendored Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
. ../env.sh
make -j15 && make install

27
extern/icu/android/armv7a/config.sh vendored Executable file
View File

@ -0,0 +1,27 @@
#!/bin/sh
. ../env.sh
../source/configure --prefix=$(pwd)/prebuilt \
--host=arm-linux-androideabi \
--enable-static=no \
--enable-shared \
--enable-extras=no \
--enable-strict=no \
--enable-icuio=no \
--enable-layout=no \
--enable-layoutex=no \
--enable-tools=no \
--enable-tests=no \
--enable-samples=no \
--enable-renaming \
--enable-dyload \
--with-cross-build=$CROSS_BUILD_DIR \
CFLAGS='-Os -march=armv7-a -mfloat-abi=softfp -mfpu=neon' \
CXXFLAGS='--std=c++11 -march=armv7-a -mfloat-abi=softfp -mfpu=neon' \
LDFLAGS='-static-libstdc++ -march=armv7-a -Wl,--fix-cortex-a8' \
CC=arm-linux-androideabi-clang \
CXX=arm-linux-androideabi-clang++ \
AR=arm-linux-androideabi-ar \
RANLIB=arm-linux-androideabi-ranlib \
--with-data-packaging=archive

6
extern/icu/android/armv7a/mk.sh vendored Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
. ../env.sh
make -j15 && make install

5
extern/icu/android/env.sh vendored Normal file
View File

@ -0,0 +1,5 @@
#!/bin/sh
export CROSS_BUILD_DIR=`realpath ../linux`
export ANDROID_NDK=${NDK}
export ANDROID_TOOLCHAIN=${NDK_TOOLCHAIN}
export PATH=$ANDROID_TOOLCHAIN/bin:$PATH

16
extern/icu/android/linux/config.sh vendored Executable file
View File

@ -0,0 +1,16 @@
#!/bin/sh
../source/runConfigureICU Linux --prefix=$PWD/prebuilt \
CFLAGS="-Os" \
CXXFLAGS="--std=c++11" \
--enable-static \
--enable-shared=no \
--enable-extras=no \
--enable-strict=no \
--enable-icuio=no \
--enable-layout=no \
--enable-layoutex=no \
--enable-tools \
--enable-tests=no \
--enable-samples=no \
--enable-dyload \
--with-data-packaging=archive

3
extern/icu/android/linux/mk.sh vendored Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
make -j15 && make install

6
extern/icu/android/renameLinks.sh vendored Normal file
View File

@ -0,0 +1,6 @@
MAJOR=52
MINOR=1
rm -f libicu*so
for i in libicu*.${MINOR}; do mv $i `basename $i .${MINOR}`; done
for i in libicu*.${MAJOR}; do ln -s $i `basename $i .${MAJOR}`; done

BIN
extern/icu/icu_android.tar.xz vendored Normal file

Binary file not shown.

View File

@ -118,13 +118,15 @@
#ifdef WIN32
#define LTC_CRIT_SECT
#endif
#ifndef USE_LTM
#define USE_LTM
#endif
#ifndef LTM_DESC
#define LTM_DESC
#endif
#endif // WIN32
/* shortcut to disable automatic inclusion */
#if defined LTC_NOTHING && !defined LTC_EASY

View File

@ -32,6 +32,10 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <limits.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dlfcn.h>
@ -138,7 +142,13 @@ ModuleLoader::Module* ModuleLoader::loadModule(ISC_STATUS* status, const Firebir
system(command.c_str());
#endif
return FB_NEW_POOL(*getDefaultMemoryPool()) DlfcnModule(*getDefaultMemoryPool(), modPath, module);
Firebird::PathName linkPath = modPath;
char b[PATH_MAX];
const char* newPath = realpath(modPath.c_str(), b);
if (newPath)
linkPath = newPath;
return FB_NEW_POOL(*getDefaultMemoryPool()) DlfcnModule(*getDefaultMemoryPool(), linkPath, module);
}
DlfcnModule::~DlfcnModule()

View File

@ -65,9 +65,6 @@ const char* const ucTemplate = "lib/libicuuc.%s.dylib";
#elif defined(HPUX)
const char* const inTemplate = "libicui18n.sl.%s";
const char* const ucTemplate = "libicuuc.sl.%s";
#elif defined(ANDROID)
const char* const inTemplate = "libicui18n.so";
const char* const ucTemplate = "libicuuc.so";
#else
const char* const inTemplate = "libicui18n.so.%s";
const char* const ucTemplate = "libicuuc.so.%s";
@ -134,7 +131,7 @@ void BaseICU::initialize(ModuleLoader::Module* module)
getEntryPoint("u_setTimeZoneFilesDirectory", module, uSetTimeZoneFilesDirectory, true);
getEntryPoint("u_setDataDirectory", module, uSetDataDirectory, true);
#if defined(WIN_NT) || defined(DARWIN)
#if defined(WIN_NT) || defined(DARWIN) || defined(ANDROID)
if (uSetDataDirectory)
{
// call uSetDataDirectory only if .dat file is exists at same folder
@ -143,6 +140,7 @@ void BaseICU::initialize(ModuleLoader::Module* module)
PathName path, file, fullName;
PathUtils::splitLastComponent(path, file, module->fileName);
#ifdef WIN_NT
// icuucXX.dll -> icudtXX.dll
file.replace(3, 2, "dt");
@ -150,6 +148,17 @@ void BaseICU::initialize(ModuleLoader::Module* module)
const FB_SIZE_T pos = file.find_last_of('.');
file.erase(pos);
file.append("l.dat");
#else
// libicuuc.so.XX -> icudtXX
const FB_SIZE_T pos = file.find_last_of('.');
if (pos > 0 && pos != file.npos)
{
file.replace(0, pos + 1, "icudt");
}
// icudtXX -> icudtXXl.dat
file += "l.dat";
#endif
PathUtils::concatPath(fullName, path, file);
@ -405,6 +414,14 @@ static GlobalPtr<UnicodeUtil::ICUModules> icuModules;
static ModuleLoader::Module* formatAndLoad(const char* templateName,
int majorVersion, int minorVersion)
{
#ifdef ANDROID
static ModuleLoader::Module* dat = ModuleLoader::loadModule(NULL,
fb_utils::getPrefix(Firebird::IConfigManager::DIR_LIB, "libicudata.so"));
Firebird::PathName newName = fb_utils::getPrefix(Firebird::IConfigManager::DIR_LIB, templateName);
templateName = newName.c_str();
#endif
ModuleLoader::Module* module = nullptr;
// System-wide ICU have no version number at file names