build-libssl.sh 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. #!/bin/sh
  2. # Automatic build script for libssl and libcrypto
  3. # for iPhoneOS and iPhoneSimulator
  4. #
  5. # Created by Felix Schulze on 16.12.10.
  6. # Copyright 2010-2015 Felix Schulze. All rights reserved.
  7. #
  8. # Licensed under the Apache License, Version 2.0 (the "License");
  9. # you may not use this file except in compliance with the License.
  10. # You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS,
  16. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. # See the License for the specific language governing permissions and
  18. # limitations under the License.
  19. #
  20. ###########################################################################
  21. # Change values here #
  22. # #
  23. VERSION="1.0.2h" #
  24. IOS_SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version` #
  25. TVOS_SDKVERSION=`xcrun -sdk appletvos --show-sdk-version` #
  26. CURL_OPTIONS="" #
  27. CONFIG_OPTIONS="no-shared no-ssl2 no-ssl3 no-comp no-hw no-md2 no-md4 no-rc2 no-rc5 no-krb5 no-ripemd160 no-idea no-gost no-camellia no-seed no-3des no-heartbeats"
  28. FORCE_BUILD=false
  29. # To set "enable-ec_nistp_64_gcc_128" configuration for x64 archs set next variable to "true"
  30. ENABLE_EC_NISTP_64_GCC_128="" #
  31. # #
  32. ###########################################################################
  33. # #
  34. # Don't change anything under this line! #
  35. # #
  36. ###########################################################################
  37. CURRENTPATH=`pwd`
  38. # PSIPHON: remove unneeded architectures
  39. #ARCHS="i386 x86_64 armv7 armv7s arm64 tv_x86_64 tv_arm64"
  40. ARCHS="x86_64 armv7 armv7s arm64"
  41. DEVELOPER=`xcode-select -print-path`
  42. IOS_MIN_SDK_VERSION="6.1"
  43. TVOS_MIN_SDK_VERSION="9.0"
  44. if [ ${FORCE_BUILD} == false ]; then
  45. echo "Checking for existing libraries"
  46. LIBCRYPTO_VERSION=""
  47. LIBSSL_VERSION=""
  48. if [ -e ${CURRENTPATH}/lib/libcrypto.a ]; then
  49. LIBCRYPTO_VERSION=$(strings ${CURRENTPATH}/lib/libcrypto.a | grep "^OpenSSL ${VERSION}")
  50. fi
  51. if [ -e ${CURRENTPATH}/lib/libssl.a ]; then
  52. LIBSSL_VERSION=$(strings ${CURRENTPATH}/lib/libssl.a | grep "^OpenSSL ${VERSION}")
  53. fi
  54. if [[ "${LIBCRYPTO_VERSION}" == *${VERSION}* && "${LIBSSL_VERSION}" == *${VERSION}* ]]; then
  55. echo "libcrypto and libssl are built already built against target version: ${VERSION}"
  56. exit 0
  57. fi
  58. fi
  59. git clean -Xdf ${CURRENTPATH}
  60. if [ ! -d "$DEVELOPER" ]; then
  61. echo "xcode path is not set correctly $DEVELOPER does not exist"
  62. echo "run"
  63. echo "sudo xcode-select -switch <xcode path>"
  64. echo "for default installation:"
  65. echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer"
  66. exit 1
  67. fi
  68. case $DEVELOPER in
  69. *\ * )
  70. echo "Your Xcode path contains whitespaces, which is not supported."
  71. exit 1
  72. ;;
  73. esac
  74. case $CURRENTPATH in
  75. *\ * )
  76. echo "Your path contains whitespaces, which is not supported by 'make install'."
  77. exit 1
  78. ;;
  79. esac
  80. set -e
  81. if [ ! -e openssl-${VERSION}.tar.gz ]; then
  82. echo "Downloading openssl-${VERSION}.tar.gz"
  83. curl ${CURL_OPTIONS} -O https://www.openssl.org/source/openssl-${VERSION}.tar.gz
  84. else
  85. echo "Using openssl-${VERSION}.tar.gz"
  86. fi
  87. mkdir -p "${CURRENTPATH}/src"
  88. mkdir -p "${CURRENTPATH}/bin"
  89. mkdir -p "${CURRENTPATH}/lib"
  90. for ARCH in ${ARCHS}
  91. do
  92. if [[ "$ARCH" == tv* ]]; then
  93. SDKVERSION=$TVOS_SDKVERSION
  94. MIN_SDK_VERSION=$TVOS_MIN_SDK_VERSION
  95. else
  96. SDKVERSION=$IOS_SDKVERSION
  97. MIN_SDK_VERSION=$IOS_MIN_SDK_VERSION
  98. fi
  99. if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]]; then
  100. PLATFORM="iPhoneSimulator"
  101. elif [ "${ARCH}" == "tv_x86_64" ]; then
  102. ARCH="x86_64"
  103. PLATFORM="AppleTVSimulator"
  104. elif [ "${ARCH}" == "tv_arm64" ]; then
  105. ARCH="arm64"
  106. PLATFORM="AppleTVOS"
  107. else
  108. PLATFORM="iPhoneOS"
  109. fi
  110. export $PLATFORM
  111. export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
  112. export CROSS_SDK="${PLATFORM}${SDKVERSION}.sdk"
  113. export BUILD_TOOLS="${DEVELOPER}"
  114. mkdir -p "${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk"
  115. LOG="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/build-openssl-${VERSION}.log"
  116. echo "Building openssl-${VERSION} for ${PLATFORM} ${SDKVERSION} ${ARCH}"
  117. echo " Logfile: $LOG"
  118. LOCAL_CONFIG_OPTIONS="${CONFIG_OPTIONS}"
  119. if [ "${ENABLE_EC_NISTP_64_GCC_128}" == "true" ]; then
  120. case "$ARCH" in
  121. *64*)
  122. LOCAL_CONFIG_OPTIONS="${LOCAL_CONFIG_OPTIONS} enable-ec_nistp_64_gcc_128"
  123. ;;
  124. esac
  125. fi
  126. export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}"
  127. echo " Patch source code..."
  128. src_work_dir="${CURRENTPATH}/src/${PLATFORM}-${ARCH}"
  129. mkdir -p "$src_work_dir"
  130. tar zxf "${CURRENTPATH}/openssl-${VERSION}.tar.gz" -C "$src_work_dir"
  131. cd "${src_work_dir}/openssl-${VERSION}"
  132. chmod u+x ./Configure
  133. if [[ "${PLATFORM}" == "AppleTVSimulator" || "${PLATFORM}" == "AppleTVOS" ]]; then
  134. LC_ALL=C sed -i -- 's/define HAVE_FORK 1/define HAVE_FORK 0/' "./apps/speed.c"
  135. LC_ALL=C sed -i -- 's/D\_REENTRANT\:iOS/D\_REENTRANT\:tvOS/' "./Configure"
  136. if [[ "${ARCH}" == "arm64" ]]; then
  137. sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c"
  138. fi
  139. elif [[ "$PLATFORM" == "iPhoneOS" ]]; then
  140. sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c"
  141. fi
  142. echo " Configure...\c"
  143. set +e
  144. if [ "$1" == "verbose" ]; then
  145. if [ "${ARCH}" == "x86_64" ]; then
  146. ./Configure no-asm darwin64-x86_64-cc --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" ${LOCAL_CONFIG_OPTIONS}
  147. else
  148. ./Configure iphoneos-cross --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" ${LOCAL_CONFIG_OPTIONS}
  149. fi
  150. else
  151. if [ "${ARCH}" == "x86_64" ]; then
  152. (./Configure no-asm darwin64-x86_64-cc --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" ${LOCAL_CONFIG_OPTIONS} > "${LOG}" 2>&1)
  153. else
  154. (./Configure iphoneos-cross --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" ${LOCAL_CONFIG_OPTIONS} > "${LOG}" 2>&1)
  155. fi
  156. fi
  157. if [ $? != 0 ]; then
  158. echo "Problem while configure - Please check ${LOG}"
  159. exit 1
  160. fi
  161. echo "\n Patch Makefile..."
  162. # add -isysroot to CC=
  163. if [[ "${PLATFORM}" == "AppleTVSimulator" || "${PLATFORM}" == "AppleTVOS" ]]; then
  164. sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -mtvos-version-min=${TVOS_MIN_SDK_VERSION} !" "Makefile"
  165. else
  166. sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=${MIN_SDK_VERSION} !" "Makefile"
  167. fi
  168. echo " Make...\c"
  169. if [ "$1" == "verbose" ]; then
  170. if [[ ! -z $CONFIG_OPTIONS ]]; then
  171. make depend
  172. fi
  173. make
  174. else
  175. if [[ ! -z $CONFIG_OPTIONS ]]; then
  176. make depend >> "${LOG}" 2>&1
  177. fi
  178. (make >> "${LOG}" 2>&1)
  179. fi
  180. echo "\n"
  181. if [ $? != 0 ]; then
  182. echo "Problem while make - Please check ${LOG}"
  183. exit 1
  184. fi
  185. set -e
  186. if [ "$1" == "verbose" ]; then
  187. make install_sw
  188. make clean
  189. else
  190. make install_sw >> "${LOG}" 2>&1
  191. make clean >> "${LOG}" 2>&1
  192. fi
  193. rm -rf "$src_work_dir"
  194. done
  195. echo "Build library for iOS..."
  196. # PSIPHON: remove unneeded architectures
  197. #lipo -create \
  198. # ${CURRENTPATH}/bin/iPhoneSimulator${IOS_SDKVERSION}-i386.sdk/lib/libssl.a \
  199. # ${CURRENTPATH}/bin/iPhoneSimulator${IOS_SDKVERSION}-x86_64.sdk/lib/libssl.a \
  200. # ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-armv7.sdk/lib/libssl.a \
  201. # ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-armv7s.sdk/lib/libssl.a \
  202. # ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-arm64.sdk/lib/libssl.a \
  203. # -output ${CURRENTPATH}/lib/libssl.a
  204. #lipo -create \
  205. # ${CURRENTPATH}/bin/iPhoneSimulator${IOS_SDKVERSION}-i386.sdk/lib/libcrypto.a \
  206. # ${CURRENTPATH}/bin/iPhoneSimulator${IOS_SDKVERSION}-x86_64.sdk/lib/libcrypto.a \
  207. # ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-armv7.sdk/lib/libcrypto.a \
  208. # ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-armv7s.sdk/lib/libcrypto.a \
  209. # ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-arm64.sdk/lib/libcrypto.a \
  210. # -output ${CURRENTPATH}/lib/libcrypto.a
  211. lipo -create \
  212. ${CURRENTPATH}/bin/iPhoneSimulator${IOS_SDKVERSION}-x86_64.sdk/lib/libssl.a \
  213. ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-armv7.sdk/lib/libssl.a \
  214. ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-armv7s.sdk/lib/libssl.a \
  215. ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-arm64.sdk/lib/libssl.a \
  216. -output ${CURRENTPATH}/lib/libssl.a
  217. lipo -create \
  218. ${CURRENTPATH}/bin/iPhoneSimulator${IOS_SDKVERSION}-x86_64.sdk/lib/libcrypto.a \
  219. ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-armv7.sdk/lib/libcrypto.a \
  220. ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-armv7s.sdk/lib/libcrypto.a \
  221. ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-arm64.sdk/lib/libcrypto.a \
  222. -output ${CURRENTPATH}/lib/libcrypto.a
  223. # PSIPHON: remove unneeded architectures
  224. #echo "Build library for tvOS..."
  225. #lipo -create \
  226. # ${CURRENTPATH}/bin/AppleTVSimulator${TVOS_SDKVERSION}-x86_64.sdk/lib/libssl.a \
  227. # ${CURRENTPATH}/bin/AppleTVOS${TVOS_SDKVERSION}-arm64.sdk/lib/libssl.a \
  228. # -output ${CURRENTPATH}/lib/libssl-tvOS.a
  229. #lipo -create \
  230. # ${CURRENTPATH}/bin/AppleTVSimulator${TVOS_SDKVERSION}-x86_64.sdk/lib/libcrypto.a \
  231. # ${CURRENTPATH}/bin/AppleTVOS${TVOS_SDKVERSION}-arm64.sdk/lib/libcrypto.a \
  232. # -output ${CURRENTPATH}/lib/libcrypto-tvOS.a
  233. mkdir -p ${CURRENTPATH}/include
  234. cp -R ${CURRENTPATH}/bin/iPhoneSimulator${IOS_SDKVERSION}-x86_64.sdk/include/openssl ${CURRENTPATH}/include/
  235. echo "Done."