build-daemon.sh 6.66 KB
Newer Older
Adrien Béraud's avatar
Adrien Béraud committed
1
#! /bin/bash
Adrien Béraud's avatar
Adrien Béraud committed
2
# Build Jami daemon for architecture specified by ANDROID_ABI
Adrien Béraud's avatar
Adrien Béraud committed
3
4
5
6
7
8
9
10
11
12
13
14
set -e

if [ -z "$ANDROID_NDK" -o -z "$ANDROID_SDK" ]; then
   echo "You must define ANDROID_NDK, ANDROID_SDK and ANDROID_ABI before starting."
   echo "They must point to your NDK and SDK directories."
   exit 1
fi
if [ -z "$ANDROID_ABI" ]; then
   echo "Please set ANDROID_ABI to your architecture: armeabi-v7a, x86."
   exit 1
fi

15
16
17
platform=$(echo "`uname`" | tr '[:upper:]' '[:lower:]')
arch=`uname -m`

Adrien Béraud's avatar
Adrien Béraud committed
18
ANDROID_TOPLEVEL_DIR="`pwd`"
Adrien Béraud's avatar
Adrien Béraud committed
19
ANDROID_APP_DIR="${ANDROID_TOPLEVEL_DIR}/ring-android"
Adrien Béraud's avatar
Adrien Béraud committed
20
21
22

# Set up ABI variables
if [ ${ANDROID_ABI} = "x86" ] ; then
23
24
    TARGET="i686-linux-android"
    PJ_TARGET="i686-pc-linux-android"
Adrien Béraud's avatar
Adrien Béraud committed
25
26
    PLATFORM_SHORT_ARCH="x86"
elif [ ${ANDROID_ABI} = "x86_64" ] ; then
27
28
    TARGET="x86_64-linux-android"
    PJ_TARGET="x86_64-pc-linux-android"
Adrien Béraud's avatar
Adrien Béraud committed
29
30
    PLATFORM_SHORT_ARCH="x86_64"
elif [ ${ANDROID_ABI} = "arm64-v8a" ] ; then
31
32
    TARGET="aarch64-linux-android"
    PJ_TARGET="aarch64-unknown-linux-android"
Adrien Béraud's avatar
Adrien Béraud committed
33
34
    PLATFORM_SHORT_ARCH="arm64"
else
35
36
37
    TARGET_CC="armv7a-linux-androideabi"
    TARGET="arm-linux-androideabi"
    PJ_TARGET="arm-unknown-linux-androideabi"
Adrien Béraud's avatar
Adrien Béraud committed
38
39
    PLATFORM_SHORT_ARCH="arm"
fi
40
TARGET_CC=${TARGET_CC:-$TARGET}
Adrien Béraud's avatar
Adrien Béraud committed
41

42
43
44
45
export API=21
export ANDROID_API=android-$API
export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/$platform-$arch
export TARGET
Adrien Béraud's avatar
Adrien Béraud committed
46
47
48
49
50
51
52

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.'
53
    echo 'If you cloned the daemon in a custom location override DAEMON_DIR to point to it'
Adrien Béraud's avatar
Adrien Béraud committed
54
    echo "You can also use our meta repo which contains both:
Adrien Béraud's avatar
Adrien Béraud committed
55
          https://review.jami.net/#/admin/projects/ring-project"
Adrien Béraud's avatar
Adrien Béraud committed
56
57
    exit 1
fi
Adrien Béraud's avatar
Adrien Béraud committed
58
export DAEMON_DIR
Adrien Béraud's avatar
Adrien Béraud committed
59

Adrien Béraud's avatar
Adrien Béraud committed
60
61
62
63
64
65
66
if [ "${RELEASE}" -eq 1 ]; then
    echo "Daemon in release mode."
    OPTS=""
else
    echo "Daemon in debug mode."
    OPTS="--enable-debug"
fi
Adrien Béraud's avatar
Adrien Béraud committed
67
68
69

# Make in //
MAKEFLAGS=
70
if which nproc >/dev/null; then
Adrien Béraud's avatar
Adrien Béraud committed
71
MAKEFLAGS=-j`nproc`
72
elif [ "$platform" == "darwin" ] && which sysctl >/dev/null; then
Adrien Béraud's avatar
Adrien Béraud committed
73
74
75
76
MAKEFLAGS=-j`sysctl -n machdep.cpu.thread_count`
fi

# Build buildsystem tools
Alexandre Lision's avatar
Alexandre Lision committed
77
cd $DAEMON_DIR/extras/tools
Adrien Béraud's avatar
Adrien Béraud committed
78
export PATH=`pwd`/build/bin:$PATH
Adrien Béraud's avatar
Adrien Béraud committed
79
80
81
echo "Building tools"
./bootstrap
make $MAKEFLAGS
Alexandre Lision's avatar
Alexandre Lision committed
82
make .pkg-config
83
make .gas
Alexandre Lision's avatar
Alexandre Lision committed
84

85
# Generate JNI interface
Alexandre Lision's avatar
Alexandre Lision committed
86
87
JNIDIR=$DAEMON_DIR/bin/jni
cd $JNIDIR
88
PACKAGEDIR=$ANDROID_APP_DIR/libringclient/src/main/java/net/jami/daemon $JNIDIR/make-swig.sh
89
90

# Setup cross-compilation build environemnt
Adrien Béraud's avatar
Adrien Béraud committed
91
export AR=$TOOLCHAIN/bin/llvm-ar
92
93
94
export AS=$TOOLCHAIN/bin/$TARGET-as
export CC=$TOOLCHAIN/bin/$TARGET_CC$API-clang
export CXX=$TOOLCHAIN/bin/$TARGET_CC$API-clang++
Adrien Béraud's avatar
Adrien Béraud committed
95
96
97
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
98
99
100
101
102
103
104
105
106

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
Adrien Béraud's avatar
Adrien Béraud committed
107
108
109
110
111

############
# Contribs #
############
echo "Building the contribs"
112
113
CONTRIB_DIR=${DAEMON_DIR}/contrib/native-${TARGET}
CONTRIB_SYSROOT=${DAEMON_DIR}/contrib/${TARGET}
Adrien Béraud's avatar
Adrien Béraud committed
114
115
mkdir -p ${CONTRIB_DIR}
mkdir -p ${CONTRIB_SYSROOT}/lib/pkgconfig
Adrien Béraud's avatar
Adrien Béraud committed
116

Adrien Béraud's avatar
Adrien Béraud committed
117
cd ${CONTRIB_DIR}
118
../bootstrap --host=${TARGET} --enable-ffmpeg
Adrien Béraud's avatar
Adrien Béraud committed
119
120
121

make list
make fetch
Adrien Béraud's avatar
Adrien Béraud committed
122
export PATH="$PATH:$CONTRIB_SYSROOT/bin"
123
make $MAKEFLAGS
Adrien Béraud's avatar
Adrien Béraud committed
124
125

############
Adrien Béraud's avatar
Adrien Béraud committed
126
# Make Jami daemon #
Adrien Béraud's avatar
Adrien Béraud committed
127
############
128
DAEMON_BUILD_DIR="${DAEMON_DIR}/build-android-${TARGET}"
Adrien Béraud's avatar
Adrien Béraud committed
129
mkdir -p ${DAEMON_BUILD_DIR}
Adrien Béraud's avatar
Adrien Béraud committed
130

131
132
cd ${DAEMON_DIR}
if [ ! -f configure ]; then
Adrien Béraud's avatar
Adrien Béraud committed
133
    ./autogen.sh
134
135
136
137
fi

cd "${DAEMON_BUILD_DIR}"
if [ ! -f config.h ]; then
Adrien Béraud's avatar
Adrien Béraud committed
138
    echo "Configuring with ${OPTS}"
139
140
    CFLAGS="${EXTRA_CFLAGS}" \
    CXXFLAGS="${EXTRA_CXXFLAGS}" \
141
142
143
144
145
146
147
    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}
Adrien Béraud's avatar
Adrien Béraud committed
148
149
150
151
152
153
154
155
fi

if [ ${ANDROID_API} = "android-21" ] ; then
    # android-21 has empty sys/shm.h headers that triggers shm detection but it
    # doesn't have any shm functions and/or symbols. */
    export ac_cv_header_sys_shm_h=no
fi

156
echo "Building jamid ${MAKEFLAGS}"
Adrien Béraud's avatar
Adrien Béraud committed
157
158
V=99 make $MAKEFLAGS

Alexandre Lision's avatar
Alexandre Lision committed
159
160
161
######################
# Building JNI library
######################
Adrien Béraud's avatar
Adrien Béraud committed
162
163
164
165
cd ${ANDROID_TOPLEVEL_DIR}

STATIC_LIBS_ALL="-llog -lOpenSLES -landroid \
                -lopendht \
166
167
168
169
170
171
172
                -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} \
173
                -lupnp -lixml \
174
                -lgit2 \
175
                -larchive \
Adrien Béraud's avatar
Adrien Béraud committed
176
                -lsecp256k1 \
177
                -lgnutls -lhogweed -lnettle -lgmp \
178
                -lwebrtc_audio_processing \
179
                -lssl -lcrypto \
180
                -lavformat -lavdevice -lavfilter -lavcodec -lswresample -lswscale -lavutil \
181
                -lyaml-cpp -ljsoncpp -lhttp_parser -lfmt\
182
                -luuid -lz -ldl \
Adrien Béraud's avatar
Adrien Béraud committed
183
                -lvpx -lopus -lspeex -lspeexdsp -lx264 \
184
                -lgit2 \
185
                -largon2 \
186
                -liconv"
187

Adrien Béraud's avatar
Adrien Béraud committed
188
LIBRING_JNI_DIR=${ANDROID_APP_DIR}/app/src/main/libs/${ANDROID_ABI}
Adrien Béraud's avatar
Adrien Béraud committed
189
190
LIBRING_JNI_UNSTRIPPED_DIR=${ANDROID_APP_DIR}/unstripped/${ANDROID_ABI}
LIBCPP=$ANDROID_NDK/sources/cxx-stl/llvm-libc++/libs/${ANDROID_ABI}/libc++_shared.so
Adrien Béraud's avatar
Adrien Béraud committed
191

Adrien Béraud's avatar
Adrien Béraud committed
192
echo "Building Jami JNI library for Android to ${LIBRING_JNI_DIR}"
Adrien Béraud's avatar
Adrien Béraud committed
193
mkdir -p ${LIBRING_JNI_DIR}
194

195
# Use a shared libc++_shared.so (shared by jami and all other plugins)
Adrien Béraud's avatar
Adrien Béraud committed
196
cp $LIBCPP $LIBRING_JNI_DIR
197

198
199
200
201
202
${CXX} --shared \
       -Wall -Wextra \
       -Wno-unused-variable \
       -Wno-unused-function \
       -Wno-unused-parameter \
Adrien Béraud's avatar
Adrien Béraud committed
203
       -Wl,-Bsymbolic \
204
       ${JNIDIR}/jami_wrapper.cpp \
205
206
207
208
209
210
       ${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 \
211
       -o ${LIBRING_JNI_DIR}/libring.so
Adrien Béraud's avatar
Adrien Béraud committed
212

213
214
215
216
217
218
if [ "${RELEASE}" -eq 1 ]; then
    mkdir -p ${LIBRING_JNI_UNSTRIPPED_DIR}
    cp ${LIBCPP} ${LIBRING_JNI_UNSTRIPPED_DIR}
    cp ${LIBRING_JNI_DIR}/libring.so ${LIBRING_JNI_UNSTRIPPED_DIR}
    ${STRIP} ${LIBRING_JNI_DIR}/libring.so
fi