-
Notifications
You must be signed in to change notification settings - Fork 21
/
ndk-configure
executable file
·210 lines (186 loc) · 5.37 KB
/
ndk-configure
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
# static data
CROSS_COMPILE=arm-linux-androideabi
NDK_TOOLCHAIN=""
function die()
{
echo $@
exit 1
}
function arg_parse()
{
if [ $# -lt 2 ] ; then
name=$(basename "$0")
die -e "Usage $name <ndk_path> <api_level> [configure_script] [stl_provider] [update_files]\n\
\n\
where:\n\
\n\
\tndk_path is the install directory of your ndk ( usually /opt/android-ndk )\n\
\tapi_level is the target api level of your application\n\
\tconfigure_script is the real configure script [default=./configure]\n\
\tstl_provider is the c++ stl provider [default=system]\n\
\tif update_files option is given will update machine detecting scripts\n\
\n\
stl_provider must be one of:\n\
\n\
\tgnustl_static: GNU stl statically linked\n\
\tgnustl_shared: GNU stl shared library\n\
\tstlport_static: android NDK stl port statically linked\n\
\tstlport_shared: android NDK stl port shared library\n\
\tsystem: android NDK default stl\n\
\n\
read this answer for choose the right stl:\n\
\thttp://stackoverflow.com/questions/9226513/linker-errors-in-android-ndk-undefined-reference-to-cxa-end-cleanup\n"
fi
if [ ! -d "$1" ] ; then
die "error: the ndk-path is not valid"
fi
if [ ! -d "$1/platforms/android-$2/" ] ; then
die "cannot find android sysroot in your ndk_path"
fi
}
function check_external_scripts()
{
if [ ! -f "${NDK}/config.guess" -o ! -f "${NDK}/config.sub" ] ; then
echo "warning: missing config.guess or config.sub in your ndk dir"
echo "info: should i download them for you? [y/n]"
read choice
if [ "x$choice" != "xy" -a "x$choice" != "xY" ] ; then
die "error: missing config.guess or config.sub"
fi
wget "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD" -qO "${NDK}/config.sub" || die "cannot download config.sub"
wget "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD" -qO "${NDK}/config.guess" || die "cannot download config.guess"
fi
#cp ${NDK}/config.guess . || die "cannot import files"
#cp ${NDK}/config.sub . || die "cannot import files"
}
function update_files()
{
for f in config.sub config.guess; do
for dst in $(find . -name "$f"); do
diff -q "${NDK}/$f" "$dst" 2>&1 >/dev/null || cp -b "${NDK}/$f" "$dst"
done
done
}
function find_toolchain()
{
local tmp;
local host_arch;
case $(uname -m) in
x86_64)
host_arch="x86_64 x86"
;;
i[3456]86)
host_arch="x86"
;;
*)
die "cannot detect your system arch"
;;
esac
for d in $( ls -1 "${NDK}/toolchains/" ); do
name=$(basename "$d")
case $name in
*clang*) continue
;;
$CROSS_COMPILE-*)
for arch in $host_arch; do
NDK_TOOLCHAIN="${NDK}/toolchains/$name/prebuilt/linux-$arch/bin"
tmp="${NDK_TOOLCHAIN}/${CROSS_COMPILE}-"
for bin in gcc g++ ld ar ranlib strip; do
if [ ! -f "$tmp$bin" ] ; then
unset NDK_TOOLCHAIN
break
fi
done
test "x$NDK_TOOLCHAIN" != "x" && break
done
;;
*) continue
;;
esac
done
test "x$NDK_TOOLCHAIN" != "x" || die "cannot find an usable toolchain"
}
function find_cxxflags()
{
case $1 in
gnustl_*)
includes=$(find ${NDK}/sources/cxx-stl/gnu* -maxdepth 2 -name include | head -n1)
main_path=$(grep -oE "^.*/[0-9]+\.[0-9]+\.?[0-9]*/" <<<$includes)
libdir=$(find $main_path -type d -name armeabi)
includes="$includes ${libdir}/include"
;;
stlport_*)
main_path="${NDK}/sources/cxx-stl/stlport/"
includes="${main_path}stlport"
libdir="${main_path}libs/armeabi"
;;
*)
main_inc=no
includes=no
libdir=no
;;
esac
if test "x$libdir" != "xno"; then
test -d $libdir || die "cannot find include directories for c++"
CXXFLAGS="${CXXFLAGS} -L$libdir -l$1 -I${includes/ / -I}"
echo "CXXFLAGS=$CXXFLAGS"
export CXXFLAGS
export LDFLAGS="-L$libdir -l$1 ${LDFLAGS}"
fi
}
## MAIN ##
arg_parse $@
NDK=$1
PLATFORM="android-$2"
if test -x "$3"; then
CONFIGURE=$3
shift
else
CONFIGURE="./configure"
fi
shift
shift
check_external_scripts
find_toolchain
old=$CXXFLAGS
find_cxxflags $1
test "$CXXFLAGS" != "$old" && shift
unset old
if test "$1" == "update_files"; then
update_files
exit 0
fi
export AS=${NDK_TOOLCHAIN}/${CROSS_COMPILE}-as
export CC=${NDK_TOOLCHAIN}/${CROSS_COMPILE}-gcc
export CXX=${NDK_TOOLCHAIN}/${CROSS_COMPILE}-g++
export CPP=${NDK_TOOLCHAIN}/${CROSS_COMPILE}-cpp
export LD=${NDK_TOOLCHAIN}/${CROSS_COMPILE}-ld
export AR=${NDK_TOOLCHAIN}/${CROSS_COMPILE}-ar
export RANLIB=${NDK_TOOLCHAIN}/${CROSS_COMPILE}-ranlib
export STRIP=${NDK_TOOLCHAIN}/${CROSS_COMPILE}-strip
export ac_cv_func_malloc_0_nonnull=yes
export ac_cv_func_realloc_0_nonnull=yes
export SYSROOT=${NDK}/platforms/${PLATFORM}/arch-arm
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT}"
export CPPFLAGS="${CPPFLAGS} --sysroot=${SYSROOT}"
export CXXFLAGS="${CXXFLAGS} --sysroot=${SYSROOT}"
export LDFLAGS="--sysroot=${SYSROOT} ${LDFLAGS}"
argStr=""
while [ "$1" != "" ] ; do
argStr="${argStr} $1"
shift
done
warning=no
if $CONFIGURE --help | grep -q "with-sysroot"; then
argStr="--with-sysroot=$SYSROOT $argStr"
else
warning="this configure script does not accept sysroot option.\nplease check any absolute path in the script"
fi
$CONFIGURE "--host=$CROSS_COMPILE" "--target=$CROSS_COMPILE" "--prefix=$SYSROOT/usr" $argStr
if test "x$warning" != "xno"; then
echo -e $warning
fi
#make -j$(( $(cat /proc/cpuinfo | grep processor | wc -l) +1 ))
#DEBUG
#make install