Merge pull request #1137 from folecr/fixandroidbuildscript

issue #1407:Cleaner build script
This commit is contained in:
minggo 2012-07-27 17:52:44 -07:00
commit 84d47d2400
1 changed files with 40 additions and 28 deletions

View File

@ -1,6 +1,6 @@
# set params
NDK_ROOT_LOCAL=/home/james/Software/android/android-ndk-r8b
COCOS2DX_ROOT_LOCAL=/home/james/Project/cocos2d-x
APPNAME="HelloCpp"
# options
buildexternalsfromsource=
@ -8,7 +8,7 @@ usage(){
cat << EOF
usage: $0 [options]
Build C/C++ native code using Android NDK
Build C/C++ code for $APPNAME using Android NDK
OPTIONS:
-s Build externals from source
@ -16,7 +16,7 @@ OPTIONS:
EOF
}
while getopts "s" OPTION; do
while getopts "sh" OPTION; do
case "$OPTION" in
s)
buildexternalsfromsource=1
@ -28,44 +28,56 @@ exit 0
esac
done
# try to get global variable
if [ $NDK_ROOT"aaa" != "aaa" ]; then
echo "use global definition of NDK_ROOT: $NDK_ROOT"
NDK_ROOT_LOCAL=$NDK_ROOT
# paths
if [ -z "${NDK_ROOT+aaa}" ]; then
# ... if NDK_ROOT is not set, use "$HOME/bin/android-ndk"
NDK_ROOT="$HOME/bin/android-ndk"
fi
if [ $COCOS2DX_ROOT"aaa" != "aaa" ]; then
echo "use global definition of COCOS2DX_ROOT: $COCOS2DX_ROOT"
COCOS2DX_ROOT_LOCAL=$COCOS2DX_ROOT
if [ -z "${COCOS2DX_ROOT+aaa}" ]; then
# ... if COCOS2DX_ROOT is not set
# ... find current working directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# ... use paths relative to current directory
COCOS2DX_ROOT="$DIR/../../.."
APP_ROOT="$DIR/.."
APP_ANDROID_ROOT="$DIR"
else
APP_ROOT="$COCOS2DX_ROOT/samples/$APPNAME"
APP_ANDROID_ROOT="$COCOS2DX_ROOT/samples/$APPNAME/proj.android"
fi
HELLOWORLD_ROOT=$COCOS2DX_ROOT_LOCAL/samples/HelloCpp/proj.android
echo "NDK_ROOT = $NDK_ROOT"
echo "COCOS2DX_ROOT = $COCOS2DX_ROOT"
echo "APP_ROOT = $APP_ROOT"
echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
# make sure assets is exist
if [ -d $HELLOWORLD_ROOT/assets ]; then
rm -rf $HELLOWORLD_ROOT/assets
if [ -d "$APP_ANDROID_ROOT/assets" ]; then
rm -rf $APP_ANDROID_ROOT/assets
fi
mkdir $HELLOWORLD_ROOT/assets
mkdir $APP_ANDROID_ROOT/assets
# copy resources
for file in $COCOS2DX_ROOT_LOCAL/samples/HelloCpp/Resources/*
for file in $APP_ROOT/Resources/*
do
if [ -d $file ]; then
cp -rf $file $HELLOWORLD_ROOT/assets
if [ -d "$file" ]; then
cp -rf $file $APP_ANDROID_ROOT/assets
fi
if [ -f $file ]; then
cp $file $HELLOWORLD_ROOT/assets
if [ -f "$file" ]; then
cp $file $APP_ANDROID_ROOT/assets
fi
done
if [[ $buildexternalsfromsource ]]; then
echo "Building external dependencies from source"
$NDK_ROOT_LOCAL/ndk-build -C $HELLOWORLD_ROOT $* \
NDK_MODULE_PATH=${COCOS2DX_ROOT_LOCAL}:${COCOS2DX_ROOT_LOCAL}/cocos2dx/platform/third_party/android/source
if [[ "$buildexternalsfromsource" ]]; then
echo "Building external dependencies from source"
$NDK_ROOT/ndk-build -C $APP_ANDROID_ROOT $* \
NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source
else
echo "Using prebuilt externals"
$NDK_ROOT_LOCAL/ndk-build -C $HELLOWORLD_ROOT $* \
NDK_MODULE_PATH=${COCOS2DX_ROOT_LOCAL}:${COCOS2DX_ROOT_LOCAL}/cocos2dx/platform/third_party/android/prebuilt
echo "Using prebuilt externals"
$NDK_ROOT/ndk-build -C $APP_ANDROID_ROOT $* \
NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt
fi