当前位置:   article > 正文

MAC环境android编译OpenSSL库_musl 编译openssl

musl 编译openssl

MAC环境android编译OpenSSL库 笔记

参照

https://wiki.openssl.org/index.php/Android

https://segmentfault.com/a/1190000005747285


1.需要去下载OpenSSL源文件 下载后解压放到脚本同级目录

2.检查NDK环境变量是否设置

3.运行脚本 运行脚本需要make环境(brew install makedepend


直接运行

chmod a+x build-openssl-android.sh

./build-openssl-android.sh

  1. #!/bin/bash
  2. # Cross-compile environment for Android on ARMv7 and x86
  3. #
  4. # Contents licensed under the terms of the OpenSSL license
  5. # http://www.openssl.org/source/license.html
  6. #
  7. # See http://wiki.openssl.org/index.php/FIPS_Library_and_Android
  8. # and http://wiki.openssl.org/index.php/Android
  9. #####################################################################
  10. # Set NDK_ROOT to you NDK location. For example,
  11. # /opt/android-ndk-r8e or /opt/android-ndk-r9. This can be done in a
  12. # login script. If NDK_ROOT is not specified, the script will
  13. # try to pick it up with the value of _NDK_ROOT below. If
  14. # NDK_ROOT is set, then the value is ignored.
  15. # _ANDROID_NDK="android-ndk-r8e"
  16. _ANDROID_NDK="android-ndk-r10e"
  17. # _ANDROID_NDK="android-ndk-r10"
  18. # Set _ANDROID_EABI to the EABI you want to use. You can find the
  19. # list in $NDK_ROOT/toolchains. This value is always used.
  20. # _ANDROID_EABI="x86-4.6"
  21. # _ANDROID_EABI="arm-linux-androideabi-4.6"
  22. _ANDROID_EABI="arm-linux-androideabi-4.9"
  23. # Set _ANDROID_ARCH to the architecture you are building for.
  24. # This value is always used.
  25. # _ANDROID_ARCH=arch-x86
  26. _ANDROID_ARCH=arch-arm
  27. # Set _ANDROID_API to the API you want to use. You should set it
  28. # to one of: android-14, android-9, android-8, android-14, android-5
  29. # android-4, or android-3. You can't set it to the latest (for
  30. # example, API-17) because the NDK does not supply the platform. At
  31. # Android 5.0, there will likely be another platform added (android-22?).
  32. # This value is always used.
  33. # _ANDROID_API="android-14"
  34. _ANDROID_API="android-18"
  35. # _ANDROID_API="android-19"
  36. #####################################################################
  37. # If the user did not specify the NDK location, try and pick it up.
  38. # We expect something like NDK_ROOT=/opt/android-ndk-r8e
  39. # or NDK_ROOT=/usr/local/android-ndk-r8e.
  40. if [ -z "$NDK_ROOT" ]; then
  41. _NDK_ROOT=""
  42. if [ -z "$_NDK_ROOT" ] && [ -d "/usr/local/$_ANDROID_NDK" ]; then
  43. _NDK_ROOT="/usr/local/$_ANDROID_NDK"
  44. fi
  45. if [ -z "$_NDK_ROOT" ] && [ -d "/opt/$_ANDROID_NDK" ]; then
  46. _NDK_ROOT="/opt/$_ANDROID_NDK"
  47. fi
  48. if [ -z "$_NDK_ROOT" ] && [ -d "$HOME/$_ANDROID_NDK" ]; then
  49. _NDK_ROOT="$HOME/$_ANDROID_NDK"
  50. fi
  51. if [ -z "$_NDK_ROOT" ] && [ -d "$PWD/$_ANDROID_NDK" ]; then
  52. _NDK_ROOT="$PWD/$_ANDROID_NDK"
  53. fi
  54. # If a path was set, then export it
  55. if [ ! -z "$_NDK_ROOT" ] && [ -d "$_NDK_ROOT" ]; then
  56. export NDK_ROOT="$_NDK_ROOT"
  57. fi
  58. fi
  59. # Error checking
  60. # NDK_ROOT should always be set by the user (even when not running this script)
  61. # http://groups.google.com/group/android-ndk/browse_thread/thread/a998e139aca71d77
  62. if [ -z "$NDK_ROOT" ] || [ ! -d "$NDK_ROOT" ]; then
  63. echo "Error: NDK_ROOT is not a valid path. Please edit this script."
  64. # echo "$NDK_ROOT"
  65. # exit 1
  66. fi
  67. # Error checking
  68. if [ ! -d "$NDK_ROOT/toolchains" ]; then
  69. echo "Error: NDK_ROOT/toolchains is not a valid path. Please edit this script."
  70. # echo "$NDK_ROOT/toolchains"
  71. # exit 1
  72. fi
  73. # Error checking
  74. if [ ! -d "$NDK_ROOT/toolchains/$_ANDROID_EABI" ]; then
  75. echo "Error: ANDROID_EABI is not a valid path. Please edit this script."
  76. # echo "$NDK_ROOT/toolchains/$_ANDROID_EABI"
  77. # exit 1
  78. fi
  79. #####################################################################
  80. # Based on NDK_ROOT, try and pick up the required toolchain. We expect something like:
  81. # /opt/android-ndk-r83/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin
  82. # Once we locate the toolchain, we add it to the PATH. Note: this is the 'hard way' of
  83. # doing things according to the NDK documentation for Ice Cream Sandwich.
  84. # https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
  85. ANDROID_TOOLCHAIN=""
  86. for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86"
  87. do
  88. if [ -d "$NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin" ]; then
  89. ANDROID_TOOLCHAIN="$NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin"
  90. break
  91. fi
  92. done
  93. # Error checking
  94. if [ -z "$ANDROID_TOOLCHAIN" ] || [ ! -d "$ANDROID_TOOLCHAIN" ]; then
  95. echo "Error: ANDROID_TOOLCHAIN is not valid. Please edit this script."
  96. # echo "$ANDROID_TOOLCHAIN"
  97. # exit 1
  98. fi
  99. case $_ANDROID_ARCH in
  100. arch-arm)
  101. ANDROID_TOOLS="arm-linux-androideabi-gcc arm-linux-androideabi-ranlib arm-linux-androideabi-ld"
  102. ;;
  103. arch-x86)
  104. ANDROID_TOOLS="i686-linux-android-gcc i686-linux-android-ranlib i686-linux-android-ld"
  105. ;;
  106. *)
  107. echo "ERROR ERROR ERROR"
  108. ;;
  109. esac
  110. for tool in $ANDROID_TOOLS
  111. do
  112. # Error checking
  113. if [ ! -e "$ANDROID_TOOLCHAIN/$tool" ]; then
  114. echo "Error: Failed to find $tool. Please edit this script."
  115. # echo "$ANDROID_TOOLCHAIN/$tool"
  116. # exit 1
  117. fi
  118. done
  119. # Only modify/export PATH if ANDROID_TOOLCHAIN good
  120. if [ ! -z "$ANDROID_TOOLCHAIN" ]; then
  121. export ANDROID_TOOLCHAIN="$ANDROID_TOOLCHAIN"
  122. export PATH="$ANDROID_TOOLCHAIN":"$PATH"
  123. fi
  124. #####################################################################
  125. # For the Android SYSROOT. Can be used on the command line with --sysroot
  126. # https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
  127. export ANDROID_SYSROOT="$NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH"
  128. export CROSS_SYSROOT="$ANDROID_SYSROOT"
  129. export NDK_SYSROOT="$ANDROID_SYSROOT"
  130. # Error checking
  131. if [ -z "$ANDROID_SYSROOT" ] || [ ! -d "$ANDROID_SYSROOT" ]; then
  132. echo "Error: ANDROID_SYSROOT is not valid. Please edit this script."
  133. # echo "$ANDROID_SYSROOT"
  134. # exit 1
  135. fi
  136. #####################################################################
  137. # If the user did not specify the FIPS_SIG location, try and pick it up
  138. # If the user specified a bad location, then try and pick it up too.
  139. if [ -z "$FIPS_SIG" ] || [ ! -e "$FIPS_SIG" ]; then
  140. # Try and locate it
  141. _FIPS_SIG=""
  142. if [ -d "/usr/local/ssl/$_ANDROID_API" ]; then
  143. _FIPS_SIG=`find "/usr/local/ssl/$_ANDROID_API" -name incore`
  144. fi
  145. if [ ! -e "$_FIPS_SIG" ]; then
  146. _FIPS_SIG=`find $PWD -name incore`
  147. fi
  148. # If a path was set, then export it
  149. if [ ! -z "$_FIPS_SIG" ] && [ -e "$_FIPS_SIG" ]; then
  150. export FIPS_SIG="$_FIPS_SIG"
  151. fi
  152. fi
  153. # Error checking. Its OK to ignore this if you are *not* building for FIPS
  154. if [ -z "$FIPS_SIG" ] || [ ! -e "$FIPS_SIG" ]; then
  155. echo "Error: FIPS_SIG does not specify incore module. Please edit this script."
  156. # echo "$FIPS_SIG"
  157. # exit 1
  158. fi
  159. #####################################################################
  160. # Most of these should be OK (MACHINE, SYSTEM, ARCH). RELEASE is ignored.
  161. export MACHINE=armv7
  162. export RELEASE=2.6.37
  163. export SYSTEM=android
  164. export ARCH=arm
  165. export CROSS_COMPILE="arm-linux-androideabi-"
  166. if [ "$_ANDROID_ARCH" == "arch-x86" ]; then
  167. export MACHINE=i686
  168. export RELEASE=2.6.37
  169. export SYSTEM=android
  170. export ARCH=x86
  171. export CROSS_COMPILE="i686-linux-android-"
  172. fi
  173. # For the Android toolchain
  174. # https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
  175. export ANDROID_SYSROOT="$NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH"
  176. export SYSROOT="$ANDROID_SYSROOT"
  177. export NDK_SYSROOT="$ANDROID_SYSROOT"
  178. export ANDROID_NDK_SYSROOT="$ANDROID_SYSROOT"
  179. export ANDROID_API="$_ANDROID_API"
  180. # CROSS_COMPILE and ANDROID_DEV are DFW (Don't Fiddle With). Its used by OpenSSL build system.
  181. # export CROSS_COMPILE="arm-linux-androideabi-"
  182. export ANDROID_DEV="$NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr"
  183. export HOSTCC=gcc
  184. VERBOSE=1
  185. if [ ! -z "$VERBOSE" ] && [ "$VERBOSE" != "0" ]; then
  186. echo "NDK_ROOT: $NDK_ROOT"
  187. echo "ANDROID_ARCH: $_ANDROID_ARCH"
  188. echo "ANDROID_EABI: $_ANDROID_EABI"
  189. echo "ANDROID_API: $ANDROID_API"
  190. echo "ANDROID_SYSROOT: $ANDROID_SYSROOT"
  191. echo "ANDROID_TOOLCHAIN: $ANDROID_TOOLCHAIN"
  192. echo "FIPS_SIG: $FIPS_SIG"
  193. echo "CROSS_COMPILE: $CROSS_COMPILE"
  194. echo "ANDROID_DEV: $ANDROID_DEV"
  195. fi
  196. cd openssl-1.0.2g
  197. make clean
  198. perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
  199. ./config shared no-ssl2 no-ssl3 no-comp no-hw no-engine --openssldir=/usr/local/ssl/$ANDROID_API
  200. make depend
  201. make all
  202. sudo -E make install CC=$ANDROID_TOOLCHAIN/arm-linux-androideabi-gcc RANLIB=$ANDROID_TOOLCHAIN/arm-linux-androideabi-ranlib

在openssl-1.0.2g目录下找到libcrypto.a libssl.a 或者/usr/local/ssl/android-21 去找 代码:


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/198032?site
推荐阅读
相关标签
  

闽ICP备14008679号