forked from cjdelisle/cjdns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
android_do
executable file
·129 lines (105 loc) · 3.46 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
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
#change this to valid ndk path, otherwise it will be downloaded
NDK=/bad/path/to/android-ndk-r10e/
BUILD_PATH=$(pwd)/build_android
#if you have cjdns android app somewhere else then change it
NDK_VERSION="android-ndk-r10e"
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-r10e/" ]; 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 "http://dl.google.com/android/ndk/$NDK_VERSION-${TYPE}-${cpu_arch}.bin" \
|| (echo "Can't find download for your system"; exit 1)
[[ -d "$NDK_VERSION" ]] || (chmod a+x "$NDK_VERSION-${TYPE}-${cpu_arch}.bin"; "./$NDK_VERSION-${TYPE}-${cpu_arch}.bin" || 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
$NDK/build/tools/make-standalone-toolchain.sh --platform=android-21 --toolchain=arm-linux-androideabi-4.9 --install-dir=$BUILD_PATH/arm-${TYPE}-androideabi/ --system=${TYPE}-${cpu_arch}
$NDK/build/tools/make-standalone-toolchain.sh --platform=android-21 --toolchain=x86-4.9 --install-dir=$BUILD_PATH/i686-${TYPE}-androideabi/ --system=${TYPE}-${cpu_arch}
Seccomp_NO=1
mkdir $(pwd)/android_out
mkdir $(pwd)/android_out/armeabi-v7a
mkdir $(pwd)/android_out/x86
#arm build
rm -rf build_linux
export SYSTEM=linux
export CROSS_COMPILE=$BUILD_PATH/arm-${TYPE}-androideabi/bin/arm-linux-androideabi-
export TARGET_ARCH=arm
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)/android_out/armeabi-v7a/ || ret=$?
if [ "$ret" != "" ] && [ "$ret" != "0" ]; then
echo -e "\e[1;31mCopying armeabi-v7a binary failed, non zero status returned - $ret\e[0m"
else
echo -e "\e[1;32mCopied armeabi-v7a successfully\e[0m"
fi
rm cjdroute
#x86 build
rm -rf build_linux
export CROSS_COMPILE=$BUILD_PATH/i686-${TYPE}-androideabi/bin/i686-linux-android-
export TARGET_ARCH=x64
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)/android_out/x86/ || ret=$?
if [ "$ret" != "" ] && [ "$ret" != "0" ]; then
echo -e "\e[1;31mCopying x86 binary failed, non zero status returned - $ret\e[0m"
else
echo -e "\e[1;32mCopied x86 successfully\e[0m"
fi
rm cjdroute
echo -e "\n\e[1;34mOutput: $(pwd)/android_out/armeabi-v7a/cjdroute\e[0m"
echo -e "\e[1;34m $(pwd)/android_out/x86/cjdroute\e[0m"
exit $ret