android_do 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/bin/sh
  2. # Fedora
  3. # dnf install wget git make which patch findutils unzip
  4. # Ubuntu
  5. # apt install wget git build-essential unzip time python
  6. # ./android_do
  7. die() { echo "Error: $1"; exit 1; }
  8. need() { which "$1" >/dev/null 2>/dev/null || die "Missing $1"; }
  9. need which
  10. need wget
  11. need git
  12. need make
  13. need patch
  14. need find
  15. need unzip
  16. need ls
  17. need uname
  18. need pwd
  19. need mkdir
  20. need rm
  21. need time
  22. #change this to valid ndk path, otherwise it will be downloaded
  23. BUILD_PATH=$(pwd)/build_android
  24. NDK_VERSION="android-ndk-r21"
  25. case $(uname -s) in
  26. Darwin)
  27. TYPE=darwin
  28. ;;
  29. Linux)
  30. TYPE=linux
  31. ;;
  32. *)
  33. TYPE=
  34. ;;
  35. esac
  36. if test "x$CJDNS_NDK_PATH" != "x"; then
  37. false # we already have an ndk path...
  38. elif test "x$TYPE" = xdarwin; then
  39. CJDNS_NDK_PATH_HINT=`echo $HOME/Library/Android/sdk/ndk/* | tail -1`
  40. elif test "x$TYPE" = xlinux; then
  41. CJDNS_NDK_PATH_HINT=`echo $HOME/Android/Sdk/ndk/* | tail -1`
  42. fi
  43. if test "x$CJDNS_NDK_PATH" = "x"; then
  44. if test "x$CJDNS_NDK_PATH_HINT" != "x" && [ -d "$CJDNS_NDK_PATH_HINT" ]; then
  45. echo "Using NDK at path $CJDNS_NDK_PATH_HINT"
  46. CJDNS_NDK_PATH=$CJDNS_NDK_PATH_HINT
  47. elif [ -d "$BUILD_PATH/$NDK_VERSION/" ]; then
  48. CJDNS_NDK_PATH="$BUILD_PATH/$NDK_VERSION"
  49. echo "Using previously downloaded NDK $CJDNS_NDK_PATH"
  50. else
  51. echo "No NDK path known, NDK will be downloaded"
  52. fi
  53. elif [ -d "$CJDNS_NDK_PATH" ]; then
  54. echo "Using NDK at specified path $CJDNS_NDK_PATH"
  55. else
  56. die "NDK path $CJDNS_NDK_PATH is not a directory"
  57. fi
  58. cpu_arch="$(uname -m)"
  59. [ -z "$cpu_arch" ] && die "NO CPU ARCHITECTURE DETECTED"
  60. [ "$cpu_arch" = "i686" ] && cpu_arch="x86"
  61. android_log=android_build_$$.log
  62. enabled_log=${LOG}
  63. mkdir $BUILD_PATH 2>/dev/null
  64. if test "x$CJDNS_NDK_PATH" = "x"; then
  65. cd "$BUILD_PATH"
  66. filename="$NDK_VERSION-${TYPE}-${cpu_arch}.zip"
  67. echo "$filename"
  68. if ! [ -f "$filename" ]; then
  69. url="https://dl.google.com/android/repository/$NDK_VERSION-${TYPE}-${cpu_arch}.zip"
  70. wget "$url" || die "wget $url failed"
  71. fi
  72. if ! [ -d "$NDK_VERSION" ]; then
  73. unzip -q "$filename" || die "failed to unzip "
  74. fi
  75. CJDNS_NDK_PATH="$BUILD_PATH/$NDK_VERSION"
  76. [ -d "$CJDNS_NDK_PATH" ] || die "NDK zip file does not contain expected content"
  77. cd ..
  78. fi
  79. Seccomp_NO=1
  80. mkdir $(pwd)/build_android/out 2>/dev/null
  81. BUILD_0='
  82. APP_ABI=armv7a
  83. TOOLCHAIN_PREFIX=arm
  84. EABI=androideabi
  85. VERSION=16
  86. '
  87. BUILD_1='
  88. APP_ABI=aarch64
  89. VERSION=21
  90. '
  91. BUILD_2='
  92. APP_ABI=i686
  93. VERSION=16
  94. '
  95. BUILD_3='
  96. APP_ABI=x86_64
  97. VERSION=21
  98. '
  99. for i in `seq 0 100`; do
  100. BUILD=`eval echo "\\\$BUILD_$i"`
  101. if test "x$BUILD" = "x"; then
  102. continue
  103. fi
  104. export APP_ABI=
  105. export TOOLCHAIN_PREFIX=
  106. export EABI=
  107. export VERSION=
  108. export EABI=android
  109. export $BUILD
  110. if test "x$TOOLCHAIN_PREFIX" = "x"; then
  111. export TOOLCHAIN_PREFIX=$APP_ABI
  112. fi
  113. mkdir -p $(pwd)/build_android/out/${APP_ABI}/${VERSION}/
  114. rm -rf build_linux
  115. export SYSTEM=linux
  116. CROSS_PATH=$CJDNS_NDK_PATH/toolchains/llvm/prebuilt/${TYPE}-${cpu_arch}/bin
  117. export CC=${CROSS_PATH}/${APP_ABI}-linux-${EABI}${VERSION}-clang
  118. export CROSS=${CROSS_PATH}/${TOOLCHAIN_PREFIX}-linux-${EABI}
  119. export AR=${CROSS}-ar
  120. export LINK=${CROSS}-ld
  121. export RANLIB=${CROSS}-ranlib
  122. export CFLAGS=${CROSS_CFLAGS}
  123. export LDFLAGS=${CROSS_LDFLAGS}
  124. gcc_version=$(${CC} --version)
  125. echo Using $gcc_version
  126. echo Compiler CC: $CC
  127. echo Compiler LINK: $LINK
  128. echo Compiler CFLAGS: $CFLAGS
  129. echo Compiler LDFLAGS: $LDFLAGS
  130. time ./do
  131. cp cjdroute $(pwd)/build_android/out/${APP_ABI}/${VERSION}/ || ret=$?
  132. if [ "$ret" != "" ] && [ "$ret" != "0" ]; then
  133. printf "\e[1;31mCopying ${APP_ABI} binary failed, non zero status returned - $ret\e[0m\n"
  134. exit 1
  135. else
  136. printf "\e[1;32mCopied ${APP_ABI} successfully\e[0m\n\n"
  137. fi
  138. rm cjdroute 2>/dev/null
  139. done
  140. printf "\n\e[1;34mOutput:\e[0m\n"
  141. for i in `seq 0 100`; do
  142. BUILD=`eval echo "\\\$BUILD_$i"`
  143. if test "x$BUILD" = "x"; then
  144. continue
  145. fi
  146. export $BUILD
  147. printf "\e[1;34m $(pwd)/build_android/out/${APP_ABI}/${VERSION}/cjdroute\e[0m\n"
  148. done
  149. exit $ret