Files
b2txt25/language_model/srilm-1.7.3/common/Makefile.core.android.r16b
2025-07-02 12:18:09 -07:00

193 lines
6.6 KiB
Makefile

#
# File: Makefile.core.android
# Author: Mike Frandsen
# Date: 2010/08/03
#
# Description:
# Machine dependent compilation options and variable definitions
# for Android, core file
#
# Copyright (c) 1999-2010 SRI International. All Rights Reserved.
#
# $Header: /home/srilm/CVS/srilm/common/Makefile.core.android.r16b,v 1.1 2019/07/16 23:13:19 victor Exp $
#
# This Makefile only included by core x86 or arm Android Makefiles.
# This version designed for Android NDK r16b setup as follows, I think it works....
# Get android-ndk-r16b for linux:
# wget -q --output-document=android-ndk.zip https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip
# unzip android-ndk.zip
# Finally, install the toolchain. You must explicitly specify --stl=libc++, to copy LLVM libc++ headers and libraries:
# 64-bit toolchain, api 23
# android-ndk-r16b/build/tools/make_standalone_toolchain.py --arch arm64 --api 23 --stl=libc++ --install-dir ./toolchain-16b-arm64-api23
#
# And using environment setup as follows:
# Linux:
# setenv ANDROID_TOP <path to directory with ndk>
# setenv ANDROID_HOST linux-x86_64
# setenv ANDROID_NDK ${ANDROID_TOP}/android-ndk-r16b
# setenv ANDROID_TOOLCHAIN_VERSION 4.9
# setenv ANDROID_VERSION android-23
# setenv ANDROID_LINK_VERSION android-23
# 64 bit
# setenv ARCH_NAME aarch64-linux-android
# setenv ANDROID_TOOLCHAIN_NAME ${ARCH_NAME}-4.9
# setenv TOOLCHAIN_NAME toolchain-16b-arm64-api23
# setenv MY_TOOLCHAIN ${ANDROID_TOP}/${TOOLCHAIN_NAME}
# setenv SYSROOT ${MY_TOOLCHAIN}/sysroot
# setenv PATH ${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/prebuilt/${ANDROID_HOST}/bin:$PATH
# setenv CC ${MY_TOOLCHAIN}/bin/${ARCH_NAME}-clang
# setenv CXX ${MY_TOOLCHAIN}/bin/${ARCH_NAME}-clang++
# setenv CFLAGS "--sysroot=${SYSROOT}"
# setenv CXXFLAGS "--sysroot=${SYSROOT}"
# setenv RANLIB "${MY_TOOLCHAIN}/bin/${ARCH_NAME}-ranlib"
# setenv AR "${MY_TOOLCHAIN}/bin/${ARCH_NAME}-ar"
# setenv AS "${MY_TOOLCHAIN}/bin/${ARCH_NAME}-as"
# setenv LD "${MY_TOOLCHAIN}/bin/${ARCH_NAME}-ld"
# setenv NM "${MY_TOOLCHAIN}/bin/${ARCH_NAME}-nm"
# setenv CPP "${MY_TOOLCHAIN}/bin/${ARCH_NAME}-cpp"
# setenv CXXCPP "${MY_TOOLCHAIN}/bin/${ARCH_NAME}-cpp"
# setenv STRIP "${MY_TOOLCHAIN}/bin/${ARCH_NAME}-strip"
# setenv STRINGS "${MY_TOOLCHAIN}/bin/${ARCH_NAME}-strings"
# Override this if you are not building on Linux or set to
# linux-x86_64 if your host is 64 bit.
ANDROID_HOST ?= linux-x86_64
# Need to set ndk directory; assume >= NDK r5b which bundles STL.
# Use ?= so environment variables will override.
#ANDROID_NDK ?= ~/android-ndk-r6b
ANDROID_NDK ?= ~/android-ndk-r8e
ANDROID_VERSION ?= android-23
SYSROOT := $(ANDROID_NDK)/platforms/$(ANDROID_VERSION)/$(ANDROID_ARCH)
SYSROOT = $(ANDROID_NDK)/sysroot
# Below was appropriate for NDK r5b
#ANDROID_SRILM_BIN := $(ANDROID_NDK)/toolchains/arm-eabi-4.4.0/prebuilt/$(ANDROID_HOST)/bin
#GCC := $(ANDROID_SRILM_BIN)/arm-eabi-gcc
#GPP := $(ANDROID_SRILM_BIN)/arm-eabi-g++
#AR := $(ANDROID_SRILM_BIN)/arm-eabi-ar
#OPT_GCC_VER :=
# Set as follows for NDK r6b
#ANDROID_TOOLCHAIN_VERSION := 4.4.3
#OPT_GCC_VER :=
# Set as follows for NDK r8b
# 4.4.3 should also be available in r8b
ANDROID_TOOLCHAIN_VERSION := 4.9
# Newer versions add "/4.4.3" or "/4.6" to include and lib paths
OPT_GCC_VER := /$(ANDROID_TOOLCHAIN_VERSION)
OPT_GCC_VER =
ANDROID_TOOLCHAIN_NAME_ALT ?= $(ANDROID_TOOLCHAIN_NAME)
ANDROID_SRILM_BIN := $(ANDROID_NDK)/toolchains/$(ANDROID_TOOLCHAIN_NAME_ALT)-$(ANDROID_TOOLCHAIN_VERSION)/prebuilt/$(ANDROID_HOST)/bin
GCC := $(ANDROID_SRILM_BIN)/$(ANDROID_TOOLCHAIN_NAME)-gcc
GPP := $(ANDROID_SRILM_BIN)/$(ANDROID_TOOLCHAIN_NAME)-g++
AR := $(ANDROID_SRILM_BIN)/$(ANDROID_TOOLCHAIN_NAME)-ar
# Other possible options:
# As above:
# (arm-eabi-)+(gcc,g++,ar)
# (arm-linux-androideabi-)+(gcc,g++,ar)
# Others:
# ()+(gcc,g++,ar)
# (i686-android-linux-)+(gcc,g++,ar)
ARCHIVE = $(AR) crsuv
# Use the GNU C compiler.
WARNING_FLAGS := -Wreturn-type -Wimplicit -Wuninitialized -Wdeprecated -Wpointer-arith -Wstrict-overflow -Woverlength-strings -Wunused-variable
GCC_FLAGS = $(ARCH_FLAGS) $(WARNING_FLAGS) -DNO_ZIO -DNO_ICONV
CC = $(GCC) $(GCC_FLAGS) --sysroot=$(SYSROOT)
CXX = $(GPP) $(GCC_FLAGS) -DINSTANTIATE_TEMPLATES --sysroot=$(SYSROOT)
# avoid gcc warning that all code is PIC
# Victor 4/25/16: Actually need -fPIC to build SRINTERP .so
# PIC_FLAG = -fpic
# suffix used for executable files
EXE_SUFFIX =
# Optional compilation flags.
# -Os is optimize for size
OPTIMIZE_FLAGS = -g -O2 -Os -DNDEBUG -ffunction-sections -funwind-tables -fno-short-enums
DEBUG_FLAGS = -g -DDEBUG
PROFILE_FLAGS = -g -pg -O2
# Optional linking flags.
EXPORT_LDFLAGS = -s
# Shared compilation flags.
CFLAGS = $(ADDITIONAL_CFLAGS) $(INCLUDES)
CXXFLAGS = $(ADDITIONAL_CXXFLAGS) $(INCLUDES)
# Shared linking flags.
LDFLAGS = $(ADDITIONAL_LDFLAGS) -L$(SRILM_LIBDIR)
# Other useful compilation flags.
# Turn off thread local storage; single instance assumed
# on Android and can conflict with other libraries.
ADDITIONAL_CFLAGS = -DNEED_RAND48 -DNO_TLS -DNO_BLOCK_MALLOC
ADDITIONAL_CXXFLAGS = -DNEED_RAND48 -DNO_TLS -DNO_BLOCK_MALLOC
# Other useful include directories.
ADDITIONAL_INCLUDES = -I$(SYSROOT)/usr/include -I$(SYSROOT)/usr/include/aarch64-linux-android -I$(ANDROID_NDK)/sources/cxx-stl/llvm-libc++$(OPT_GCC_VER)/include -I$(ANDROID_NDK)/sources/cxx-stl/llvm-libc++$(OPT_GCC_VER)/libs/$(ANDROID_CUST_DIR)/include -I$(ANDROID_NDK)/sysroot/usr/include
# Other useful linking flags.
ADDITIONAL_LDFLAGS =
# Other useful libraries.
# r6b and earlier
#ADDITIONAL_LIBRARIES = -lm -lstdc++ -lgcc
# r8b
# -rpath-link was recommended but not needed as -Wl option
# The -Wl,--entry=main gets rid of the warnings like "cannot find entry symbol _start"
ANDROID_CUST_DIR_ALT ?= $(ANDROID_CUST_DIR)
IS_HARD := $(findstring -hard,$(ANDROID_CUST_DIR))
ifneq ($(IS_HARD),)
# hard
ADDITIONAL_LIBRARIES += -Wl,--entry=main -L$(ANDROID_NDK)/sources/cxx-stl/llvm-libc++$(OPT_GCC_VER)/libs/$(ANDROID_CUST_DIR_ALT) -lm_hard -lgnustl_static -lsupc++ -lgcc -lc
MATH_LIBRARY = -lm_hard
else
# not hard
ADDITIONAL_LIBRARIES += -Wl,--entry=main -L$(ANDROID_NDK)/sources/cxx-stl/llvm-libc++$(OPT_GCC_VER)/libs/$(ANDROID_CUST_DIR_ALT) -lm -lc++_static -lsupc++ -lgcc -lc
endif
# run-time linker path flag
RLD_FLAG = -R
# Tcl support (part of cygwin)
TCL_INCLUDE =
TCL_LIBRARY =
NO_TCL = X
# No ranlib
RANLIB = :
# Not needed
DEMANGLE_FILTER =
# Generate dependencies from source files.
GEN_DEP = gcc $(CFLAGS) -MM
GEN_DEP.cc = g++ $(CXXFLAGS) -MM
# Run lint.
LINT = lint
LINT_FLAGS = -DDEBUG $(CFLAGS)
# Location of gawk binary
GAWK = /usr/bin/gawk
# Location of perl binary
PERL = /usr/bin/perl
# Fix __dso_handle errors
ADDITIONAL_LIBRARIES += $(SYSROOT)/usr/lib/crtbegin_so.o