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
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 52
        -DWITH_STYLE_CHECK=OFF \
        ..
elif [ $ANDROID_ABI == "arm64-v8a" ]; then
53
  cmake -DCMAKE_SYSTEM_NAME=Android \
54
        -DANDROID_STANDALONE_TOOLCHAIN=$ANDROID_STANDALONE_TOOLCHAIN \
55 56 57 58
        -DANDROID_ABI=$ANDROID_ABI \
        -DANDROID_ARM_MODE=ON \
        -DHOST_C_COMPILER=/usr/bin/gcc \
        -DHOST_CXX_COMPILER=/usr/bin/g++ \
59
        -DCMAKE_INSTALL_PREFIX=$DEST_ROOT \
60
        -DCMAKE_BUILD_TYPE=MinSizeRel \
61
        -DUSE_EIGEN_FOR_BLAS=OFF \
62 63
        -DWITH_C_API=ON \
        -DWITH_SWIG_PY=OFF \
64
        -DWITH_STYLE_CHECK=OFF \
65
        ..
66 67
elif [ $ANDROID_ABI == "armeabi" ]; then
  cmake -DCMAKE_SYSTEM_NAME=Android \
68
        -DANDROID_STANDALONE_TOOLCHAIN=$ANDROID_STANDALONE_TOOLCHAIN \
69 70 71 72
        -DANDROID_ABI=$ANDROID_ABI \
        -DANDROID_ARM_MODE=ON \
        -DHOST_C_COMPILER=/usr/bin/gcc \
        -DHOST_CXX_COMPILER=/usr/bin/g++ \
73
        -DCMAKE_INSTALL_PREFIX=$DEST_ROOT \
74
        -DCMAKE_BUILD_TYPE=MinSizeRel \
75 76
        -DWITH_C_API=ON \
        -DWITH_SWIG_PY=OFF \
77
        -DWITH_STYLE_CHECK=OFF \
78
        ..
79 80 81 82
else
  echo "Invalid ANDROID_ABI: $ANDROID_ABI"
fi

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