build_android.sh 2.6 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
mkdir -p $BUILD_ROOT
cd $BUILD_ROOT

37 38
if [ $ANDROID_ABI == "armeabi-v7a" ]; then
  cmake -DCMAKE_SYSTEM_NAME=Android \
39
        -DANDROID_STANDALONE_TOOLCHAIN=$ANDROID_STANDALONE_TOOLCHAIN \
40 41 42 43 44
        -DANDROID_ABI=$ANDROID_ABI \
        -DANDROID_ARM_NEON=ON \
        -DANDROID_ARM_MODE=ON \
        -DHOST_C_COMPILER=/usr/bin/gcc \
        -DHOST_CXX_COMPILER=/usr/bin/g++ \
45
        -DCMAKE_INSTALL_PREFIX=$DEST_ROOT \
46
        -DCMAKE_BUILD_TYPE=MinSizeRel \
47
        -DUSE_EIGEN_FOR_BLAS=ON \
48 49
        -DWITH_C_API=ON \
        -DWITH_SWIG_PY=OFF \
50 51
        ..
elif [ $ANDROID_ABI == "arm64-v8a" ]; then
52
  cmake -DCMAKE_SYSTEM_NAME=Android \
53
        -DANDROID_STANDALONE_TOOLCHAIN=$ANDROID_STANDALONE_TOOLCHAIN \
54 55 56 57
        -DANDROID_ABI=$ANDROID_ABI \
        -DANDROID_ARM_MODE=ON \
        -DHOST_C_COMPILER=/usr/bin/gcc \
        -DHOST_CXX_COMPILER=/usr/bin/g++ \
58
        -DCMAKE_INSTALL_PREFIX=$DEST_ROOT \
59
        -DCMAKE_BUILD_TYPE=MinSizeRel \
60
        -DUSE_EIGEN_FOR_BLAS=OFF \
61 62
        -DWITH_C_API=ON \
        -DWITH_SWIG_PY=OFF \
63
        ..
64 65
elif [ $ANDROID_ABI == "armeabi" ]; then
  cmake -DCMAKE_SYSTEM_NAME=Android \
66
        -DANDROID_STANDALONE_TOOLCHAIN=$ANDROID_STANDALONE_TOOLCHAIN \
67 68 69 70
        -DANDROID_ABI=$ANDROID_ABI \
        -DANDROID_ARM_MODE=ON \
        -DHOST_C_COMPILER=/usr/bin/gcc \
        -DHOST_CXX_COMPILER=/usr/bin/g++ \
71
        -DCMAKE_INSTALL_PREFIX=$DEST_ROOT \
72
        -DCMAKE_BUILD_TYPE=MinSizeRel \
73 74
        -DWITH_C_API=ON \
        -DWITH_SWIG_PY=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`