3 export DEVROOT=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
4 DFT_DIST_DIR=../libcurl-ios-dist
5 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
14 function build_for_arch() {
19 IPHONEOS_DEPLOYMENT_TARGET="6.0"
20 export PATH="${DEVROOT}/usr/bin/:${PATH}"
21 export CFLAGS="-arch ${ARCH} -pipe -Os -gdwarf-2 -isysroot ${SYSROOT} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET} -fembed-bitcode"
22 export LDFLAGS="-arch ${ARCH} -isysroot ${SYSROOT}"
23 ./configure --disable-shared --enable-static ${SSL_FLAG} --host="${HOST}" --prefix=${PREFIX} && make -j8 && make install
26 if [ "$1" == "openssl" ]
28 if [ ! -d ${HOME}/Desktop/openssl-ios-dist ]
30 echo "Please use https://github.com/sinofool/build-openssl-ios/ to build OpenSSL for iOS first"
33 export SSL_FLAG=--with-ssl=${HOME}/Desktop/openssl-ios-dist
36 export SSL_FLAG=--with-darwinssl
39 TMP_DIR=/tmp/build_libcurl_$$
41 build_for_arch i386 i386-apple-darwin /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk ${TMP_DIR}/i386 || exit 1
42 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
43 build_for_arch arm64 arm-apple-darwin /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk ${TMP_DIR}/arm64 || exit 3
44 build_for_arch armv7s armv7s-apple-darwin /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk ${TMP_DIR}/armv7s || exit 4
45 build_for_arch armv7 armv7-apple-darwin /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk ${TMP_DIR}/armv7 || exit 5
47 mkdir -p ${TMP_DIR}/lib/
48 ${DEVROOT}/usr/bin/lipo \
49 -arch i386 ${TMP_DIR}/i386/lib/libcurl.a \
50 -arch x86_64 ${TMP_DIR}/x86_64/lib/libcurl.a \
51 -arch armv7 ${TMP_DIR}/armv7/lib/libcurl.a \
52 -arch armv7s ${TMP_DIR}/armv7s/lib/libcurl.a \
53 -arch arm64 ${TMP_DIR}/arm64/lib/libcurl.a \
54 -output ${TMP_DIR}/lib/libcurl.a -create
56 cp -r ${TMP_DIR}/armv7s/include ${TMP_DIR}/
57 curl -O https://raw.githubusercontent.com/sinofool/build-libcurl-ios/master/patch-include.patch
58 patch ${TMP_DIR}/include/curl/curlbuild.h < patch-include.patch
61 cp -r ${TMP_DIR}/include ${TMP_DIR}/lib ${DIST_DIR}