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