-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathandroid_build.sh
executable file
·131 lines (120 loc) · 2.93 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env bash
set -e
BUILD_TYPE=Release
ARCH=arm64-v8a
OPENCL=OFF
ALL_BENCHMARK=OFF
CPUINFO=OFF
DOT=OFF
MMA=OFF
BFMMA=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 "-f : enable build with bfmma"
echo "-l : enable build with opencl"
echo "-t : enable total benchmark"
echo "-c : enable build with cpuinfo"
echo "-h : show usage"
echo "example: $0 -m armeabi-v7a"
exit -1
}
while getopts "adlcfhm:t" 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
;;
f)
echo "build with bfmmla"
BFMMA=ON
;;
h)
echo "show usage"
usage
exit 0
;;
t)
echo "build with total benchmark"
ALL_BENCHMARK=ON
;;
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_ALL_BENCHMARK=${ALL_BENCHMARK} \
-DMEGPEAK_ENABLE_DOT=${DOT} \
-DMEGPEAK_ENABLE_MMA=${MMA} \
-DMEGPEAK_ENABLE_BFMMA=${BFMMA} \
-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