mkssl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/sh
  2. while getopts n:o:a:t:d:h: option
  3. do
  4. case "${option}"
  5. in
  6. n) ANDROID_NDK=${OPTARG};;
  7. o) OPENSSL_VERSION=${OPTARG};;
  8. a) API_LEVEL=${OPTARG};;
  9. t) BUILD_TARGETS=${OPTARG};;
  10. d) OUT_DIR=${OPTARG};;
  11. h) HOST_TAG=${OPTARG};;
  12. *) twentytwo=${OPTARG};;
  13. esac
  14. done
  15. BUILD_DIR=/tmp/openssl_android_build
  16. if [ ! -d openssl-${OPENSSL_VERSION} ]
  17. then
  18. if [ ! -f openssl-${OPENSSL_VERSION}.tar.gz ]
  19. then
  20. wget https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz || exit 128
  21. fi
  22. tar xzf openssl-${OPENSSL_VERSION}.tar.gz || exit 128
  23. fi
  24. cd openssl-${OPENSSL_VERSION} || exit 128
  25. ##### export ndk directory. Required by openssl-build-scripts #####
  26. case ${OPENSSL_VERSION} in
  27. 1.1.1*)
  28. export ANDROID_NDK_HOME=$ANDROID_NDK
  29. ;;
  30. *)
  31. export ANDROID_NDK_ROOT=$ANDROID_NDK
  32. ;;
  33. esac
  34. export PATH=$ANDROID_NDK/toolchains/llvm/prebuilt/$HOST_TAG/bin:$PATH
  35. ##### build-function #####
  36. build_the_thing() {
  37. make clean
  38. ./Configure $SSL_TARGET -D__ANDROID_API__=$API_LEVEL && \
  39. make SHLIB_EXT=.so && \
  40. make install SHLIB_EXT=.so DESTDIR=$DESTDIR || exit 128
  41. }
  42. ##### set variables according to build-tagret #####
  43. for build_target in $BUILD_TARGETS
  44. do
  45. case $build_target in
  46. armeabi-v7a)
  47. DESTDIR="$BUILD_DIR/armeabi-v7a"
  48. SSL_TARGET="android-arm"
  49. ;;
  50. x86)
  51. DESTDIR="$BUILD_DIR/x86"
  52. SSL_TARGET="android-x86"
  53. ;;
  54. x86_64)
  55. DESTDIR="$BUILD_DIR/x86_64"
  56. SSL_TARGET="android-x86_64"
  57. ;;
  58. arm64-v8a)
  59. DESTDIR="$BUILD_DIR/arm64-v8a"
  60. SSL_TARGET="android-arm64"
  61. ;;
  62. esac
  63. rm -rf $DESTDIR
  64. build_the_thing
  65. #### copy libraries and includes to output-directory #####
  66. mkdir -p $OUT_DIR/$build_target/include
  67. cp -R $DESTDIR/usr/local/include/* $OUT_DIR/$build_target/include
  68. cp -R $DESTDIR/usr/local/ssl/* $OUT_DIR/$build_target/
  69. mkdir -p $OUT_DIR/$build_target/lib
  70. cp -R $DESTDIR/usr/local/lib/*.so $OUT_DIR/$build_target/lib
  71. cp -R $DESTDIR/usr/local/lib/*.a $OUT_DIR/$build_target/lib
  72. done
  73. echo Success