build_android.sh 2.6 KB
Newer Older
1 2 3 4
#!/bin/bash

set -xe

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
if [ $ANDROID_ABI == "arm64-v8a" ]; then
  ANDROID_ARCH=arm64
else # armeabi, armeabi-v7a
  ANDROID_ARCH=arm
fi

ANDROID_STANDALONE_TOOLCHAIN=$ANDROID_TOOLCHAINS_DIR/$ANDROID_ARCH-android-$ANDROID_API

cat <<EOF
============================================
Generating the standalone toolchain ...
${ANDROID_NDK_HOME}/build/tools/make-standalone-toolchain.sh
      --arch=$ANDROID_ARCH
      --platform=android-$ANDROID_API
      --install-dir=${ANDROID_STANDALONE_TOOLCHAIN}
============================================
EOF
${ANDROID_NDK_HOME}/build/tools/make-standalone-toolchain.sh \
      --arch=$ANDROID_ARCH \
      --platform=android-$ANDROID_API \
      --install-dir=$ANDROID_STANDALONE_TOOLCHAIN

27
BUILD_ROOT=/paddle/build_android
28
DEST_ROOT=/paddle/install_android
29

30 31 32 33
rm -rf $BUILD_ROOT 2>/dev/null || true
mkdir -p $BUILD_ROOT
cd $BUILD_ROOT

34 35
if [ $ANDROID_ABI == "armeabi-v7a" ]; then
  cmake -DCMAKE_SYSTEM_NAME=Android \
36
        -DANDROID_STANDALONE_TOOLCHAIN=$ANDROID_STANDALONE_TOOLCHAIN \
37 38 39 40 41
        -DANDROID_ABI=$ANDROID_ABI \
        -DANDROID_ARM_NEON=ON \
        -DANDROID_ARM_MODE=ON \
        -DHOST_C_COMPILER=/usr/bin/gcc \
        -DHOST_CXX_COMPILER=/usr/bin/g++ \
42
        -DCMAKE_INSTALL_PREFIX=$DEST_ROOT \
43
        -DCMAKE_BUILD_TYPE=Release \
44
        -DUSE_EIGEN_FOR_BLAS=ON \
45 46
        -DWITH_C_API=ON \
        -DWITH_SWIG_PY=OFF \
47 48 49
        -DWITH_STYLE_CHECK=OFF \
        ..
elif [ $ANDROID_ABI == "arm64-v8a" ]; then
50
  cmake -DCMAKE_SYSTEM_NAME=Android \
51
        -DANDROID_STANDALONE_TOOLCHAIN=$ANDROID_STANDALONE_TOOLCHAIN \
52 53 54 55
        -DANDROID_ABI=$ANDROID_ABI \
        -DANDROID_ARM_MODE=ON \
        -DHOST_C_COMPILER=/usr/bin/gcc \
        -DHOST_CXX_COMPILER=/usr/bin/g++ \
56
        -DCMAKE_INSTALL_PREFIX=$DEST_ROOT \
57
        -DCMAKE_BUILD_TYPE=Release \
58
        -DUSE_EIGEN_FOR_BLAS=OFF \
59 60
        -DWITH_C_API=ON \
        -DWITH_SWIG_PY=OFF \
61
        -DWITH_STYLE_CHECK=OFF \
62
        ..
63 64
elif [ $ANDROID_ABI == "armeabi" ]; then
  cmake -DCMAKE_SYSTEM_NAME=Android \
65
        -DANDROID_STANDALONE_TOOLCHAIN=$ANDROID_STANDALONE_TOOLCHAIN \
66 67 68 69
        -DANDROID_ABI=$ANDROID_ABI \
        -DANDROID_ARM_MODE=ON \
        -DHOST_C_COMPILER=/usr/bin/gcc \
        -DHOST_CXX_COMPILER=/usr/bin/g++ \
70
        -DCMAKE_INSTALL_PREFIX=$DEST_ROOT \
71 72 73
        -DCMAKE_BUILD_TYPE=Release \
        -DWITH_C_API=ON \
        -DWITH_SWIG_PY=OFF \
74
        -DWITH_STYLE_CHECK=OFF \
75
        ..
76 77 78 79
else
  echo "Invalid ANDROID_ABI: $ANDROID_ABI"
fi

80 81 82 83 84
cat <<EOF
============================================
Building in $BUILD_ROOT ...
============================================
EOF
85 86
make -j `nproc`
make install -j `nproc`