🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.4 KiB

  1. #!/bin/bash
  2. SOURCES=()
  3. MKSOURCES=""
  4. CURDIR=`pwd -P`
  5. # Fetch sources
  6. if [[ $# -ge 2 ]]; then
  7. for src in ${@:2}
  8. do
  9. SOURCES+=($src)
  10. MKSOURCES="$MKSOURCES $(basename $src)"
  11. done
  12. else
  13. if [ -n "$1" ]; then
  14. while read src
  15. do
  16. SOURCES+=($src)
  17. MKSOURCES="$MKSOURCES $(basename $src)"
  18. done
  19. fi
  20. fi
  21. if [ -z "$1" ] || [ -z "$SOURCES" ]; then
  22. echo "Usage: androidbuild.sh com.yourcompany.yourapp < sources.list"
  23. echo "Usage: androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c"
  24. echo "To copy SDL source instead of symlinking: COPYSOURCE=1 androidbuild.sh ... "
  25. exit 1
  26. fi
  27. SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )"
  28. if [ -z "$ANDROID_HOME" ];then
  29. echo "Please set the ANDROID_HOME directory to the path of the Android SDK"
  30. exit 1
  31. fi
  32. if [ ! -d "$ANDROID_HOME/ndk-bundle" -a -z "$ANDROID_NDK_HOME" ]; then
  33. echo "Please set the ANDROID_NDK_HOME directory to the path of the Android NDK"
  34. exit 1
  35. fi
  36. APP="$1"
  37. APPARR=(${APP//./ })
  38. BUILDPATH="$SDLPATH/build/$APP"
  39. # Start Building
  40. rm -rf $BUILDPATH
  41. mkdir -p $BUILDPATH
  42. cp -r $SDLPATH/android-project/* $BUILDPATH
  43. # Copy SDL sources
  44. mkdir -p $BUILDPATH/app/jni/SDL
  45. if [ -z "$COPYSOURCE" ]; then
  46. ln -s $SDLPATH/src $BUILDPATH/app/jni/SDL
  47. ln -s $SDLPATH/include $BUILDPATH/app/jni/SDL
  48. else
  49. cp -r $SDLPATH/src $BUILDPATH/app/jni/SDL
  50. cp -r $SDLPATH/include $BUILDPATH/app/jni/SDL
  51. fi
  52. cp -r $SDLPATH/Android.mk $BUILDPATH/app/jni/SDL
  53. sed -i -e "s|YourSourceHere.c|$MKSOURCES|g" $BUILDPATH/app/jni/src/Android.mk
  54. sed -i -e "s|org\.libsdl\.app|$APP|g" $BUILDPATH/app/build.gradle
  55. sed -i -e "s|org\.libsdl\.app|$APP|g" $BUILDPATH/app/src/main/AndroidManifest.xml
  56. # Copy user sources
  57. for src in "${SOURCES[@]}"
  58. do
  59. cp $src $BUILDPATH/app/jni/src
  60. done
  61. # Create an inherited Activity
  62. cd $BUILDPATH/app/src/main/java
  63. for folder in "${APPARR[@]}"
  64. do
  65. mkdir -p $folder
  66. cd $folder
  67. done
  68. ACTIVITY="${folder}Activity"
  69. sed -i -e "s|\"SDLActivity\"|\"$ACTIVITY\"|g" $BUILDPATH/app/src/main/AndroidManifest.xml
  70. # Fill in a default Activity
  71. cat >"$ACTIVITY.java" <<__EOF__
  72. package $APP;
  73. import org.libsdl.app.SDLActivity;
  74. public class $ACTIVITY extends SDLActivity
  75. {
  76. }
  77. __EOF__
  78. # Update project and build
  79. echo "To build and install to a device for testing, run the following:"
  80. echo "cd $BUILDPATH"
  81. echo "./gradlew installDebug"