Commit 8e5cfa6a authored by Adrien Béraud's avatar Adrien Béraud

build: don't use standalone NDK toolchain anymore

Change-Id: If4d36f435b4ae5fd5b7122582949ce45ee71ff47
parent 95356e06
......@@ -12,6 +12,9 @@ if [ -z "$ANDROID_ABI" ]; then
exit 1
fi
platform=$(echo "`uname`" | tr '[:upper:]' '[:lower:]')
arch=`uname -m`
ANDROID_TOPLEVEL_DIR="`pwd`"
ANDROID_APP_DIR="${ANDROID_TOPLEVEL_DIR}/ring-android"
......@@ -21,111 +24,65 @@ HAVE_64=0
# Set up ABI variables
if [ ${ANDROID_ABI} = "x86" ] ; then
TARGET_TUPLE="i686-linux-android"
PJ_TARGET_TUPLE="i686-pc-linux-android"
PATH_HOST="x86"
TARGET="i686-linux-android"
PJ_TARGET="i686-pc-linux-android"
HAVE_X86=1
PLATFORM_SHORT_ARCH="x86"
elif [ ${ANDROID_ABI} = "x86_64" ] ; then
TARGET_TUPLE="x86_64-linux-android"
PJ_TARGET_TUPLE="x86_64-pc-linux-android"
PATH_HOST="x86_64"
TARGET="x86_64-linux-android"
PJ_TARGET="x86_64-pc-linux-android"
HAVE_X86=1
HAVE_64=1
PLATFORM_SHORT_ARCH="x86_64"
elif [ ${ANDROID_ABI} = "arm64-v8a" ] ; then
TARGET_TUPLE="aarch64-linux-android"
PJ_TARGET_TUPLE="aarch64-unknown-linux-android"
PATH_HOST=$TARGET_TUPLE
TARGET="aarch64-linux-android"
PJ_TARGET="aarch64-unknown-linux-android"
HAVE_ARM=1
HAVE_64=1
PLATFORM_SHORT_ARCH="arm64"
else
TARGET_TUPLE="arm-linux-androideabi"
PJ_TARGET_TUPLE="arm-unknown-linux-androideabi"
PATH_HOST=$TARGET_TUPLE
TARGET_CC="armv7a-linux-androideabi"
TARGET="arm-linux-androideabi"
PJ_TARGET="arm-unknown-linux-androideabi"
HAVE_ARM=1
PLATFORM_SHORT_ARCH="arm"
fi
TARGET_CC=${TARGET_CC:-$TARGET}
if [ "${HAVE_64}" = 1 ];then
LIBDIR=lib64
else
LIBDIR=lib
fi
ANDROID_API_VERS=21
ANDROID_API=android-$ANDROID_API_VERS
export ANDROID_TOOLCHAIN="`pwd`/android-toolchain-$ANDROID_API_VERS-$PLATFORM_SHORT_ARCH"
if [ ! -d "$ANDROID_TOOLCHAIN" ]; then
$ANDROID_NDK/build/tools/make_standalone_toolchain.py \
--arch=$PLATFORM_SHORT_ARCH \
--api $ANDROID_API_VERS \
--stl libc++ \
--install-dir=$ANDROID_TOOLCHAIN
fi
export ANDROID_API
export TARGET_TUPLE
export API=21
export ANDROID_API=android-$API
export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/$platform-$arch
export TARGET
export HAVE_ARM
export HAVE_X86
export HAVE_64
# Add the NDK toolchain to the PATH, needed both for contribs and for building
# stub libraries
NDK_TOOLCHAIN_PATH="${ANDROID_TOOLCHAIN}/bin"
CROSS_COMPILE=${NDK_TOOLCHAIN_PATH}/${TARGET_TUPLE}-
export PATH=${NDK_TOOLCHAIN_PATH}:${PATH}
export CROSS_COMPILE="${CROSS_COMPILE}"
export SYSROOT=$ANDROID_TOOLCHAIN/sysroot
if [ -z "$DAEMON_DIR" ]; then
DAEMON_DIR="$(pwd)/../daemon"
echo "DAEMON_DIR not provided trying to find it in $DAEMON_DIR"
fi
if [ ! -d "$DAEMON_DIR" ]; then
echo 'Daemon not found.'
echo 'If you cloned the daemon in a custom location override' \
'DAEMON_DIR to point to it'
echo 'If you cloned the daemon in a custom location override DAEMON_DIR to point to it'
echo "You can also use our meta repo which contains both:
https://review.jami.net/#/admin/projects/ring-project"
exit 1
fi
export DAEMON_DIR
# Setup LDFLAGS
if [ ${ANDROID_ABI} = "armeabi-v7a" ] ; then
EXTRA_CFLAGS="${EXTRA_CFLAGS} -march=armv7-a -mthumb -mfpu=vfpv3-d16"
EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -march=armv7-a -mthumb -mfpu=vfpv3-d16"
elif [ ${ANDROID_ABI} = "arm64-v8a" ] ; then
EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_TOOLCHAIN}/${TARGET_TUPLE}/lib"
fi
EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -L${ANDROID_TOOLCHAIN}/${TARGET_TUPLE}/${LIBDIR}/${ANDROID_ABI} -L${ANDROID_TOOLCHAIN}/${TARGET_TUPLE}/${LIBDIR}"
EXTRA_CFLAGS="${EXTRA_CFLAGS} -fPIC"
EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS} -fPIC"
EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -L${SYSROOT}/usr/${LIBDIR}"
echo "EXTRA_CFLAGS= ${EXTRA_CFLAGS}" >> config.mak
echo "EXTRA_CXXFLAGS= ${EXTRA_CXXFLAGS}" >> config.mak
echo "EXTRA_LDFLAGS= ${EXTRA_LDFLAGS}" >> config.mak
if [ "${RELEASE}" -eq 1 ]; then
echo "Daemon in release mode."
OPTS=""
STRIP_ARG="-s "
else
echo "Daemon in debug mode."
OPTS="--enable-debug"
fi
# Make in //
UNAMES=$(uname -s)
MAKEFLAGS=
if which nproc >/dev/null
then
if which nproc >/dev/null; then
MAKEFLAGS=-j`nproc`
elif [ "$UNAMES" == "Darwin" ] && which sysctl >/dev/null
then
elif [ "$platform" == "darwin" ] && which sysctl >/dev/null; then
MAKEFLAGS=-j`sysctl -n machdep.cpu.thread_count`
fi
......@@ -138,24 +95,40 @@ make $MAKEFLAGS
make .pkg-config
make .gas
# Generate JNI interface
JNIDIR=$DAEMON_DIR/bin/jni
PACKAGEDIR=$ANDROID_APP_DIR/libringclient/src/main/java/cx/ring/daemon
#Build JNI interface
cd $JNIDIR
PACKAGEDIR=$PACKAGEDIR $JNIDIR/make-swig.sh
PACKAGEDIR=$ANDROID_APP_DIR/libringclient/src/main/java/cx/ring/daemon $JNIDIR/make-swig.sh
# Setup cross-compilation build environemnt
export AR=$TOOLCHAIN/bin/$TARGET-ar
export AS=$TOOLCHAIN/bin/$TARGET-as
export CC=$TOOLCHAIN/bin/$TARGET_CC$API-clang
export CXX=$TOOLCHAIN/bin/$TARGET_CC$API-clang++
export LD=$TOOLCHAIN/bin/$TARGET-ld
export RANLIB=$TOOLCHAIN/bin/$TARGET-ranlib
export STRIP=$TOOLCHAIN/bin/$TARGET-strip
FLAGS_COMMON="-fPIC -g"
EXTRA_CFLAGS="${EXTRA_CFLAGS} ${FLAGS_COMMON}"
EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS} ${FLAGS_COMMON}"
EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -g"
if [ ${ANDROID_ABI} = "armeabi-v7a" ] ; then
EXTRA_CFLAGS="${EXTRA_CFLAGS} -march=armv7-a -mthumb -mfpu=vfpv3-d16"
EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -march=armv7-a -mthumb -mfpu=vfpv3-d16"
fi
############
# Contribs #
############
echo "Building the contribs"
CONTRIB_DIR=${DAEMON_DIR}/contrib/native-${TARGET_TUPLE}
CONTRIB_SYSROOT=${DAEMON_DIR}/contrib/${TARGET_TUPLE}
CONTRIB_DIR=${DAEMON_DIR}/contrib/native-${TARGET}
CONTRIB_SYSROOT=${DAEMON_DIR}/contrib/${TARGET}
mkdir -p ${CONTRIB_DIR}
mkdir -p ${CONTRIB_SYSROOT}/lib/pkgconfig
cd ${CONTRIB_DIR}
../bootstrap --host=${TARGET_TUPLE} --enable-ffmpeg
../bootstrap --host=${TARGET} --enable-ffmpeg
make list
make fetch
......@@ -165,18 +138,26 @@ make $MAKEFLAGS
############
# Make Jami daemon #
############
DAEMON_BUILD_DIR="${DAEMON_DIR}/build-android-${TARGET_TUPLE}"
DAEMON_BUILD_DIR="${DAEMON_DIR}/build-android-${TARGET}"
mkdir -p ${DAEMON_BUILD_DIR}
if [ ! -f config.h ]; then
cd ${DAEMON_DIR}
cd ${DAEMON_DIR}
if [ ! -f configure ]; then
./autogen.sh
cd "${DAEMON_BUILD_DIR}"
fi
cd "${DAEMON_BUILD_DIR}"
if [ ! -f config.h ]; then
echo "Configuring with ${OPTS}"
CFLAGS="${EXTRA_CFLAGS}" \
CXXFLAGS="${EXTRA_CXXFLAGS}" \
LDFLAGS="${EXTRA_LDFLAGS}" \
${ANDROID_TOPLEVEL_DIR}/configure.sh ${OPTS}
CPPFLAGS="${CPPFLAGS} -I${DAEMON_DIR}/contrib/${TARGET}/include " \
LDFLAGS="${EXTRA_LDFLAGS} -L${DAEMON_DIR}/contrib/${TARGET}/lib " \
PKG_CONFIG_LIBDIR=$DAEMON_DIR/contrib/$TARGET/lib/pkgconfig \
${DAEMON_DIR}/configure --host=$TARGET $EXTRA_PARAMS \
--disable-shared --with-opensl --without-dbus --without-alsa --without-pulse --enable-accel\
--prefix=$DAEMON_DIR/install-android-$TARGET \
${OPTS}
fi
if [ ${ANDROID_API} = "android-21" ] ; then
......@@ -195,13 +176,13 @@ cd ${ANDROID_TOPLEVEL_DIR}
STATIC_LIBS_ALL="-llog -lOpenSLES -landroid \
-lopendht \
-lpjsip-${PJ_TARGET_TUPLE} \
-lpjsip-simple-${PJ_TARGET_TUPLE} \
-lpjsip-ua-${PJ_TARGET_TUPLE} -lpjsua-${PJ_TARGET_TUPLE} \
-lpjnath-${PJ_TARGET_TUPLE} \
-lpjmedia-${PJ_TARGET_TUPLE} \
-lpjlib-util-${PJ_TARGET_TUPLE} \
-lpj-${PJ_TARGET_TUPLE} \
-lpjsip-${PJ_TARGET} \
-lpjsip-simple-${PJ_TARGET} \
-lpjsip-ua-${PJ_TARGET} -lpjsua-${PJ_TARGET} \
-lpjnath-${PJ_TARGET} \
-lpjmedia-${PJ_TARGET} \
-lpjlib-util-${PJ_TARGET} \
-lpj-${PJ_TARGET} \
-lupnp -lixml \
-larchive \
-lsecp256k1 \
......@@ -223,17 +204,16 @@ mkdir -p ${LIBRING_JNI_DIR}
cp $ANDROID_NDK/sources/cxx-stl/llvm-libc++/libs/${ANDROID_ABI}/libc++_shared.so $LIBRING_JNI_DIR
# Use a shared libc++_shared.so (shared by jami and all other plugins)
${NDK_TOOLCHAIN_PATH}/clang++ \
--shared \
-Wall -Wextra \
-Wno-unused-variable \
-Wno-unused-function \
-Wno-unused-parameter \
${JNIDIR}/ring_wrapper.cpp \
${DAEMON_BUILD_DIR}/src/.libs/libring.a \
-isystem ${DAEMON_DIR}/contrib/${TARGET_TUPLE}/include \
-I${DAEMON_DIR}/src \
-L${DAEMON_DIR}/contrib/${TARGET_TUPLE}/lib \
${STATIC_LIBS_ALL} \
${STRIP_ARG} --std=c++14 -O3 -fPIC \
-o ${LIBRING_JNI_DIR}/libring.so
${CXX} --shared \
-Wall -Wextra \
-Wno-unused-variable \
-Wno-unused-function \
-Wno-unused-parameter \
${JNIDIR}/ring_wrapper.cpp \
${DAEMON_BUILD_DIR}/src/.libs/libring.a \
-isystem ${DAEMON_DIR}/contrib/${TARGET}/include \
-I${DAEMON_DIR}/src \
-L${DAEMON_DIR}/contrib/${TARGET}/lib \
${STATIC_LIBS_ALL} \
${FLAGS_COMMON} -O3 --std=c++17 \
-o ${LIBRING_JNI_DIR}/libring.so
#!/bin/sh
if [ -z "$ANDROID_NDK" ]; then
echo "Please set the ANDROID_NDK environment variable with its path."
exit 1
fi
if [ -z "$ANDROID_ABI" ]; then
echo "Please set ANDROID_ABI to your architecture: armeabi-v7a, armeabi, arm64-v8a, x86, x86_64 or mips."
exit 1
fi
if [ -z "$ANDROID_API" ];then
echo "ANDROID_API not set, call ./compile.sh first"
exit 1
fi
CPPFLAGS="${CPPFLAGS} -I${DAEMON_DIR}/contrib/${TARGET_TUPLE}/include " \
LDFLAGS="${LDFLAGS} -L${DAEMON_DIR}/contrib/${TARGET_TUPLE}/lib " \
CC="${CROSS_COMPILE}clang" \
CXX="${CROSS_COMPILE}clang++" \
NM="${CROSS_COMPILE}nm" \
STRIP="${CROSS_COMPILE}strip" \
RANLIB="${CROSS_COMPILE}ranlib" \
AR="${CROSS_COMPILE}ar" \
AS="${CROSS_COMPILE}as" \
PKG_CONFIG_LIBDIR=$DAEMON_DIR/contrib/$TARGET_TUPLE/lib/pkgconfig \
$DAEMON_DIR/configure --host=$TARGET_TUPLE $EXTRA_PARAMS \
--disable-shared --with-opensl --without-dbus --without-alsa --without-pulse --enable-accel\
--prefix=$DAEMON_DIR/install-android-$TARGET_TUPLE \
$*
#!/bin/bash
# Simple script to generate env.txt
ENVTXT=$1/assets/env.txt
function optional_var {
echo -n "$1=" >> $ENVTXT
ONE=\$$1
T=`eval echo $ONE`
if [ -z "$T" ]; then
echo -n "0" >> $ENVTXT
else
echo -n "$T" >> $ENVTXT
fi
echo -n -e "\n" >> $ENVTXT
}
rm -f $ENVTXT
echo -e "ANDROID_ABI=$ANDROID_ABI" >> $ENVTXT
optional_var "NO_FPU"
optional_var "NO_ARMV6"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment