p≡p engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.7 KiB

  1. #!/bin/bash
  2. # This file is under GNU General Public License 3.0
  3. # see LICENSE.txt
  4. export DEVROOT=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
  5. DFT_DIST_DIR=../libcurl-ios-dist
  6. DIST_DIR=${DIST_DIR:-$DFT_DIST_DIR}
  7. function check_curl_ver() {
  8. echo "#include \"include/curl/curlver.h\"
  9. #if LIBCURL_VERSION_MAJOR < 7 || LIBCURL_VERSION_MINOR < 40
  10. #error Required curl 7.40.0+; See http://curl.haxx.se/docs/adv_20150108A.html
  11. #endif"|gcc -c -o /dev/null -xc -||exit 9
  12. }
  13. function build_for_arch() {
  14. ARCH=$1
  15. HOST=$2
  16. SYSROOT=$3
  17. PREFIX=$4
  18. IPHONEOS_DEPLOYMENT_TARGET="6.0"
  19. export PATH="${DEVROOT}/usr/bin/:${PATH}"
  20. export CFLAGS="-arch ${ARCH} -pipe -Os -gdwarf-2 -isysroot ${SYSROOT} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET} -fembed-bitcode"
  21. export LDFLAGS="-arch ${ARCH} -isysroot ${SYSROOT}"
  22. ./configure --disable-shared --enable-static ${SSL_FLAG} --host="${HOST}" --prefix=${PREFIX} && make -j8 && make install
  23. }
  24. if [ "$1" == "openssl" ]
  25. then
  26. if [ ! -d ${HOME}/Desktop/openssl-ios-dist ]
  27. then
  28. echo "Please use https://github.com/sinofool/build-openssl-ios/ to build OpenSSL for iOS first"
  29. exit 8
  30. fi
  31. export SSL_FLAG=--with-ssl=${HOME}/Desktop/openssl-ios-dist
  32. else
  33. check_curl_ver
  34. export SSL_FLAG=--with-darwinssl
  35. fi
  36. TMP_DIR=/tmp/build_libcurl_$$
  37. build_for_arch i386 i386-apple-darwin /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk ${TMP_DIR}/i386 || exit 1
  38. build_for_arch x86_64 x86_64-apple-darwin /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk ${TMP_DIR}/x86_64 || exit 2
  39. build_for_arch arm64 arm-apple-darwin /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk ${TMP_DIR}/arm64 || exit 3
  40. build_for_arch armv7s armv7s-apple-darwin /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk ${TMP_DIR}/armv7s || exit 4
  41. build_for_arch armv7 armv7-apple-darwin /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk ${TMP_DIR}/armv7 || exit 5
  42. mkdir -p ${TMP_DIR}/lib/
  43. ${DEVROOT}/usr/bin/lipo \
  44. -arch i386 ${TMP_DIR}/i386/lib/libcurl.a \
  45. -arch x86_64 ${TMP_DIR}/x86_64/lib/libcurl.a \
  46. -arch armv7 ${TMP_DIR}/armv7/lib/libcurl.a \
  47. -arch armv7s ${TMP_DIR}/armv7s/lib/libcurl.a \
  48. -arch arm64 ${TMP_DIR}/arm64/lib/libcurl.a \
  49. -output ${TMP_DIR}/lib/libcurl.a -create
  50. cp -r ${TMP_DIR}/armv7s/include ${TMP_DIR}/
  51. curl -O https://raw.githubusercontent.com/sinofool/build-libcurl-ios/master/patch-include.patch
  52. patch ${TMP_DIR}/include/curl/curlbuild.h < patch-include.patch
  53. mkdir -p ${DIST_DIR}
  54. cp -r ${TMP_DIR}/include ${TMP_DIR}/lib ${DIST_DIR}