android_do 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/bash
  2. #change this to valid ndk path, otherwise it will be downloaded
  3. NDK=/bad/path/to/android-ndk-r11c/
  4. BUILD_PATH=$(pwd)/build_android
  5. #if you have cjdns android app somewhere else then change it
  6. NDK_VERSION="android-ndk-r11c"
  7. case $(uname -s) in
  8. Darwin)
  9. TYPE=darwin
  10. ;;
  11. Linux)
  12. TYPE=linux
  13. ;;
  14. *)
  15. TYPE=
  16. ;;
  17. esac
  18. cpu_arch="$(uname -m)"
  19. [[ -z "$cpu_arch" ]] && {
  20. echo "ERROR: NO CPU ARCHITECTURE DETECTED"
  21. exit 1
  22. }
  23. [[ "$cpu_arch" = "i686" ]] \
  24. && cpu_arch="x86"
  25. android_log=android_build_$$.log
  26. enabled_log=${LOG}
  27. mkdir $BUILD_PATH
  28. if [ "$NDK" == "/bad/path/to/android-ndk-r11c/" ]; then
  29. if [ ! -d $BUILD_PATH/$NDK_VERSION/ ]; then
  30. echo "NDK path is not specified. Downloading it..."
  31. NDK=$BUILD_PATH/$NDK_VERSION/
  32. ##SETUP NDK
  33. cd "$BUILD_PATH"
  34. if [ ! -d "$NDK" ]; then
  35. echo "$NDK_VERSION-${TYPE}-${cpu_arch}.tar.bz2"
  36. [[ -f "$NDK_VERSION-${TYPE}-${cpu_arch}.tar.bz2" ]] \
  37. || wget "https://dl.google.com/android/repository/$NDK_VERSION-${TYPE}-${cpu_arch}.zip" \
  38. || (echo "Can't find download for your system"; exit 1)
  39. [[ -d "$NDK_VERSION" ]] || (unzip -q "$NDK_VERSION-${TYPE}-${cpu_arch}.zip" || exit 1)
  40. fi
  41. [[ ! -d "$NDK" ]] && {
  42. echo "The NDK variable is not pointing to a valid directory"
  43. exit 1
  44. }
  45. cd ..
  46. else
  47. NDK=$BUILD_PATH/$NDK_VERSION/
  48. fi
  49. fi
  50. Seccomp_NO=1
  51. mkdir $(pwd)/build_android/out
  52. declare -a APP_ABI=("armeabi-v7a" "arm64-v8a" "x86")
  53. declare -a APP_ABI2=("arm" "aarch64" "i686")
  54. declare -a TARGET_ARCH=("arm" "aarch64" "x64")
  55. declare -a EABI=("androideabi" "android" "android")
  56. declare -a PLATFORM=(16 21 16)
  57. declare -a TOOLCHAIN=("arm-linux-androideabi-4.9" "aarch64-linux-android-4.9" "x86-4.9")
  58. for i in {0..2}
  59. do
  60. GCC=$BUILD_PATH/${APP_ABI2[$i]}-${TYPE}-${EABI[$i]}/bin/${APP_ABI2[$i]}-linux-${EABI[$i]}-gcc
  61. [[ ! -x "$GCC" ]] && {
  62. $NDK/build/tools/make-standalone-toolchain.sh --platform=android-${PLATFORM[$i]} --toolchain=${TOOLCHAIN[$i]} --install-dir=$BUILD_PATH/${APP_ABI2[$i]}-${TYPE}-${EABI[$i]}/ \
  63. || exit 1
  64. }
  65. mkdir $(pwd)/build_android/out/${APP_ABI[$i]}
  66. rm -rf build_linux
  67. export PLATFORM=android
  68. export SYSTEM=linux
  69. export CROSS_COMPILE=$BUILD_PATH/${APP_ABI2[$i]}-${TYPE}-${EABI[$i]}/bin/${APP_ABI2[$i]}-linux-${EABI[$i]}-
  70. export CROSS=${CROSS_COMPILE}
  71. export CC=${CROSS}gcc
  72. export AR=${CROSS}ar
  73. export RANLIB=${CROSS}ranlib
  74. export CFLAGS=${CROSS_CFLAGS}
  75. export LDFLAGS=${CROSS_LDFLAGS}
  76. gcc_version=$(${CC} --version)
  77. echo Using $gcc_version
  78. echo Compiler CC: $CC
  79. echo Compiler CFLAGS: $CFLAGS
  80. echo Compiler LDFLAGS: $LDFLAGS
  81. time ./do
  82. cp cjdroute $(pwd)/build_android/out/${APP_ABI[$i]}/ || ret=$?
  83. if [ "$ret" != "" ] && [ "$ret" != "0" ]; then
  84. echo -e "\e[1;31mCopying ${APP_ABI[$i]} binary failed, non zero status returned - $ret\e[0m"
  85. exit 1
  86. else
  87. echo -e "\e[1;32mCopied ${APP_ABI[$i]} successfully\e[0m"
  88. fi
  89. rm cjdroute
  90. done
  91. echo -e "\n\e[1;34mOutput:\e[0m"
  92. for i in {0..2}
  93. do
  94. echo -e "\e[1;34m $(pwd)/build_android/out/${APP_ABI[$i]}/cjdroute\e[0m"
  95. done
  96. exit $ret