Skip to content

Commit 472943a

Browse files
committed
add luajit android build scripts
1 parent d1c583c commit 472943a

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

build/android/build_with_no_export.sh

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/bin/sh
2+
set -e
3+
set -x
4+
5+
info()
6+
{
7+
local green="\033[1;32m"
8+
local normal="\033[0m"
9+
echo "[${green}build${normal}] $1"
10+
}
11+
12+
# TODO: You must set your ANDROID_NDK path in .bash_profile
13+
source ~/.bash_profile
14+
ANDROID_ABI="armeabi-v7a"
15+
ANDROID_API="android-19"
16+
ANDROID_GCC_VERSION=4.8
17+
ANDROID_ARCH=arm
18+
19+
# TODO: configure to compile specify 3rd party libraries
20+
OPTIONS=""
21+
22+
usage()
23+
{
24+
cat << EOF
25+
usage: $0 [options]
26+
Build cocos2d-x 3rd party libraries for Android
27+
OPTIONS:
28+
-h Show some help
29+
-q Be quiet
30+
-k <sdk> Use the specified Android API level (default: $ANDROID_API)
31+
-a <arch> Use the specified arch (default: $ANDROID_ABI)
32+
-n <version> Use the gcc version(default: $ANDROID_GCC_VERSION)
33+
-l <libname> Use the specified library name
34+
EOF
35+
}
36+
37+
spushd()
38+
{
39+
pushd "$1" > /dev/null
40+
}
41+
42+
spopd()
43+
{
44+
popd > /dev/null
45+
}
46+
47+
while getopts "hvk:a:l:" OPTION
48+
do
49+
case $OPTION in
50+
h)
51+
usage
52+
exit 1
53+
;;
54+
q)
55+
set +x
56+
QUIET="yes"
57+
;;
58+
a)
59+
ANDROID_ABI=$OPTARG
60+
;;
61+
k)
62+
ANDROID_API=$OPTARG
63+
;;
64+
n)
65+
ANDROID_GCC_VERSION=$OPTARG
66+
;;
67+
l)
68+
OPTIONS=--enable-$OPTARG
69+
;;
70+
esac
71+
done
72+
73+
if test -z "$OPTIONS"
74+
then
75+
echo "You must specify a OPTIONS parameter."
76+
usage
77+
exit 1
78+
fi
79+
80+
if [ "${ANDROID_ABI}" != "x86" ] && [ "${ANDROID_ABI}" != "armeabi-v7a" ] && [ "${ANDROID_ABI}" != "armeabi" ]; then
81+
echo "You must specify the right Android Arch within {armeabi, armeabi-v7a, x86}"
82+
exit 1
83+
fi
84+
85+
86+
# FIXME: we need a way to determine the toolchina address automatically
87+
toolchain_bin=
88+
89+
if [ "${ANDROID_ABI}" = "x86" ]; then
90+
TARGET="i686-linux-android"
91+
toolchain_bin=${ANDROID_NDK}/toolchains/x86-${ANDROID_GCC_VERSION}/prebuilt/darwin-x86_64/bin
92+
ANDROID_ARCH=x86
93+
else
94+
TARGET="arm-linux-androideabi"
95+
toolchain_bin=${ANDROID_NDK}/toolchains/${TARGET}-${ANDROID_GCC_VERSION}/prebuilt/darwin-x86_64/bin
96+
fi
97+
98+
shift $(($OPTIND - 1))
99+
if [ "x$1" != "x" ]; then
100+
usage
101+
exit 1
102+
fi
103+
#
104+
# Various initialization
105+
#
106+
out="/dev/stdout"
107+
if [ "$QUIET" = "yes" ]; then
108+
out="/dev/null"
109+
fi
110+
111+
info "Building 3rd party libraries for the Android"
112+
cocos_root=`pwd`/../..
113+
114+
export ANDROID_ABI
115+
export ANDROID_API
116+
# export LDFLAGS="-L${ANDROID_NDK}/platforms/${ANDROID_API}/arch-${ANDROID_ARCH}/usr/lib"
117+
# info "LD FLAGS SELECTED = '${LDFLAGS}'"
118+
119+
export PATH="${toolchain_bin}:${cocos_root}/extras/tools/bin:$PATH"
120+
if [ "$ANDROID_ABI" = "armeabi-v7a" ]; then
121+
export CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Os -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security "
122+
elif [ "$ANDROID_ABI" = "armeabi" ]; then
123+
CFLAGS="-ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -mthumb -Os -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security"
124+
else
125+
CFLAGS="-ffunction-sections -funwind-tables -fstack-protector -fPIC -no-canonical-prefixes -O2 -DNDEBUG -fomit-frame-pointer -fstrict-aliasing -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security"
126+
fi
127+
128+
info "CFLAGS is ${CFLAGS}"
129+
130+
#
131+
# build 3rd party libraries
132+
#
133+
info "Building static libraries"
134+
spushd "${cocos_root}/contrib"
135+
mkdir -p "Android-${ANDROID_ABI}" && cd "Android-${ANDROID_ABI}"
136+
137+
138+
../bootstrap ${OPTIONS} \
139+
--host=${TARGET} \
140+
--prefix=${cocos_root}/contrib/${TARGET}-${ANDROID_ABI}> $out
141+
142+
echo "ANDROID_ARCH := ${CFLAGS}" >> config.mak
143+
144+
#
145+
# make
146+
#
147+
make fetch
148+
make list
149+
make

contrib/src/luajit/rules.mak

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,18 @@ LUAJIT_TARGET_FLAGS="-arch armv7s -isysroot $(IOS_SDK)"
2525
LUAJIT_HOST_CC="gcc -m32 -arch i386"
2626
endif
2727

28+
ifdef HAVE_ANDROID
29+
NDKF=--sysroot=$(ANDROID_NDK)/platforms/$(ANDROID_API)/arch-$(PLATFORM_SHORT_ARCH)
30+
ifeq ($(ANDROID_ABI),armeabi-v7a)
31+
LUAJIT_LDFLAGS="-march=armv7-a -Wl,--fix-cortex-a8"
32+
endif
33+
endif
34+
2835

2936
.luajit: luajit
37+
ifdef HAVE_ANDROID
38+
cd $< && $(MAKE) HOST_CC="gcc -m32" CROSS=$(HOST)- TARGET_SYS=Linux TARGET_FLAGS="${ANDROID_ARCH} ${NDKF}" TARGET_LDFLAGS=$(LUAJIT_LDFLAGS)
39+
endif
3040
ifdef HAVE_MACOSX
3141
cd $< && $(MAKE) HOST_CC="$(CC)" HOST_CFLAGS="$(CFLAGS)"
3242
endif

0 commit comments

Comments
 (0)