do-compile-openssl.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #! /usr/bin/env bash
  2. #
  3. # Copyright (C) 2013-2014 Bilibili
  4. # Copyright (C) 2013-2014 Zhang Rui <bbcallen@gmail.com>
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. # This script is based on projects below
  19. # https://github.com/x2on/OpenSSL-for-iPhone
  20. #--------------------
  21. echo "===================="
  22. echo "[*] check host"
  23. echo "===================="
  24. set -e
  25. FF_XCRUN_DEVELOPER=`xcode-select -print-path`
  26. if [ ! -d "$FF_XCRUN_DEVELOPER" ]; then
  27. echo "xcode path is not set correctly $FF_XCRUN_DEVELOPER does not exist (most likely because of xcode > 4.3)"
  28. echo "run"
  29. echo "sudo xcode-select -switch <xcode path>"
  30. echo "for default installation:"
  31. echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer"
  32. exit 1
  33. fi
  34. case $FF_XCRUN_DEVELOPER in
  35. *\ * )
  36. echo "Your Xcode path contains whitespaces, which is not supported."
  37. exit 1
  38. ;;
  39. esac
  40. #--------------------
  41. # include
  42. #--------------------
  43. # common defines
  44. FF_ARCH=$1
  45. if [ -z "$FF_ARCH" ]; then
  46. echo "You must specific an architecture 'armv7, armv7s, arm64, i386, x86_64, ...'.\n"
  47. exit 1
  48. fi
  49. FF_BUILD_ROOT=`pwd`
  50. FF_TAGET_OS="darwin"
  51. # openssl build params
  52. export COMMON_FF_CFG_FLAGS=
  53. OPENSSL_CFG_FLAGS=
  54. OPENSSL_EXTRA_CFLAGS=
  55. OPENSSL_CFG_CPU=
  56. # i386, x86_64
  57. OPENSSL_CFG_FLAGS_SIMULATOR=
  58. # armv7, armv7s, arm64
  59. OPENSSL_CFG_FLAGS_ARM=
  60. OPENSSL_CFG_FLAGS_ARM="iphoneos-cross"
  61. echo "build_root: $FF_BUILD_ROOT"
  62. #--------------------
  63. echo "===================="
  64. echo "[*] config arch $FF_ARCH"
  65. echo "===================="
  66. FF_BUILD_NAME="unknown"
  67. FF_XCRUN_PLATFORM="iPhoneOS"
  68. FF_XCRUN_OSVERSION=
  69. FF_GASPP_EXPORT=
  70. FF_XCODE_BITCODE=
  71. if [ "$FF_ARCH" = "i386" ]; then
  72. FF_BUILD_NAME="openssl-i386"
  73. FF_XCRUN_PLATFORM="iPhoneSimulator"
  74. FF_XCRUN_OSVERSION="-mios-simulator-version-min=6.0"
  75. OPENSSL_CFG_FLAGS="darwin-i386-cc $OPENSSL_CFG_FLAGS"
  76. elif [ "$FF_ARCH" = "x86_64" ]; then
  77. FF_BUILD_NAME="openssl-x86_64"
  78. FF_XCRUN_PLATFORM="iPhoneSimulator"
  79. FF_XCRUN_OSVERSION="-mios-simulator-version-min=7.0"
  80. OPENSSL_CFG_FLAGS="darwin64-x86_64-cc $OPENSSL_CFG_FLAGS"
  81. elif [ "$FF_ARCH" = "armv7" ]; then
  82. FF_BUILD_NAME="openssl-armv7"
  83. FF_XCRUN_OSVERSION="-miphoneos-version-min=6.0"
  84. FF_XCODE_BITCODE="-fembed-bitcode"
  85. OPENSSL_CFG_FLAGS="$OPENSSL_CFG_FLAGS_ARM $OPENSSL_CFG_FLAGS"
  86. # OPENSSL_CFG_CPU="--cpu=cortex-a8"
  87. elif [ "$FF_ARCH" = "armv7s" ]; then
  88. FF_BUILD_NAME="openssl-armv7s"
  89. OPENSSL_CFG_CPU="--cpu=swift"
  90. FF_XCRUN_OSVERSION="-miphoneos-version-min=6.0"
  91. FF_XCODE_BITCODE="-fembed-bitcode"
  92. OPENSSL_CFG_FLAGS="$OPENSSL_CFG_FLAGS_ARM $OPENSSL_CFG_FLAGS"
  93. elif [ "$FF_ARCH" = "arm64" ]; then
  94. FF_BUILD_NAME="openssl-arm64"
  95. FF_XCRUN_OSVERSION="-miphoneos-version-min=7.0"
  96. FF_XCODE_BITCODE="-fembed-bitcode"
  97. OPENSSL_CFG_FLAGS="$OPENSSL_CFG_FLAGS_ARM $OPENSSL_CFG_FLAGS"
  98. FF_GASPP_EXPORT="GASPP_FIX_XCODE5=1"
  99. else
  100. echo "unknown architecture $FF_ARCH";
  101. exit 1
  102. fi
  103. echo "build_name: $FF_BUILD_NAME"
  104. echo "platform: $FF_XCRUN_PLATFORM"
  105. echo "osversion: $FF_XCRUN_OSVERSION"
  106. #--------------------
  107. echo "===================="
  108. echo "[*] make ios toolchain $FF_BUILD_NAME"
  109. echo "===================="
  110. FF_BUILD_SOURCE="$FF_BUILD_ROOT/$FF_BUILD_NAME"
  111. FF_BUILD_PREFIX="$FF_BUILD_ROOT/build/$FF_BUILD_NAME/output"
  112. mkdir -p $FF_BUILD_PREFIX
  113. FF_XCRUN_SDK=`echo $FF_XCRUN_PLATFORM | tr '[:upper:]' '[:lower:]'`
  114. FF_XCRUN_SDK_PLATFORM_PATH=`xcrun -sdk $FF_XCRUN_SDK --show-sdk-platform-path`
  115. FF_XCRUN_SDK_PATH=`xcrun -sdk $FF_XCRUN_SDK --show-sdk-path`
  116. FF_XCRUN_CC="xcrun -sdk $FF_XCRUN_SDK clang"
  117. export CROSS_TOP="$FF_XCRUN_SDK_PLATFORM_PATH/Developer"
  118. export CROSS_SDK=`echo ${FF_XCRUN_SDK_PATH/#$CROSS_TOP\/SDKs\//}`
  119. export BUILD_TOOL="$FF_XCRUN_DEVELOPER"
  120. export CC="$FF_XCRUN_CC -arch $FF_ARCH $FF_XCRUN_OSVERSION"
  121. echo "build_source: $FF_BUILD_SOURCE"
  122. echo "build_prefix: $FF_BUILD_PREFIX"
  123. echo "CROSS_TOP: $CROSS_TOP"
  124. echo "CROSS_SDK: $CROSS_SDK"
  125. echo "BUILD_TOOL: $BUILD_TOOL"
  126. echo "CC: $CC"
  127. #--------------------
  128. echo "\n--------------------"
  129. echo "[*] configurate openssl"
  130. echo "--------------------"
  131. OPENSSL_CFG_FLAGS="$OPENSSL_CFG_FLAGS $FF_XCODE_BITCODE"
  132. OPENSSL_CFG_FLAGS="$OPENSSL_CFG_FLAGS --openssldir=$FF_BUILD_PREFIX"
  133. # xcode configuration
  134. export DEBUG_INFORMATION_FORMAT=dwarf-with-dsym
  135. cd $FF_BUILD_SOURCE
  136. if [ -f "./Makefile" ]; then
  137. echo 'reuse configure'
  138. else
  139. echo "config: $OPENSSL_CFG_FLAGS"
  140. ./Configure \
  141. $OPENSSL_CFG_FLAGS
  142. make clean
  143. fi
  144. #--------------------
  145. echo "\n--------------------"
  146. echo "[*] compile openssl"
  147. echo "--------------------"
  148. set +e
  149. make
  150. make install_sw