build-scripts/androidbuild.sh
author Sam Lantinga <slouken@libsdl.org>
Fri, 02 Dec 2016 21:01:13 -0800
changeset 10673 4f02752f8d85
parent 10200 c678dcec4f44
child 11647 5816b27073a4
permissions -rwxr-xr-x
Added SDL_HINT_MOUSE_NORMAL_SPEED_SCALE and SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE to scale the speed of the mouse.
This currently doesn't affect absolute motion, which would need to be implemented on each windowing system so the cursor matches the reported mouse coordinates.
     1 #!/bin/bash
     2 
     3 SOURCES=()
     4 MKSOURCES=""
     5 CURDIR=`pwd -P`
     6 
     7 # Fetch sources
     8 if [[ $# -ge 2 ]]; then
     9     for src in ${@:2}
    10     do
    11         SOURCES+=($src)
    12         MKSOURCES="$MKSOURCES $(basename $src)"
    13     done
    14 else
    15     if [ -n "$1" ]; then
    16         while read src
    17         do
    18             SOURCES+=($src)
    19             MKSOURCES="$MKSOURCES $(basename $src)"
    20         done
    21     fi
    22 fi
    23 
    24 if [ -z "$1" ] || [ -z "$SOURCES" ]; then
    25     echo "Usage: androidbuild.sh com.yourcompany.yourapp < sources.list"
    26     echo "Usage: androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c"
    27     echo "To copy SDL source instead of symlinking: COPYSOURCE=1 androidbuild.sh ... "
    28     echo "You can pass additional arguments to ndk-build with the NDKARGS variable: NDKARGS=\"-s\" androidbuild.sh ..."
    29     exit 1
    30 fi
    31 
    32 
    33 
    34 SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )"
    35 
    36 NDKBUILD=`which ndk-build`
    37 if [ -z "$NDKBUILD" ];then
    38     echo "Could not find the ndk-build utility, install Android's NDK and add it to the path"
    39     exit 1
    40 fi
    41 
    42 ANDROID=`which android`
    43 if [ -z "$ANDROID" ];then
    44     echo "Could not find the android utility, install Android's SDK and add it to the path"
    45     exit 1
    46 fi
    47 
    48 ANT=`which ant`
    49 
    50 if [ -z "$ANT" ];then
    51     echo "Could not find the ant utility, install Android's SDK and add it to the path"
    52     exit 1
    53 fi
    54 
    55 NCPUS="1"
    56 case "$OSTYPE" in
    57     darwin*)
    58         NCPU=`sysctl -n hw.ncpu`
    59         ;; 
    60     linux*)
    61         if [ -n `which nproc` ]; then
    62             NCPUS=`nproc`
    63         fi  
    64         ;;
    65   *);;
    66 esac
    67 
    68 APP="$1"
    69 APPARR=(${APP//./ })
    70 BUILDPATH="$SDLPATH/build/$APP"
    71 
    72 # Start Building
    73 
    74 rm -rf $BUILDPATH
    75 mkdir -p $BUILDPATH
    76 
    77 cp -r $SDLPATH/android-project/* $BUILDPATH
    78 
    79 # Copy SDL sources
    80 mkdir -p $BUILDPATH/jni/SDL
    81 if [ -z "$COPYSOURCE" ]; then
    82     ln -s $SDLPATH/src $BUILDPATH/jni/SDL
    83     ln -s $SDLPATH/include $BUILDPATH/jni/SDL
    84 else
    85     cp -r $SDLPATH/src $BUILDPATH/jni/SDL
    86     cp -r $SDLPATH/include $BUILDPATH/jni/SDL
    87 fi
    88 
    89 cp -r $SDLPATH/Android.mk $BUILDPATH/jni/SDL
    90 sed -i -e "s|YourSourceHere.c|$MKSOURCES|g" $BUILDPATH/jni/src/Android.mk
    91 sed -i -e "s|org\.libsdl\.app|$APP|g" $BUILDPATH/AndroidManifest.xml
    92 
    93 # Copy user sources
    94 for src in "${SOURCES[@]}"
    95 do
    96     cp $src $BUILDPATH/jni/src
    97 done
    98 
    99 # Create an inherited Activity
   100 cd $BUILDPATH/src
   101 for folder in "${APPARR[@]}"
   102 do
   103     mkdir -p $folder
   104     cd $folder
   105 done
   106 
   107 ACTIVITY="${folder}Activity"
   108 sed -i -e "s|SDLActivity|$ACTIVITY|g" $BUILDPATH/AndroidManifest.xml
   109 sed -i -e "s|SDLActivity|$APP|g" $BUILDPATH/build.xml
   110 
   111 # Fill in a default Activity
   112 echo "package $APP;" >  "$ACTIVITY.java"
   113 echo "import org.libsdl.app.SDLActivity;" >> "$ACTIVITY.java"
   114 echo "public class $ACTIVITY extends SDLActivity {}" >> "$ACTIVITY.java"
   115 
   116 # Update project and build
   117 cd $BUILDPATH
   118 $ANDROID update project --path $BUILDPATH
   119 $NDKBUILD -j $NCPUS $NDKARGS
   120 $ANT debug
   121 
   122 cd $CURDIR
   123 
   124 APK="$BUILDPATH/bin/$APP-debug.apk"
   125 
   126 if [ -f "$APK" ]; then
   127     echo "Your APK is ready at $APK"
   128     echo "To install to your device: "
   129     echo "cd  $BUILDPATH"
   130     echo "ant debug install"
   131     exit 0
   132 fi
   133 
   134 echo "There was an error building the APK"
   135 exit 1