android_do 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/bin/bash
  2. #change this to valid ndk path, otherwise it will be downloaded
  3. NDK=/bad/path/to/android-ndk-r10e/
  4. BUILD_PATH=$(pwd)/build_android
  5. #if you have cjdns android app somewhere else then change it
  6. NDK_VERSION="android-ndk-r10e"
  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-r10e/" ]; 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 "http://dl.google.com/android/ndk/$NDK_VERSION-${TYPE}-${cpu_arch}.bin" \
  38. || (echo "Can't find download for your system"; exit 1)
  39. [[ -d "$NDK_VERSION" ]] || (chmod a+x "$NDK_VERSION-${TYPE}-${cpu_arch}.bin"; "./$NDK_VERSION-${TYPE}-${cpu_arch}.bin" || 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. $NDK/build/tools/make-standalone-toolchain.sh --platform=android-21 --toolchain=arm-linux-androideabi-4.9 --install-dir=$BUILD_PATH/arm-${TYPE}-androideabi/ --system=${TYPE}-${cpu_arch}
  51. $NDK/build/tools/make-standalone-toolchain.sh --platform=android-21 --toolchain=x86-4.9 --install-dir=$BUILD_PATH/i686-${TYPE}-androideabi/ --system=${TYPE}-${cpu_arch}
  52. Seccomp_NO=1
  53. mkdir $(pwd)/android_out
  54. mkdir $(pwd)/android_out/armeabi-v7a
  55. mkdir $(pwd)/android_out/x86
  56. #arm build
  57. rm -rf build_linux
  58. export SYSTEM=linux
  59. export CROSS_COMPILE=$BUILD_PATH/arm-${TYPE}-androideabi/bin/arm-linux-androideabi-
  60. export TARGET_ARCH=arm
  61. export CROSS=${CROSS_COMPILE}
  62. export CC=${CROSS}gcc
  63. export AR=${CROSS}ar
  64. export RANLIB=${CROSS}ranlib
  65. export CFLAGS=${CROSS_CFLAGS}
  66. export LDFLAGS=${CROSS_LDFLAGS}
  67. gcc_version=$(${CC} --version)
  68. echo Using $gcc_version
  69. echo Compiler CC: $CC
  70. echo Compiler CFLAGS: $CFLAGS
  71. echo Compiler LDFLAGS: $LDFLAGS
  72. time ./do
  73. cp cjdroute $(pwd)/android_out/armeabi-v7a/ || ret=$?
  74. if [ "$ret" != "" ] && [ "$ret" != "0" ]; then
  75. echo -e "\e[1;31mCopying armeabi-v7a binary failed, non zero status returned - $ret\e[0m"
  76. else
  77. echo -e "\e[1;32mCopied armeabi-v7a successfully\e[0m"
  78. fi
  79. rm cjdroute
  80. #x86 build
  81. rm -rf build_linux
  82. export CROSS_COMPILE=$BUILD_PATH/i686-${TYPE}-androideabi/bin/i686-linux-android-
  83. export TARGET_ARCH=x64
  84. export CROSS=${CROSS_COMPILE}
  85. export CC=${CROSS}gcc
  86. export AR=${CROSS}ar
  87. export RANLIB=${CROSS}ranlib
  88. export CFLAGS=${CROSS_CFLAGS}
  89. export LDFLAGS=${CROSS_LDFLAGS}
  90. gcc_version=$(${CC} --version)
  91. echo Using $gcc_version
  92. echo Compiler CC: $CC
  93. echo Compiler CFLAGS: $CFLAGS
  94. echo Compiler LDFLAGS: $LDFLAGS
  95. time ./do
  96. cp cjdroute $(pwd)/android_out/x86/ || ret=$?
  97. if [ "$ret" != "" ] && [ "$ret" != "0" ]; then
  98. echo -e "\e[1;31mCopying x86 binary failed, non zero status returned - $ret\e[0m"
  99. else
  100. echo -e "\e[1;32mCopied x86 successfully\e[0m"
  101. fi
  102. rm cjdroute
  103. echo -e "\n\e[1;34mOutput: $(pwd)/android_out/armeabi-v7a/cjdroute\e[0m"
  104. echo -e "\e[1;34m $(pwd)/android_out/x86/cjdroute\e[0m"
  105. exit $ret