forked from MegEngine/MegPeak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
android_build.sh
executable file
·117 lines (106 loc) · 2.54 KB
/
android_build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
set -e
BUILD_TYPE=Release
ARCH=arm64-v8a
OPENCL=OFF
CPUINFO=OFF
DOT=OFF
MMA=OFF
ARCH_LIST="arm64-v8a armeabi-v7a"
READLINK=readlink
MAKEFILE_TYPE="Ninja"
OS=$(uname -s)
function usage() {
echo "$0 args1 .."
echo "available args detail:"
echo "-m : machine arch(arm64-v8a, armeabi-v7a)"
echo "-d : enable build with dotprod"
echo "-a : enable build with mma"
echo "-l : enable build with opencl"
echo "-c : enable build with cpuinfo"
echo "-h : show usage"
echo "example: $0 -m armeabi-v7a"
exit -1
}
while getopts "adlchm:" arg
do
case $arg in
m)
echo "build with arch:$OPTARG"
ARCH=$OPTARG
;;
l)
echo "build with opencl"
OPENCL=ON
;;
c)
echo "build with cpuinfo"
CPUINFO=ON
;;
a)
echo "build with mma"
MMA=ON
;;
d)
echo "build with dotprod"
DOT=ON
;;
h)
echo "show usage"
usage
exit 0
;;
esac
done
if [ $OS = "Darwin" ];then
READLINK=greadlink
elif [[ $OS =~ "NT" ]]; then
echo "BUILD in NT ..."
MAKEFILE_TYPE="Unix"
fi
SRC_DIR=$($READLINK -f "`dirname $0`/")
function cmake_build() {
if [ $NDK_ROOT ];then
echo "NDK_ROOT: $NDK_ROOT"
else
echo "Please define env var NDK_ROOT first"
exit 1
fi
BUILD_DIR=$SRC_DIR/build-${ARCH}/
BUILD_ABI=$1
BUILD_NATIVE_LEVEL=$2
echo "build dir: $BUILD_DIR"
echo "build ARCH: $ARCH"
echo "build ABI: $BUILD_ABI"
echo "build native level: $BUILD_NATIVE_LEVEL"
echo "BUILD MAKEFILE_TYPE: $MAKEFILE_TYPE"
echo "create build dir"
mkdir -p $BUILD_DIR
cd $BUILD_DIR
cmake -G "$MAKEFILE_TYPE" \
"-B$BUILD_DIR" \
"-S$SRC_DIR" \
-DCMAKE_TOOLCHAIN_FILE="$NDK_ROOT/build/cmake/android.toolchain.cmake" \
-DANDROID_NDK="$NDK_ROOT" \
-DANDROID_ABI=$BUILD_ABI \
-DANDROID_NATIVE_API_LEVEL=$BUILD_NATIVE_LEVEL \
-DMEGPEAK_ENABLE_OPENCL=${OPENCL} \
-DMEGPEAK_ENABLE_DOT=${DOT} \
-DMEGPEAK_ENABLE_MMA=${MMA} \
-DMEGPEAK_USE_CPUINFO=${CPUINFO}
ninja ${Target}
}
api_level=16
abi="armeabi-v7a with NEON"
IFS=""
if [ "$ARCH" = "arm64-v8a" ]; then
api_level=21
abi="arm64-v8a"
elif [ "$ARCH" = "armeabi-v7a" ]; then
api_level=16
abi="armeabi-v7a with NEON"
else
echo "ERR CONFIG ABORT NOW!!"
exit -1
fi
cmake_build $abi $api_level