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