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