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

set -xe

5 6
if [ $ANDROID_ABI == "arm64-v8a" ]; then
  ANDROID_ARCH=arm64
7 8 9 10
  if [ $ANDROID_API -lt 21 ]; then
    echo "Warning: arm64-v8a requires ANDROID_API >= 21."
    ANDROID_API=21
  fi
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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

31
BUILD_ROOT=/paddle/build_android
32
DEST_ROOT=/paddle/install_android
33

34 35 36 37
rm -rf $BUILD_ROOT 2>/dev/null || true
mkdir -p $BUILD_ROOT
cd $BUILD_ROOT

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

84 85 86 87 88
cat <<EOF
============================================
Building in $BUILD_ROOT ...
============================================
EOF
89 90
make -j `nproc`
make install -j `nproc`