compile-openssl.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #----------
  19. # modify for your build tool
  20. FF_ALL_ARCHS_IOS6_SDK="armv7 armv7s i386"
  21. FF_ALL_ARCHS_IOS7_SDK="armv7 armv7s arm64 i386 x86_64"
  22. FF_ALL_ARCHS_IOS8_SDK="armv7 arm64 i386 x86_64"
  23. FF_ALL_ARCHS=$FF_ALL_ARCHS_IOS8_SDK
  24. #----------
  25. UNI_BUILD_ROOT=`pwd`
  26. UNI_TMP="$UNI_BUILD_ROOT/tmp"
  27. UNI_TMP_LLVM_VER_FILE="$UNI_TMP/llvm.ver.txt"
  28. FF_TARGET=$1
  29. set -e
  30. #----------
  31. FF_LIBS="libssl libcrypto"
  32. #----------
  33. echo_archs() {
  34. echo "===================="
  35. echo "[*] check xcode version"
  36. echo "===================="
  37. echo "FF_ALL_ARCHS = $FF_ALL_ARCHS"
  38. }
  39. do_lipo () {
  40. LIB_FILE=$1
  41. LIPO_FLAGS=
  42. for ARCH in $FF_ALL_ARCHS
  43. do
  44. LIPO_FLAGS="$LIPO_FLAGS $UNI_BUILD_ROOT/build/openssl-$ARCH/output/lib/$LIB_FILE"
  45. done
  46. xcrun lipo -create $LIPO_FLAGS -output $UNI_BUILD_ROOT/build/universal/lib/$LIB_FILE
  47. xcrun lipo -info $UNI_BUILD_ROOT/build/universal/lib/$LIB_FILE
  48. }
  49. do_lipo_all () {
  50. mkdir -p $UNI_BUILD_ROOT/build/universal/lib
  51. echo "lipo archs: $FF_ALL_ARCHS"
  52. for FF_LIB in $FF_LIBS
  53. do
  54. do_lipo "$FF_LIB.a";
  55. done
  56. cp -R $UNI_BUILD_ROOT/build/openssl-armv7/output/include $UNI_BUILD_ROOT/build/universal/
  57. }
  58. #----------
  59. if [ "$FF_TARGET" = "armv7" -o "$FF_TARGET" = "armv7s" -o "$FF_TARGET" = "arm64" ]; then
  60. echo_archs
  61. sh tools/do-compile-openssl.sh $FF_TARGET
  62. elif [ "$FF_TARGET" = "i386" -o "$FF_TARGET" = "x86_64" ]; then
  63. echo_archs
  64. sh tools/do-compile-openssl.sh $FF_TARGET
  65. elif [ "$FF_TARGET" = "lipo" ]; then
  66. echo_archs
  67. do_lipo_all
  68. elif [ "$FF_TARGET" = "all" ]; then
  69. echo_archs
  70. for ARCH in $FF_ALL_ARCHS
  71. do
  72. sh tools/do-compile-openssl.sh $ARCH
  73. done
  74. do_lipo_all
  75. elif [ "$FF_TARGET" = "check" ]; then
  76. echo_archs
  77. elif [ "$FF_TARGET" = "clean" ]; then
  78. echo_archs
  79. for ARCH in $FF_ALL_ARCHS
  80. do
  81. cd openssl-$ARCH && git clean -xdf && cd -
  82. done
  83. else
  84. echo "Usage:"
  85. echo " compile-openssl.sh armv7|arm64|i386|x86_64"
  86. echo " compile-openssl.sh armv7s (obselete)"
  87. echo " compile-openssl.sh lipo"
  88. echo " compile-openssl.sh all"
  89. echo " compile-openssl.sh clean"
  90. echo " compile-openssl.sh check"
  91. exit 1
  92. fi