Skip to content

Commit

Permalink
Android / JNI (neuromore#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberjunk authored Apr 14, 2020
1 parent 21a0e96 commit ae139bc
Show file tree
Hide file tree
Showing 106 changed files with 5,637 additions and 644 deletions.
158 changes: 158 additions & 0 deletions build/make/Makefile.android-linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#
# ANDROID CLANG MAKEFILE FOR LINUX
#

# REQUIRED ENVIRONMENT ARGS:
# ANDROID_NDK_HOME Location of Android NDK
# JAVA_HOME Location of Java JDK

# android ndk, toolchain and api version
TOOLCHAIN = $(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/linux-x86_64
API = 21

#########################################################################################
# target platforms
# builds for ARM by default
# for x86/x64 use: make [..] ANDROID_TARGET=x86

ifeq ($(ANDROID_TARGET),x86)
TARGET_X86 = i686-linux-android
TARGET_X64 = x86_64-linux-android
TARGET_AR_X86 = i686-linux-android
TARGET_AR_X64 = x86_64-linux-android
SYSROOT_X86 = $(ANDROID_NDK_HOME)/platforms/android-$(API)/arch-x86
SYSROOT_X64 = $(ANDROID_NDK_HOME)/platforms/android-$(API)/arch-x86_64
ARCHFLAGS_X86 = -msse -msse2 -msse3
ARCHFLAGS_X64 = -msse -msse2 -msse3
else
TARGET_X86 = armv7a-linux-androideabi
TARGET_X64 = aarch64-linux-android
TARGET_AR_X86 = arm-linux-androideabi
TARGET_AR_X64 = aarch64-linux-android
SYSROOT_X86 = $(ANDROID_NDK_HOME)/platforms/android-$(API)/arch-arm
SYSROOT_X64 = $(ANDROID_NDK_HOME)/platforms/android-$(API)/arch-arm64
ARCHFLAGS_X86 = -DANDROID_ARM_NEON=ON -march=armv7-a -mfloat-abi=softfp -mfpu=neon-fp16
ARCHFLAGS_X64 = -DANDROID_ARM_NEON=ON -march=armv8-a
endif

#########################################################################################

# flags shared between all
FLAGS = -O3 \
-fpic \
-DANDROID \
-D__ANDROID_API__=$(API) \
-D_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING \
-Wno-deprecated-declarations

# C Compiler
CC_X86 = $(TOOLCHAIN)/bin/$(TARGET_X86)$(API)-clang
CC_X64 = $(TOOLCHAIN)/bin/$(TARGET_X64)$(API)-clang
CFLAGS_X86 = -static -m32 --target=$(TARGET_X86) -isystem $(ANDROID_NDK_HOME)/sysroot/usr/include/$(TARGET_AR_X86) $(ARCHFLAGS_X86) $(FLAGS)
CFLAGS_X64 = -static -m64 --target=$(TARGET_X64) -isystem $(ANDROID_NDK_HOME)/sysroot/usr/include/$(TARGET_AR_X64) $(ARCHFLAGS_X64) $(FLAGS)

# C++ Compiler
CXX_X86 = $(TOOLCHAIN)/bin/$(TARGET_X86)$(API)-clang++
CXX_X64 = $(TOOLCHAIN)/bin/$(TARGET_X64)$(API)-clang++
CXXFLAGS_X86 = -static -m32 -target $(TARGET_X86) -isystem $(ANDROID_NDK_HOME)/sysroot/usr/include/$(TARGET_AR_X86) $(ARCHFLAGS_X86) $(FLAGS)
CXXFLAGS_X64 = -static -m64 -target $(TARGET_X64) -isystem $(ANDROID_NDK_HOME)/sysroot/usr/include/$(TARGET_AR_X64) $(ARCHFLAGS_X64) $(FLAGS)

# JAVA JDK
JAR = "$(JAVA_HOME)/bin/jar"
JAVAC = "$(JAVA_HOME)/bin/javac"

# File Operations
define deletefilepattern
find $(1) -type f -name '$(2)' -delete
endef

# AR
LIB_X86 = $(TOOLCHAIN)/bin/$(TARGET_AR_X86)-ar
LIB_X64 = $(TOOLCHAIN)/bin/$(TARGET_AR_X64)-ar
LIBFLAGS_X86 = rcs
LIBFLAGS_X64 = rcs

# AR Functions
define createlib32
$(LIB_X86) $(LIBFLAGS_X86) $(LIBDIR_X86)/$(1).a $(2)
endef
define createlib64
$(LIB_X64) $(LIBFLAGS_X64) $(LIBDIR_X64)/$(1).a $(2)
endef

# Linker
LINK_X86 = $(CXX_X86)
LINK_X64 = $(CXX_X64)
LINKFLAGS_X86 = --sysroot=$(SYSROOT_X86) -target $(TARGET_X86) -isystem $(ANDROID_NDK_HOME)/sysroot/usr/include/$(TARGET_AR_X86) $(ARCHFLAGS_X86) $(FLAGS)
LINKFLAGS_X64 = --sysroot=$(SYSROOT_X64) -target $(TARGET_X64) -isystem $(ANDROID_NDK_HOME)/sysroot/usr/include/$(TARGET_AR_X64) $(ARCHFLAGS_X64) $(FLAGS)
LINKFLAGSDYN_X86 = -shared -static-libstdc++
LINKFLAGSDYN_X64 = -shared -static-libstdc++

# Additional Linker Library Path for shared libraries
LINKPATH_X86 = \
-L./lib/x86 \
-L$(SYSROOT_X86)/usr/lib/ \
-L$(TOOLCHAIN)/sysroot/usr/lib/$(TARGET_AR_X86)/$(API) \
-L$(TOOLCHAIN)/sysroot/usr/lib/$(TARGET_AR_X86)

LINKPATH_X64 = \
-L./lib/x64 \
-L$(SYSROOT_X64)/usr/lib/ \
-L$(TOOLCHAIN)/sysroot/usr/lib/$(TARGET_AR_X64)/$(API) \
-L$(TOOLCHAIN)/sysroot/usr/lib/$(TARGET_AR_X64)

# Shared Libraries for X86 and X64
LINKLIBS_ALL = -llog

# Libraries for X86 or X64
LINKLIBS_X86 = $(LINKLIBS_ALL)
LINKLIBS_X64 = $(LINKLIBS_ALL)

# Linker Functions for Executable
define createbin32
$(LINK_X86) $(LINKFLAGS_X86) $(LINKPATH_X86) $(2) $(3) $(LINKLIBS_X86) -o $(BINDIR_X86)/$(1)
endef
define createbin64
$(LINK_X64) $(LINKFLAGS_X64) $(LINKPATH_X64) $(2) $(3) $(LINKLIBS_X64) -o $(BINDIR_X64)/$(1)
endef

# Linker Functions for Shared Library
define createshared32
$(LINK_X86) $(LINKFLAGS_X86) $(LINKFLAGSDYN_X86) $(LINKPATH_X86) $(2) $(3) $(LINKLIBS_X86) -o $(LIBDIR_X86)/$(1).so
endef
define createshared64
$(LINK_X64) $(LINKFLAGS_X64) $(LINKFLAGSDYN_X64) $(LINKPATH_X64) $(2) $(3) $(LINKLIBS_X64) -o $(LIBDIR_X64)/$(1).so
endef

# Qt MOC+RCC+UIC
MOC_X86 = ../../deps/prebuilt/linux/x64/qt-moc
MOC_X64 = ../../deps/prebuilt/linux/x64/qt-moc
ifneq (,$(findstring x86,$(MAKECMDGOALS)))
MOC = $(MOC_X86)
endif
ifneq (,$(findstring x64,$(MAKECMDGOALS)))
MOC = $(MOC_X64)
endif

RCC_X86 = ../../deps/prebuilt/linux/x64/qt-rcc
RCC_X64 = ../../deps/prebuilt/linux/x64/qt-rcc
ifneq (,$(findstring x86,$(MAKECMDGOALS)))
RCC = $(RCC_X86)
endif
ifneq (,$(findstring x64,$(MAKECMDGOALS)))
RCC = $(RCC_X64)
endif

UIC_X86 = ../../deps/prebuilt/linux/x64/qt-rcc
UIC_X64 = ../../deps/prebuilt/linux/x64/qt-rcc
ifneq (,$(findstring x86,$(MAKECMDGOALS)))
UIC = $(UIC_X86)
endif
ifneq (,$(findstring x64,$(MAKECMDGOALS)))
UIC = $(UIC_X64)
endif

#####################################################################################

# Include Common Parts
include Makefile.android-shared
158 changes: 158 additions & 0 deletions build/make/Makefile.android-osx
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#
# ANDROID CLANG MAKEFILE FOR OSX
#

# REQUIRED ENVIRONMENT ARGS:
# ANDROID_NDK_HOME Location of Android NDK

# android ndk, toolchain and api version
TOOLCHAIN = $(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/darwin-x86_64
API = 21

#########################################################################################
# target platforms
# builds for ARM by default
# for x86/x64 use: make [..] ANDROID_TARGET=x86

ifeq ($(ANDROID_TARGET),x86)
TARGET_X86 = i686-linux-android
TARGET_X64 = x86_64-linux-android
TARGET_AR_X86 = i686-linux-android
TARGET_AR_X64 = x86_64-linux-android
SYSROOT_X86 = $(ANDROID_NDK_HOME)/platforms/android-$(API)/arch-x86
SYSROOT_X64 = $(ANDROID_NDK_HOME)/platforms/android-$(API)/arch-x86_64
ARCHFLAGS_X86 = -msse -msse2 -msse3
ARCHFLAGS_X64 = -msse -msse2 -msse3
else
TARGET_X86 = armv7a-linux-androideabi
TARGET_X64 = aarch64-linux-android
TARGET_AR_X86 = arm-linux-androideabi
TARGET_AR_X64 = aarch64-linux-android
SYSROOT_X86 = $(ANDROID_NDK_HOME)/platforms/android-$(API)/arch-arm
SYSROOT_X64 = $(ANDROID_NDK_HOME)/platforms/android-$(API)/arch-arm64
ARCHFLAGS_X86 = -DANDROID_ARM_NEON=ON -march=armv7-a -mfloat-abi=softfp -mfpu=neon-fp16
ARCHFLAGS_X64 = -DANDROID_ARM_NEON=ON -march=armv8-a
endif

#########################################################################################

# flags shared between all
FLAGS = -O3 \
-fpic \
-DANDROID \
-D__ANDROID_API__=$(API) \
-D_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING \
-Wno-deprecated-declarations

# C Compiler
CC_X86 = $(TOOLCHAIN)/bin/$(TARGET_X86)$(API)-clang
CC_X64 = $(TOOLCHAIN)/bin/$(TARGET_X64)$(API)-clang
CFLAGS_X86 = -static -m32 --target=$(TARGET_X86) -isystem $(ANDROID_NDK_HOME)/sysroot/usr/include/$(TARGET_AR_X86) $(ARCHFLAGS_X86) $(FLAGS)
CFLAGS_X64 = -static -m64 --target=$(TARGET_X64) -isystem $(ANDROID_NDK_HOME)/sysroot/usr/include/$(TARGET_AR_X64) $(ARCHFLAGS_X64) $(FLAGS)

# C++ Compiler
CXX_X86 = $(TOOLCHAIN)/bin/$(TARGET_X86)$(API)-clang++
CXX_X64 = $(TOOLCHAIN)/bin/$(TARGET_X64)$(API)-clang++
CXXFLAGS_X86 = -static -m32 -target $(TARGET_X86) -isystem $(ANDROID_NDK_HOME)/sysroot/usr/include/$(TARGET_AR_X86) $(ARCHFLAGS_X86) $(FLAGS)
CXXFLAGS_X64 = -static -m64 -target $(TARGET_X64) -isystem $(ANDROID_NDK_HOME)/sysroot/usr/include/$(TARGET_AR_X64) $(ARCHFLAGS_X64) $(FLAGS)

# JAVA JDK
JAVA_HOME:=`/usr/libexec/java_home`
JAR = "$(JAVA_HOME)/bin/jar"
JAVAC = "$(JAVA_HOME)/bin/javac"

# File Operations
define deletefilepattern
find $(1) -type f -name '$(2)' -delete
endef

# AR
LIB_X86 = $(TOOLCHAIN)/bin/$(TARGET_AR_X86)-ar
LIB_X64 = $(TOOLCHAIN)/bin/$(TARGET_AR_X64)-ar
LIBFLAGS_X86 = rcs
LIBFLAGS_X64 = rcs

# AR Functions
define createlib32
$(LIB_X86) $(LIBFLAGS_X86) $(LIBDIR_X86)/$(1).a $(2)
endef
define createlib64
$(LIB_X64) $(LIBFLAGS_X64) $(LIBDIR_X64)/$(1).a $(2)
endef

# Linker
LINK_X86 = $(CXX_X86)
LINK_X64 = $(CXX_X64)
LINKFLAGS_X86 = --sysroot=$(SYSROOT_X86) -target $(TARGET_X86) -isystem $(ANDROID_NDK_HOME)/sysroot/usr/include/$(TARGET_AR_X86) $(ARCHFLAGS_X86) $(FLAGS)
LINKFLAGS_X64 = --sysroot=$(SYSROOT_X64) -target $(TARGET_X64) -isystem $(ANDROID_NDK_HOME)/sysroot/usr/include/$(TARGET_AR_X64) $(ARCHFLAGS_X64) $(FLAGS)
LINKFLAGSDYN_X86 = -shared -static-libstdc++
LINKFLAGSDYN_X64 = -shared -static-libstdc++

# Additional Linker Library Path for shared libraries
LINKPATH_X86 = \
-L./lib/x86 \
-L$(SYSROOT_X86)/usr/lib/ \
-L$(TOOLCHAIN)/sysroot/usr/lib/$(TARGET_AR_X86)/$(API) \
-L$(TOOLCHAIN)/sysroot/usr/lib/$(TARGET_AR_X86)

LINKPATH_X64 = \
-L./lib/x64 \
-L$(SYSROOT_X64)/usr/lib/ \
-L$(TOOLCHAIN)/sysroot/usr/lib/$(TARGET_AR_X64)/$(API) \
-L$(TOOLCHAIN)/sysroot/usr/lib/$(TARGET_AR_X64)

# Shared Libraries for X86 and X64
LINKLIBS_ALL = -llog

# Libraries for X86 or X64
LINKLIBS_X86 = $(LINKLIBS_ALL)
LINKLIBS_X64 = $(LINKLIBS_ALL)

# Linker Functions for Executable
define createbin32
$(LINK_X86) $(LINKFLAGS_X86) $(LINKPATH_X86) $(2) $(3) $(LINKLIBS_X86) -o $(BINDIR_X86)/$(1)
endef
define createbin64
$(LINK_X64) $(LINKFLAGS_X64) $(LINKPATH_X64) $(2) $(3) $(LINKLIBS_X64) -o $(BINDIR_X64)/$(1)
endef

# Linker Functions for Shared Library
define createshared32
$(LINK_X86) $(LINKFLAGS_X86) $(LINKFLAGSDYN_X86) $(LINKPATH_X86) $(2) $(3) $(LINKLIBS_X86) -o $(LIBDIR_X86)/$(1).so
endef
define createshared64
$(LINK_X64) $(LINKFLAGS_X64) $(LINKFLAGSDYN_X64) $(LINKPATH_X64) $(2) $(3) $(LINKLIBS_X64) -o $(LIBDIR_X64)/$(1).so
endef

# Qt MOC+RCC+UIC
MOC_X86 = ../../deps/prebuilt/osx/x64/qt-moc
MOC_X64 = ../../deps/prebuilt/osx/x64/qt-moc
ifneq (,$(findstring x86,$(MAKECMDGOALS)))
MOC = $(MOC_X86)
endif
ifneq (,$(findstring x64,$(MAKECMDGOALS)))
MOC = $(MOC_X64)
endif

RCC_X86 = ../../deps/prebuilt/osx/x64/qt-rcc
RCC_X64 = ../../deps/prebuilt/osx/x64/qt-rcc
ifneq (,$(findstring x86,$(MAKECMDGOALS)))
RCC = $(RCC_X86)
endif
ifneq (,$(findstring x64,$(MAKECMDGOALS)))
RCC = $(RCC_X64)
endif

UIC_X86 = ../../deps/prebuilt/osx/x64/qt-rcc
UIC_X64 = ../../deps/prebuilt/osx/x64/qt-rcc
ifneq (,$(findstring x86,$(MAKECMDGOALS)))
UIC = $(UIC_X86)
endif
ifneq (,$(findstring x64,$(MAKECMDGOALS)))
UIC = $(UIC_X64)
endif

#####################################################################################

# Include Common Parts
include Makefile.android-shared
Loading

0 comments on commit ae139bc

Please sign in to comment.