Created
September 14, 2013 01:46
-
-
Save crimsonwoods/6558128 to your computer and use it in GitHub Desktop.
build script for jamruby.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[email protected]:jamruby/jamruby.git | |
[email protected]:jamruby/JamrubyApp.git | |
GITHUB_URL_MRUBY=https://github.com/mruby/mruby.git | |
JAMRUBY_MRUBY_BUILD_CONFIG=jamruby_build_config.rb | |
UPDATE_REPOSITORIES=0 | |
ANDROID_TARGET_JAMRUBY=`cat jamruby/project.properties | grep -P "target\s*\=\s*android\-" | sed -e "s/target\=\(.*\)/\\1/"` | |
ANDROID_TARGET_JAMRUBYAPP=`cat JamrubyApp/project.properties | grep -P "target\s*\=\s*android\-" | sed -e "s/target\=\(.*\)/\\1/"` | |
while getopts "uh" OPT | |
do | |
case $OPT in | |
u) | |
UPDATE_REPOSITORIES=1 | |
;; | |
h) | |
echo "Usage: `basename $0` [-u]" | |
echo "[Options]" | |
echo " -u : update repository before build." | |
exit 0 | |
;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
check_command() { | |
which=`which $1` | |
if [ -z $which ] | |
then | |
echo "'$1' command is not found in your environment." | |
exit 1 | |
fi | |
} | |
setup_env() { | |
if [ ! -z $ANDROID_HOME ] | |
then | |
return 0 | |
fi | |
if [ ! -z $ANDROID_SDK_HOME ] | |
then | |
if [ -d $ANDROID_SDK_HOME ] | |
then | |
ANDROID_HOME=$ANDROID_SDK_HOME | |
export ANDROID_HOME | |
return 0 | |
fi | |
fi | |
if [ ! -z $ANDROIDSDK_HOME ] | |
then | |
if [ -d $ANDROIDSDK_HOME ] | |
then | |
ANDROID_HOME=$ANDROIDSDK_HOME | |
export ANDROID_HOME | |
fi | |
fi | |
echo "please set 'ANDROID_HOME' or 'ANDROID_SDK_HOME' environment variable." | |
exit 1 | |
} | |
check_android_target() { | |
jamruby_target=`android list target | grep -P "$ANDROID_TARGET_JAMRUBY"` | |
jamrubyapp_target=`android list target | grep -P "$ANDROID_TARGET_JAMRUBYAPP"` | |
if [ -z $jamruby_target -o -z $jamrubyapp_target ] | |
then | |
echo "android target is not found." | |
echo "please check your available targets." | |
echo "'android list target' command can use to do." | |
exit 1 | |
fi | |
} | |
git_clone() { | |
if [ -z "$2" ] | |
then | |
git clone $1 | |
else | |
git clone $1 $2 | |
fi | |
if [ $? -ne 0 ] | |
then | |
echo "cannot clone git repository from '$1'." >&2 | |
exit 1 | |
fi | |
} | |
git_pull() { | |
pushd . > /dev/null | |
echo "Update git repository '$1'." | |
cd $1 | |
git checkout -f . | |
git checkout master | |
git pull origin master | |
result=$? | |
popd > /dev/null | |
if [ $result -ne 0 ] | |
then | |
echo "cannot update git repository" >&2 | |
exit 1 | |
fi | |
} | |
# check if required commands are available? | |
check_command git && \ | |
check_command ant && \ | |
check_command ndk-build && \ | |
check_command ruby && \ | |
check_command bison && \ | |
check_command java && \ | |
check_command android | |
# check if required android targets are available? | |
check_android_target | |
# setup environment variable if 'local.properties' files are not. | |
if [ ! -e jamruby/local.properties -o ! -e JamrubyApp/local.properties ] | |
then | |
setup_env | |
fi | |
# cloning jamruby project | |
if [ ! -d jamruby ] | |
then | |
git_clone $GITHUB_URL_JAMRUBY | |
fi | |
# cloning JamrubyApp project | |
if [ ! -d JamrubyApp ] | |
then | |
git_clone $GITHUB_URL_JAMRUBYAPP | |
fi | |
# cloning mruby project | |
if [ ! -d mruby ] | |
then | |
git_clone $GITHUB_URL_MRUBY | |
fi | |
if [ $UPDATE_REPOSITORIES -ne 0 ] | |
then | |
echo "Update all projects." | |
echo "This process dispose all changes!" | |
echo -n "Do you want to continue? [Y/n]: " | |
perform=0 | |
while true | |
do | |
read YESNO | |
if [ $YESNO = 'Y' -o $YESNO = 'y' ] | |
then | |
perform=1 | |
break | |
fi | |
if [ $YESNO = 'N' -o $YESNO = 'n' ] | |
then | |
break | |
fi | |
done | |
if [ $perform -eq 1 ] | |
then | |
git_pull jamruby | |
git_pull JamrubyApp | |
git_pull mruby | |
else | |
echo "Update is canceled." | |
fi | |
fi | |
# copy build configuration file | |
if [ ! -e mruby/$JAMRUBY_MRUBY_BUILD_CONFIG ] | |
then | |
if [ -e jamruby/$JAMRUBY_MRUBY_BUILD_CONFIG ] | |
then | |
cp jamruby/$JAMRUBY_MRUBY_BUILD_CONFIG mruby | |
else | |
echo "'$JAMRUBY_MRUBY_BUILD_CONFIG' is not found in 'jamruby' directory." >&2 | |
exit 1 | |
fi | |
fi | |
# make mruby | |
if [ ! -d mruby/build/ ] | |
then | |
pushd . > /dev/null | |
echo "Enter 'mruby' directory and make mruby." | |
cd mruby | |
MRUBY_CONFIG=$JAMRUBY_MRUBY_BUILD_CONFIG make | |
popd > /dev/null | |
fi | |
# make jamruby | |
if [ -d jamruby ] | |
then | |
pushd . > /dev/null | |
echo "Enter 'jamruby' directory and build." | |
cd jamruby/jni | |
ndk-build | |
cd ../ | |
if [ -e build.xml ] | |
then | |
ant release | |
else | |
echo "'build.xml' is not found in 'jamruby' directory." >&2 | |
fi | |
popd > /dev/null | |
fi | |
# make jamruby app | |
if [ -d JamrubyApp ] | |
then | |
pushd . > /dev/null | |
echo "Enter 'JamrubyApp' directory and build." | |
cd JamrubyApp | |
if [ -e build.xml ] | |
then | |
ant release | |
else | |
echo "'build.xml' is not found in 'JamrubyApp' directory." >&2 | |
fi | |
popd > /dev/null | |
else | |
echo "'JamrubyApp' directory is not found." >&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment