-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-android.sh
executable file
·151 lines (124 loc) · 3.7 KB
/
build-android.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash -e
set -x
ANDROID_API=15
TOOLCHAIN=arm-linux-androideabi-4.9
##
## Dep. versions
##
CARES_VER=1.10.0
LIBCONFIG_VER=1.4.9
LIBSODIUM_VER=1.0.2
CURL_VER=7.42.1
##
## This shouldn't need to be changed for a while ...
##
BASE_DIR=$PWD
# Find NDK
if [ -z ${ANDROID_NDK} ]; then
ANDROID_NDK=~/local/android-ndk-r10d
echo "Setting ANDROID_NDK to a default value: $ANDROID_NDK"
fi
if [ -d ${ANDROID_NDK} ]; then
echo "Found Android NDK in $ANDROID_NDK"
else
echo "$ANDROID_NDK does not appear to contain a NDK installation...Aborting."
exit 1
fi
# Export toolchain
if [ -d ${TOOLCHAIN} ]; then
echo "Re-using existing Android NDK toolchain found in '$TOOLCHAIN'"
else
echo "Creating Android NDK toolchain in '$TOOLCHAIN'"
mkdir ${TOOLCHAIN}
sh $ANDROID_NDK/build/tools/make-standalone-toolchain.sh \
--platform=android-$ANDROID_API \
--toolchain=${TOOLCHAIN} \
--install-dir=${TOOLCHAIN}
if [ $? -ne 0 ]; then
echo "Failed to create the Android NDK Toolchain...Aborting."
rm -rf ${TOOLCHAIN}
exit 1
fi
fi
# Update env. var
export CC=arm-linux-androideabi-gcc
export CXX=arm-linux-androideabi-g++
export RANLIB=arm-linux-androideabi-ranlib
export AR=arm-linux-androideabi-ar
export LD=arm-linux-androideabi-ld
export STRIP=arm-linux-androideabi-strip
export PATH=$PWD/$TOOLCHAIN/bin:$PATH
export CFLAGS="-Os -fPIE $CFLAGS"
export CXXFLAGS="-Os -fPIE $CXXFLAGS"
export LDFLAGS="-fPIE -pie $LDFLAGS"
# Build dependencies
build_dep() {
FILE=$(eval "echo \${F$1}")
if [ ! -e ${FILE} ]; then
echo "Downloading $FILE"
curl -L -o $FILE $(eval "echo \${$1_URL}")
else
echo "Skipping download of $FILE"
fi
DIR=$(eval "echo \${$1}")-$(eval "echo \${$1_VER}")
if [ ! -d ${DIR} ]; then
echo "Expanding to $DIR"
mkdir ${DIR}
tar -xf ${FILE} -C ${DIR} --strip-component=1
else
echo "$FILE is already uncompressed in $DIR"
fi
cd ${DIR}
BUILD="$1_build"
eval ${BUILD}
cd $BASE_DIR
}
CARES="c-ares"
FCARES=$CARES-$CARES_VER.tar.gz
CARES_URL=http://c-ares.haxx.se/download/$FCARES
CARES_build() {
./configure --host=arm-linux --disable-shared --prefix=$BASE_DIR
make -j4
make install
}
LIBCONFIG="libconfig"
FLIBCONFIG=$LIBCONFIG-$LIBCONFIG_VER.tar.gz
LIBCONFIG_URL=http://www.hyperrealm.com/libconfig/$FLIBCONFIG
LIBCONFIG_build() {
./configure --host=arm-linux --disable-shared --prefix=$BASE_DIR
make -j4
make install
}
LIBSODIUM="libsodium"
FLIBSODIUM=$LIBSODIUM-$LIBSODIUM_VER.tar.gz
LIBSODIUM_URL=https://download.libsodium.org/libsodium/releases/$FLIBSODIUM
LIBSODIUM_build() {
./configure --host=arm-linux --disable-shared --prefix=$BASE_DIR
make -j4
make install
}
CURL="curl"
FCURL=$CURL-$CURL_VER.tar.gz
CURL_URL=http://curl.haxx.se/download/$FCURL
CURL_build() {
./configure --host=arm-linux --disable-shared --prefix=$BASE_DIR --disable-ntlm-wb --without-zlib
make -j4
make install
}
mkdir -p usr/include/sys
echo "#include <sys/types.h>" > usr/include/sys/bitypes.h
#export CFLAGS="$CFLAGS -I$BASE_DIR/usr/include"
export CXXFLAGS="$CXXFLAGS -I$BASE_DIR/usr/include"
#for dep in CARES LIBCONFIG LIBSODIUM CURL; do
# build_dep $dep
#done
export CC=arm-linux-androideabi-gcc
$CC -O0 -ggdb -c -Iinclude -fpic dns_tests.c
$CC -shared -o libdns_tests.so dns_tests.o -Llib -lcares
$CC -O0 -ggdb -c -Iinclude -fpic curl_tests.c
$CC -shared -o libcurl_tests.so curl_tests.o -Llib -lcurl
## -e : environment variables override those defined in Makefile
make -e android
# debug notes:
#~/local/android-ndk-r10d/ndk-stack -sym ./ -dump ts
#~/local/android-ndk-r10d/toolchains/x86-4.6/prebuilt/linux-x86_64/bin/i686-linux-android-addr2line -f -e libdns_tests.so 00003628