Skip to content

Commit b07cfe1

Browse files
committed
android: initial configure helper for the Android NDK toolchain
1 parent a4cac25 commit b07cfe1

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

android/ndk-configure

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/bash
2+
3+
if [ "$1" = "" ]; then
4+
echo "Usage ndk-autoconf <api> <architecture> <compiler>"
5+
echo "e.g. ndk-autoconf android-9 armeabi 4.6"
6+
exit 1
7+
fi
8+
9+
##### host detection:
10+
11+
HOST_OS=$(uname -s)
12+
case ${HOST_OS} in
13+
Darwin) HOST_OS=darwin ;;
14+
Linux) HOST_OS=linux ;;
15+
FreeBsd) HOST_OS=freebsd ;;
16+
CYGWIN*|*_NT-*) HOST_OS=cygwin ;;
17+
*)
18+
echo "ERROR: Unknown host operating system: ${HOST_OS}"
19+
exit 1
20+
esac
21+
22+
HOST_ARCH=$(uname -m)
23+
case ${HOST_ARCH} in
24+
i?86) HOST_ARCH=x86 ;;
25+
x86_64|and64) HOST_ARCH=x86_64 ;;
26+
*)
27+
echo "ERROR: Unknown host CPU architecture: ${HOST_ARCH}"
28+
exit 1
29+
esac
30+
31+
HOST=${HOST_OS}-${HOST_ARCH}
32+
33+
##### target detection:
34+
35+
platform=$1
36+
ARCH=$2
37+
case "${ARCH}" in
38+
armeabi)
39+
# export ARCH_FLAGS="-march=armv5te -mtune=xscale -msoft-float -mthumb"
40+
export CROSS_COMPILE=arm-linux-androideabi
41+
arch=arm
42+
;;
43+
armeabi-v7a)
44+
# export ARCH_FLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb"
45+
export CROSS_COMPILE=arm-linux-androideabi
46+
arch=arm
47+
;;
48+
x86)
49+
export CROSS_COMPILE=x86
50+
arch=x86
51+
;;
52+
mips)
53+
export CROSS_COMPILE=mipsel-linux-android
54+
arch=mips
55+
;;
56+
*)
57+
echo "Unsupported architecture: $2"
58+
echo "... supported architectures: armeabi, armabi-v7a, x86, mips"
59+
exit 1
60+
esac
61+
compiler=$3
62+
63+
shift
64+
shift
65+
shift
66+
67+
##### compiler configuration:
68+
69+
export NDK=`ndk-which gcc | sed -e 's,/toolchains/.*,,'`
70+
71+
export NDK_TOOLCHAIN=${NDK}/toolchains/${CROSS_COMPILE}-${compiler}/prebuilt/${HOST}/bin
72+
73+
export CC=${NDK_TOOLCHAIN}/${CROSS_COMPILE}-gcc
74+
export CXX=${NDK_TOOLCHAIN}/${CROSS_COMPILE}-g++
75+
export LD=${NDK_TOOLCHAIN}/${CROSS_COMPILE}-ld
76+
export AR=${NDK_TOOLCHAIN}/${CROSS_COMPILE}-ar
77+
export RANLIB=${NDK_TOOLCHAIN}/${CROSS_COMPILE}-ranlib
78+
export STRIP=${NDK_TOOLCHAIN}/${CROSS_COMPILE}-strip
79+
80+
export ac_cv_func_malloc_0_nonnull=yes
81+
export ac_cv_func_realloc_0_nonnull=yes
82+
83+
export SYSROOT=${NDK}/platforms/${platform}/arch-${arch}
84+
85+
export CXXFLAGS="--sysroot=${SYSROOT}"
86+
export CFLAGS=" --sysroot=${SYSROOT}"
87+
88+
##### C++ standard library:
89+
90+
export STL=${NDK}/sources/cxx-stl/gnu-libstdc++/${compiler}
91+
92+
export CXXFLAGS="${CXXFLAGS} -isystem ${STL}/include -isystem ${STL}/libs/${ARCH}/include" "-L\"${STL}/libs/${ARCH}\" -lgnustl_static -lsupc++"
93+
94+
##### configure:
95+
96+
argStr=""
97+
98+
while [ "$1" != "" ]; do
99+
argStr="${argStr} $1"
100+
shift
101+
done
102+
103+
./configure --host=${CROSS_COMPILE} --target=${CROSS_COMPILE} --prefix=$SYSROOT/usr LIBS="-lc -lgcc" $argStr

build.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/bash
22

33
PACKAGE=cainteoir-engine
4+
ANDROID_VERSION=8
5+
ANDROID_COMPILER=4.6
6+
ANDROID_ARCHS="armeabi armeabi-v7a x86 mips"
47

58
doclean() {
69
git clean -fxd
@@ -14,14 +17,26 @@ dodist() {
1417
( popd && exit 1 )
1518
}
1619

20+
doandroid() {
21+
./autogen.sh || exit 1
22+
for arch in ${ANDROID_ARCHS} ; do
23+
echo "===== android ${arch} ====="
24+
android/ndk-configure android-${ANDROID_VERSION} ${arch} ${ANDROID_COMPILER} || exit 1
25+
make || exit 1
26+
sudo make install || exit 1
27+
done
28+
}
29+
1730
case "$1" in
31+
android) doandroid ;;
1832
clean) doclean ;;
1933
dist) dodist ;;
2034
help|*)
2135
echo "usage: `basename $0` <command>
2236
2337
where <command> is one of:
2438
39+
android Build the library for android.
2540
clean Clean the build tree and generated files.
2641
dist Create (and test) a distribution source tarball.
2742
help Show this help screen.

0 commit comments

Comments
 (0)