forked from cjdelisle/cjdns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
android_do
executable file
·116 lines (96 loc) · 3.18 KB
/
android_do
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
#!/bin/bash
#change this to valid ndk path, otherwise it will be downloaded
NDK=/bad/path/to/android-ndk-r11c/
BUILD_PATH=$(pwd)/build_android
#if you have cjdns android app somewhere else then change it
NDK_VERSION="android-ndk-r11c"
case $(uname -s) in
Darwin)
TYPE=darwin
;;
Linux)
TYPE=linux
;;
*)
TYPE=
;;
esac
cpu_arch="$(uname -m)"
[[ -z "$cpu_arch" ]] && {
echo "ERROR: NO CPU ARCHITECTURE DETECTED"
exit 1
}
[[ "$cpu_arch" = "i686" ]] \
&& cpu_arch="x86"
android_log=android_build_$$.log
enabled_log=${LOG}
mkdir $BUILD_PATH
if [ "$NDK" == "/bad/path/to/android-ndk-r11c/" ]; then
if [ ! -d $BUILD_PATH/$NDK_VERSION/ ]; then
echo "NDK path is not specified. Downloading it..."
NDK=$BUILD_PATH/$NDK_VERSION/
##SETUP NDK
cd "$BUILD_PATH"
if [ ! -d "$NDK" ]; then
echo "$NDK_VERSION-${TYPE}-${cpu_arch}.tar.bz2"
[[ -f "$NDK_VERSION-${TYPE}-${cpu_arch}.tar.bz2" ]] \
|| wget "https://dl.google.com/android/repository/$NDK_VERSION-${TYPE}-${cpu_arch}.zip" \
|| (echo "Can't find download for your system"; exit 1)
[[ -d "$NDK_VERSION" ]] || (unzip -q "$NDK_VERSION-${TYPE}-${cpu_arch}.zip" || exit 1)
fi
[[ ! -d "$NDK" ]] && {
echo "The NDK variable is not pointing to a valid directory"
exit 1
}
cd ..
else
NDK=$BUILD_PATH/$NDK_VERSION/
fi
fi
Seccomp_NO=1
mkdir $(pwd)/build_android/out
declare -a APP_ABI=("armeabi-v7a" "arm64-v8a" "x86")
declare -a APP_ABI2=("arm" "aarch64" "i686")
declare -a TARGET_ARCH=("arm" "aarch64" "x64")
declare -a EABI=("androideabi" "android" "android")
declare -a PLATFORM=(16 21 16)
declare -a TOOLCHAIN=("arm-linux-androideabi-4.9" "aarch64-linux-android-4.9" "x86-4.9")
for i in {0..2}
do
GCC=$BUILD_PATH/${APP_ABI2[$i]}-${TYPE}-${EABI[$i]}/bin/${APP_ABI2[$i]}-linux-${EABI[$i]}-gcc
[[ ! -x "$GCC" ]] && {
$NDK/build/tools/make-standalone-toolchain.sh --platform=android-${PLATFORM[$i]} --toolchain=${TOOLCHAIN[$i]} --install-dir=$BUILD_PATH/${APP_ABI2[$i]}-${TYPE}-${EABI[$i]}/ \
|| exit 1
}
mkdir $(pwd)/build_android/out/${APP_ABI[$i]}
rm -rf build_linux
export PLATFORM=android
export SYSTEM=linux
export CROSS_COMPILE=$BUILD_PATH/${APP_ABI2[$i]}-${TYPE}-${EABI[$i]}/bin/${APP_ABI2[$i]}-linux-${EABI[$i]}-
export CROSS=${CROSS_COMPILE}
export CC=${CROSS}gcc
export AR=${CROSS}ar
export RANLIB=${CROSS}ranlib
export CFLAGS=${CROSS_CFLAGS}
export LDFLAGS=${CROSS_LDFLAGS}
gcc_version=$(${CC} --version)
echo Using $gcc_version
echo Compiler CC: $CC
echo Compiler CFLAGS: $CFLAGS
echo Compiler LDFLAGS: $LDFLAGS
time ./do
cp cjdroute $(pwd)/build_android/out/${APP_ABI[$i]}/ || ret=$?
if [ "$ret" != "" ] && [ "$ret" != "0" ]; then
echo -e "\e[1;31mCopying ${APP_ABI[$i]} binary failed, non zero status returned - $ret\e[0m"
exit 1
else
echo -e "\e[1;32mCopied ${APP_ABI[$i]} successfully\e[0m"
fi
rm cjdroute
done
echo -e "\n\e[1;34mOutput:\e[0m"
for i in {0..2}
do
echo -e "\e[1;34m $(pwd)/build_android/out/${APP_ABI[$i]}/cjdroute\e[0m"
done
exit $ret