(OK) 在CentOS7—编译OpenSSL 静态库—for—Android


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

下载makedepend.zip , 从http://llg.cubic.org/docs/vc7.html下载。 解压编译,然后 cp makedepend /bin/
下载Setenv-android.sh , wget https://wiki.openssl.org/images/7/70/Setenv-android.sh

[root@localhost openssl-1.0.1p]# gedit Setenv-android.sh        //关键设置如下:
#-------------------------------------------------------
ANDROID_NDK_ROOT="/opt/android-on-linux/android-ndk-r8e"
_ANDROID_NDK="android-ndk-r8e"
_ANDROID_EABI="arm-linux-androideabi-4.7"
_ANDROID_API="android-14"

export MACHINE=armv7
export RELEASE=2.6.37
export SYSTEM=android
export ARCH=arm
#export CROSS_COMPILE="arm-linux-androideabi-"
export CROSS_COMPILE=""
#-------------------------------------------------------

[root@localhost openssl-1.0.1p]# pwd
/opt/cBPM-android/nginx-on-android/openssl-1.0.1p

chmod a+x Setenv-android.sh
perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
./config shared no-ssl2 no-ssl3 no-comp no-hw no-engine --openssldir=/usr/local/ssl/android-14/
make depend
make all

find . -name "*.a"
find . -name libcrypto.a
find . -name libssl.a

readelf -h ./libcrypto.a | grep -i 'class\|machine' | head -2

cp libssl.a libcrypto.a /opt/cBPM-android/criteria-lin/lib


+++++++++++++++++++++++++++++++++++++++++++++
# gedit Setenv-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. ANDROID_NDK_ROOT="/opt/android-on-linux/android-ndk-r8e"

  11. # Set ANDROID_NDK_ROOT to you NDK location. For example,
  12. # /opt/android-ndk-r8e or /opt/android-ndk-r9. This can be done in a
  13. # login script. If ANDROID_NDK_ROOT is not specified, the script will
  14. # try to pick it up with the value of _ANDROID_NDK_ROOT below. If
  15. # ANDROID_NDK_ROOT is set, then the value is ignored.
  16.  _ANDROID_NDK="android-ndk-r8e"
  17. #_ANDROID_NDK="android-ndk-r9"
  18. # _ANDROID_NDK="android-ndk-r10"

  19. # Set _ANDROID_EABI to the EABI you want to use. You can find the
  20. # list in $ANDROID_NDK_ROOT/toolchains. This value is always used.
  21. # _ANDROID_EABI="x86-4.6"
  22. # _ANDROID_EABI="arm-linux-androideabi-4.6"
  23. _ANDROID_EABI="arm-linux-androideabi-4.7"

  24. # Set _ANDROID_ARCH to the architecture you are building for.
  25. # This value is always used.
  26. # _ANDROID_ARCH=arch-x86
  27. _ANDROID_ARCH=arch-arm

  28. # Set _ANDROID_API to the API you want to use. You should set it
  29. # to one of: android-14, android-9, android-8, android-14, android-5
  30. # android-4, or android-3. You can't set it to the latest (for
  31. # example, API-17) because the NDK does not supply the platform. At
  32. # Android 5.0, there will likely be another platform added (android-22?).
  33. # This value is always used.
  34.  _ANDROID_API="android-14"
  35. #_ANDROID_API="android-18"
  36. # _ANDROID_API="android-19"

  37. #####################################################################

  38. # If the user did not specify the NDK location, try and pick it up.
  39. # We expect something like ANDROID_NDK_ROOT=/opt/android-ndk-r8e
  40. # or ANDROID_NDK_ROOT=/usr/local/android-ndk-r8e.

  41. if [ -z "$ANDROID_NDK_ROOT" ]; then

  42.   _ANDROID_NDK_ROOT=""
  43.   if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "/usr/local/$_ANDROID_NDK" ]; then
  44.     _ANDROID_NDK_ROOT="/usr/local/$_ANDROID_NDK"
  45.   fi

  46.   if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "/opt/$_ANDROID_NDK" ]; then
  47.     _ANDROID_NDK_ROOT="/opt/$_ANDROID_NDK"
  48.   fi

  49.   if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "$HOME/$_ANDROID_NDK" ]; then
  50.     _ANDROID_NDK_ROOT="$HOME/$_ANDROID_NDK"
  51.   fi

  52.   if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "$PWD/$_ANDROID_NDK" ]; then
  53.     _ANDROID_NDK_ROOT="$PWD/$_ANDROID_NDK"
  54.   fi

  55.   # If a path was set, then export it
  56.   if [ ! -z "$_ANDROID_NDK_ROOT" ] && [ -d "$_ANDROID_NDK_ROOT" ]; then
  57.     export ANDROID_NDK_ROOT="$_ANDROID_NDK_ROOT"
  58.   fi
  59. fi

  60. # Error checking
  61. # ANDROID_NDK_ROOT should always be set by the user (even when not running this script)
  62. # http://groups.google.com/group/android-ndk/browse_thread/thread/a998e139aca71d77
  63. if [ -z "$ANDROID_NDK_ROOT" ] || [ ! -d "$ANDROID_NDK_ROOT" ]; then
  64.   echo "Error: ANDROID_NDK_ROOT is not a valid path. Please edit this script."
  65.   # echo "$ANDROID_NDK_ROOT"
  66.   # exit 1
  67. fi

  68. # Error checking
  69. if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; then
  70.   echo "Error: ANDROID_NDK_ROOT/toolchains is not a valid path. Please edit this script."
  71.   # echo "$ANDROID_NDK_ROOT/toolchains"
  72.   # exit 1
  73. fi

  74. # Error checking
  75. if [ ! -d "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI" ]; then
  76.   echo "Error: ANDROID_EABI is not a valid path. Please edit this script."
  77.   # echo "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI"
  78.   # exit 1
  79. fi

  80. #####################################################################

  81. # Based on ANDROID_NDK_ROOT, try and pick up the required toolchain. We expect something like:
  82. # /opt/android-ndk-r83/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin
  83. # Once we locate the toolchain, we add it to the PATH. Note: this is the 'hard way' of
  84. # doing things according to the NDK documentation for Ice Cream Sandwich.
  85. # https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html

  86. ANDROID_TOOLCHAIN=""
  87. for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86"
  88. do
  89.   if [ -d "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin" ]; then
  90.     ANDROID_TOOLCHAIN="$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin"
  91.     break
  92.   fi
  93. done

  94. # Error checking
  95. if [ -z "$ANDROID_TOOLCHAIN" ] || [ ! -d "$ANDROID_TOOLCHAIN" ]; then
  96.   echo "Error: ANDROID_TOOLCHAIN is not valid. Please edit this script."
  97.   # echo "$ANDROID_TOOLCHAIN"
  98.   # exit 1
  99. fi

  100. case $_ANDROID_ARCH in
  101.     arch-arm)    
  102.       ANDROID_TOOLS="arm-linux-androideabi-gcc arm-linux-androideabi-ranlib arm-linux-androideabi-ld"
  103.      ;;
  104.     arch-x86)    
  105.       ANDROID_TOOLS="i686-linux-android-gcc i686-linux-android-ranlib i686-linux-android-ld"
  106.      ;;    
  107.     *)
  108.      echo "ERROR ERROR ERROR"
  109.      ;;
  110. esac

  111. for tool in $ANDROID_TOOLS
  112. do
  113.   # Error checking
  114.   if [ ! -e "$ANDROID_TOOLCHAIN/$tool" ]; then
  115.     echo "Error: Failed to find $tool. Please edit this script."
  116.     # echo "$ANDROID_TOOLCHAIN/$tool"
  117.     # exit 1
  118.   fi
  119. done

  120. # Only modify/export PATH if ANDROID_TOOLCHAIN good
  121. if [ ! -z "$ANDROID_TOOLCHAIN" ]; then
  122.   export ANDROID_TOOLCHAIN="$ANDROID_TOOLCHAIN"
  123.   export PATH="$ANDROID_TOOLCHAIN":"$PATH"
  124. fi

  125. #####################################################################

  126. # For the Android SYSROOT. Can be used on the command line with --sysroot
  127. # https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
  128. export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH"
  129. export SYSROOT="$ANDROID_SYSROOT"
  130. export NDK_SYSROOT="$ANDROID_SYSROOT"

  131. # Error checking
  132. if [ -z "$ANDROID_SYSROOT" ] || [ ! -d "$ANDROID_SYSROOT" ]; then
  133.   echo "Error: ANDROID_SYSROOT is not valid. Please edit this script."
  134.   # echo "$ANDROID_SYSROOT"
  135.   # exit 1
  136. fi

  137. #####################################################################

  138. # If the user did not specify the FIPS_SIG location, try and pick it up
  139. # If the user specified a bad location, then try and pick it up too.
  140. if [ -z "$FIPS_SIG" ] || [ ! -e "$FIPS_SIG" ]; then

  141.   # Try and locate it
  142.   _FIPS_SIG=""
  143.   if [ -d "/usr/local/ssl/$_ANDROID_API" ]; then
  144.     _FIPS_SIG=`find "/usr/local/ssl/$_ANDROID_API" -name incore`
  145.   fi

  146.   if [ ! -e "$_FIPS_SIG" ]; then
  147.     _FIPS_SIG=`find $PWD -name incore`
  148.   fi

  149.   # If a path was set, then export it
  150.   if [ ! -z "$_FIPS_SIG" ] && [ -e "$_FIPS_SIG" ]; then
  151.     export FIPS_SIG="$_FIPS_SIG"
  152.   fi
  153. fi

  154. # Error checking. Its OK to ignore this if you are *not* building for FIPS
  155. if [ -z "$FIPS_SIG" ] || [ ! -e "$FIPS_SIG" ]; then
  156.   echo "Error: FIPS_SIG does not specify incore module. Please edit this script."
  157.   # echo "$FIPS_SIG"
  158.   # exit 1
  159. fi

  160. #####################################################################

  161. # Most of these should be OK (MACHINE, SYSTEM, ARCH). RELEASE is ignored.
  162. export MACHINE=armv7
  163. export RELEASE=2.6.37
  164. export SYSTEM=android
  165. export ARCH=arm
  166. #export CROSS_COMPILE="arm-linux-androideabi-"
  167. export CROSS_COMPILE=""

  168. if [ "$_ANDROID_ARCH" == "arch-x86" ]; then
  169.     export MACHINE=i686
  170.     export RELEASE=2.6.37
  171.     export SYSTEM=android
  172.     export ARCH=x86
  173.     export CROSS_COMPILE="i686-linux-android-"
  174. fi

  175. # For the Android toolchain
  176. # https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
  177. export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH"
  178. export SYSROOT="$ANDROID_SYSROOT"
  179. export NDK_SYSROOT="$ANDROID_SYSROOT"
  180. export ANDROID_NDK_SYSROOT="$ANDROID_SYSROOT"
  181. export ANDROID_API="$_ANDROID_API"

  182. # CROSS_COMPILE and ANDROID_DEV are DFW (Don't Fiddle With). Its used by OpenSSL build system.
  183. # export CROSS_COMPILE="arm-linux-androideabi-"
  184. export ANDROID_DEV="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr"
  185. export HOSTCC=gcc

  186. VERBOSE=1
  187. if [ ! -z "$VERBOSE" ] && [ "$VERBOSE" != "0" ]; then
  188.   echo "ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT"
  189.   echo "ANDROID_ARCH: $_ANDROID_ARCH"
  190.   echo "ANDROID_EABI: $_ANDROID_EABI"
  191.   echo "ANDROID_API: $ANDROID_API"
  192.   echo "ANDROID_SYSROOT: $ANDROID_SYSROOT"
  193.   echo "ANDROID_TOOLCHAIN: $ANDROID_TOOLCHAIN"
  194.   echo "FIPS_SIG: $FIPS_SIG"
  195.   echo "CROSS_COMPILE: $CROSS_COMPILE"
  196.   echo "ANDROID_DEV: $ANDROID_DEV"
  197. fi





<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(106) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
posted @ 2016-02-01 00:00  张同光  阅读(138)  评论(0编辑  收藏  举报