build-mac/build_libcurl_dist.sh
author Edouard Tisserant
Tue, 27 Sep 2016 21:58:54 +0200
branchkeysync
changeset 1204 e0859bbaf844
parent 531 a7cc26cc39f2
child 1513 e7f7e42385b5
permissions -rw-r--r--
merge
     1 #!/bin/bash
     2 
     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}
     6 
     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 
    14 function build_for_arch() {
    15   ARCH=$1
    16   HOST=$2
    17   SYSROOT=$3
    18   PREFIX=$4
    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
    24 }
    25 
    26 if [ "$1" == "openssl" ]
    27 then
    28   if [ ! -d ${HOME}/Desktop/openssl-ios-dist ]
    29   then
    30     echo "Please use https://github.com/sinofool/build-openssl-ios/ to build OpenSSL for iOS first"
    31     exit 8
    32   fi
    33   export SSL_FLAG=--with-ssl=${HOME}/Desktop/openssl-ios-dist
    34 else
    35   check_curl_ver
    36   export SSL_FLAG=--with-darwinssl
    37 fi
    38 
    39 TMP_DIR=/tmp/build_libcurl_$$
    40 
    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
    46 
    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
    55 
    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
    59 
    60 mkdir -p ${DIST_DIR}
    61 cp -r ${TMP_DIR}/include ${TMP_DIR}/lib ${DIST_DIR}
    62