1#!/usr/bin/env bash 2#*************************************************************************** 3# _ _ ____ _ 4# Project ___| | | | _ \| | 5# / __| | | | |_) | | 6# | (__| |_| | _ <| |___ 7# \___|\___/|_| \_\_____| 8# 9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 10# 11# This software is licensed as described in the file COPYING, which 12# you should have received as part of this distribution. The terms 13# are also available at https://curl.se/docs/copyright.html. 14# 15# You may opt to use, copy, modify, merge, publish, distribute and/or sell 16# copies of the Software, and permit persons to whom the Software is 17# furnished to do so, under the terms of the COPYING file. 18# 19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 20# KIND, either express or implied. 21# 22# SPDX-License-Identifier: curl 23# 24########################################################################### 25# This script performs all of the steps needed to build a 26# universal binary libcurl.framework for Mac OS X 10.4 or greater. 27# 28# Hendrik Visage: 29# Generalizations added since Snowleopard (10.6) do not include 30# the 10.4u SDK. 31# 32# Also note: 33# 10.5 is the *ONLY* SDK that support PPC64 :( -- 10.6 do not have ppc64 support 34#If you need to have PPC64 support then change below to 1 35PPC64_NEEDED=0 36# Apple does not support building for PPC anymore in Xcode 4 and later. 37# If you're using Xcode 3 or earlier and need PPC support, then change 38# the setting below to 1 39PPC_NEEDED=0 40 41# For me the default is to develop for the platform I am on, and if you 42#desire compatibility with older versions then change USE_OLD to 1 :) 43USE_OLD=0 44 45VERSION=`/usr/bin/sed -ne 's/^#define LIBCURL_VERSION "\(.*\)"/\1/p' include/curl/curlver.h` 46FRAMEWORK_VERSION=Versions/Release-$VERSION 47 48#I also wanted to "copy over" the system, and thus the reason I added the 49# version to Versions/Release-7.20.1 etc. 50# now a simple rsync -vaP libcurl.framework /Library/Frameworks will install it 51# and setup the right paths to this version, leaving the system version 52# "intact", so you can "fix" it later with the links to Versions/A/... 53 54DEVELOPER_PATH=`xcode-select --print-path` 55# Around Xcode 4.3, SDKs were moved from the Developer folder into the 56# MacOSX.platform folder 57if test -d "$DEVELOPER_PATH/Platforms/MacOSX.platform/Developer/SDKs"; then 58 SDK_PATH="$DEVELOPER_PATH/Platforms/MacOSX.platform/Developer/SDKs" 59else 60 SDK_PATH="$DEVELOPER_PATH/SDKs" 61fi 62OLD_SDK=`ls $SDK_PATH|head -1` 63NEW_SDK=`ls -r $SDK_PATH|head -1` 64 65if test "0"$USE_OLD -gt 0 66then 67 SDK32=$OLD_SDK 68else 69 SDK32=$NEW_SDK 70fi 71 72MACVER=`echo $SDK32|sed -e s/[a-zA-Z]//g -e s/.\$//` 73 74SDK32_DIR=$SDK_PATH/$SDK32 75MINVER32='-mmacosx-version-min='$MACVER 76if test $PPC_NEEDED -gt 0; then 77 ARCHES32='-arch i386 -arch ppc' 78else 79 ARCHES32='-arch i386' 80fi 81 82if test $PPC64_NEEDED -gt 0 83then 84 SDK64=10.5 85 ARCHES64='-arch x86_64 -arch ppc64' 86 SDK64=`ls $SDK_PATH | grep "10\.5" | head -1` 87else 88 ARCHES64='-arch x86_64' 89 #We "know" that 10.4 and earlier do not support 64bit 90 OLD_SDK64=`ls $SDK_PATH | grep -v "10\.[0-4]" | head -1` 91 NEW_SDK64=`ls -r $SDK_PATH | grep -v "10\.[0-4][^0-9]" | head -1` 92 if test $USE_OLD -gt 0 93 then 94 SDK64=$OLD_SDK64 95 else 96 SDK64=$NEW_SDK64 97 fi 98fi 99 100SDK64_DIR=$SDK_PATH/$SDK64 101MACVER64=`echo $SDK64|sed -e s/[a-zA-Z]//g -e s/.\$//` 102 103MINVER64='-mmacosx-version-min='$MACVER64 104 105if test ! -z $SDK32; then 106 echo "----Configuring libcurl for 32 bit universal framework..." 107 make clean 108 ./configure --disable-dependency-tracking --disable-static --with-gssapi --with-secure-transport \ 109 CFLAGS="-Os -isysroot $SDK32_DIR $ARCHES32" \ 110 LDFLAGS="-Wl,-syslibroot,$SDK32_DIR $ARCHES32 -Wl,-headerpad_max_install_names" \ 111 CC=$CC 112 113 echo "----Building 32 bit libcurl..." 114 make -j `sysctl -n hw.logicalcpu_max` 115 116 echo "----Creating 32 bit framework..." 117 rm -r libcurl.framework 118 mkdir -p libcurl.framework/${FRAMEWORK_VERSION}/Resources 119 cp lib/.libs/libcurl.dylib libcurl.framework/${FRAMEWORK_VERSION}/libcurl 120 install_name_tool -id @rpath/libcurl.framework/${FRAMEWORK_VERSION}/libcurl libcurl.framework/${FRAMEWORK_VERSION}/libcurl 121 cp lib/libcurl.plist libcurl.framework/${FRAMEWORK_VERSION}/Resources/Info.plist 122 mkdir -p libcurl.framework/${FRAMEWORK_VERSION}/Headers/curl 123 cp include/curl/*.h libcurl.framework/${FRAMEWORK_VERSION}/Headers/curl 124 pushd libcurl.framework 125 ln -fs ${FRAMEWORK_VERSION}/libcurl libcurl 126 ln -fs ${FRAMEWORK_VERSION}/Resources Resources 127 ln -fs ${FRAMEWORK_VERSION}/Headers Headers 128 cd Versions 129 ln -fs $(basename "${FRAMEWORK_VERSION}") Current 130 131 echo Testing for SDK64 132 if test -d $SDK64_DIR; then 133 echo entering... 134 popd 135 make clean 136 echo "----Configuring libcurl for 64 bit universal framework..." 137 ./configure --disable-dependency-tracking --disable-static --with-gssapi --with-secure-transport \ 138 CFLAGS="-Os -isysroot $SDK64_DIR $ARCHES64" \ 139 LDFLAGS="-Wl,-syslibroot,$SDK64_DIR $ARCHES64 -Wl,-headerpad_max_install_names" \ 140 CC=$CC 141 142 echo "----Building 64 bit libcurl..." 143 make -j `sysctl -n hw.logicalcpu_max` 144 145 echo "----Appending 64 bit framework to 32 bit framework..." 146 cp lib/.libs/libcurl.dylib libcurl.framework/${FRAMEWORK_VERSION}/libcurl64 147 install_name_tool -id @rpath/libcurl.framework/${FRAMEWORK_VERSION}/libcurl libcurl.framework/${FRAMEWORK_VERSION}/libcurl64 148 cp libcurl.framework/${FRAMEWORK_VERSION}/libcurl libcurl.framework/${FRAMEWORK_VERSION}/libcurl32 149 pwd 150 lipo libcurl.framework/${FRAMEWORK_VERSION}/libcurl32 libcurl.framework/${FRAMEWORK_VERSION}/libcurl64 -create -output libcurl.framework/${FRAMEWORK_VERSION}/libcurl 151 rm libcurl.framework/${FRAMEWORK_VERSION}/libcurl32 libcurl.framework/${FRAMEWORK_VERSION}/libcurl64 152 fi 153 154 pwd 155 lipo -info libcurl.framework/${FRAMEWORK_VERSION}/libcurl 156 echo "libcurl.framework is built and can now be included in other projects." 157 echo "Copy libcurl.framework to your bundle's Contents/Frameworks folder, ~/Library/Frameworks or /Library/Frameworks." 158else 159 echo "Building libcurl.framework requires Mac OS X 10.4 or later with the MacOSX10.4/5/6 SDK installed." 160fi 161