blob: e6badcde5424bd67c69ac354f08a7d71764b615c [file] [log] [blame]
Yang Tsef5548972009-02-23 12:39:06 +00001#!/bin/bash
Yang Tsea07bc792010-02-14 19:40:18 +00002# This script performs all of the steps needed to build a
Yang Tsef5548972009-02-23 12:39:06 +00003# universal binary libcurl.framework for Mac OS X 10.4 or greater.
Hendrik Visage70a025f2010-09-21 00:07:45 +02004#
5# Hendrik Visage:
6# Generalizations added since Snowleopard (10.6) do not include
7# the 10.4u SDK.
8#
9# Also note:
10# 10.5 is the *ONLY* SDK that support PPC64 :( -- 10.6 do not have ppc64 support
11#If you need to have PPC64 support then change below to 1
12PPC64_NEEDED=0
Nick Zitzmann072b1ad2013-02-17 14:30:38 -070013# Apple does not support building for PPC anymore in Xcode 4 and later.
14# If you're using Xcode 3 or earlier and need PPC support, then change
15# the setting below to 1
16PPC_NEEDED=0
Hendrik Visage70a025f2010-09-21 00:07:45 +020017
18# For me the default is to develop for the platform I am on, and if you
19#desire compatibility with older versions then change USE_OLD to 1 :)
20USE_OLD=0
Yang Tsef5548972009-02-23 12:39:06 +000021
22VERSION=`/usr/bin/sed -ne 's/^#define LIBCURL_VERSION "\(.*\)"/\1/p' include/curl/curlver.h`
Hendrik Visage70a025f2010-09-21 00:07:45 +020023FRAMEWORK_VERSION=Versions/Release-$VERSION
Yang Tsef5548972009-02-23 12:39:06 +000024
Hendrik Visage70a025f2010-09-21 00:07:45 +020025#I also wanted to "copy over" the system, and thus the reason I added the
26# version to Versions/Release-7.20.1 etc.
27# now a simple rsync -vaP libcurl.framework /Library/Frameworks will install it
28# and setup the right paths to this version, leaving the system version
29# "intact", so you can "fix" it later with the links to Versions/A/...
Yang Tsef5548972009-02-23 12:39:06 +000030
Nick Zitzmann072b1ad2013-02-17 14:30:38 -070031DEVELOPER_PATH=`xcode-select --print-path`
32# Around Xcode 4.3, SDKs were moved from the Developer folder into the
33# MacOSX.platform folder
34if test -d "$DEVELOPER_PATH/Platforms/MacOSX.platform/Developer/SDKs"; then
35 SDK_PATH="$DEVELOPER_PATH/Platforms/MacOSX.platform/Developer/SDKs"
36else
37 SDK_PATH="$DEVELOPER_PATH/SDKs";
38fi
39OLD_SDK=`ls $SDK_PATH|head -1`
40NEW_SDK=`ls -r $SDK_PATH|head -1`
Yang Tsef5548972009-02-23 12:39:06 +000041
Hendrik Visage70a025f2010-09-21 00:07:45 +020042if test "0"$USE_OLD -gt 0
43then
44 SDK32=$OLD_SDK
45else
46 SDK32=$NEW_SDK
47fi
Yang Tsef5548972009-02-23 12:39:06 +000048
Hendrik Visage70a025f2010-09-21 00:07:45 +020049MACVER=`echo $SDK32|sed -e s/[a-zA-Z]//g -e s/.\$//`
Yang Tsef5548972009-02-23 12:39:06 +000050
Nick Zitzmann072b1ad2013-02-17 14:30:38 -070051SDK32_DIR=$SDK_PATH/$SDK32
Hendrik Visage70a025f2010-09-21 00:07:45 +020052MINVER32='-mmacosx-version-min='$MACVER
Nick Zitzmann072b1ad2013-02-17 14:30:38 -070053if test $PPC_NEEDED -gt 0; then
54 ARCHES32='-arch i386 -arch ppc'
55else
56 ARCHES32='-arch i386'
57fi
Hendrik Visage70a025f2010-09-21 00:07:45 +020058
59if test $PPC64_NEEDED -gt 0
60then
61 SDK64=10.5
62 ARCHES64='-arch x86_64 -arch ppc64'
Nick Zitzmann072b1ad2013-02-17 14:30:38 -070063 SDK64=`ls $SDK_PATH|grep 10.5|head -1`
Hendrik Visage70a025f2010-09-21 00:07:45 +020064else
65 ARCHES64='-arch x86_64'
66 #We "know" that 10.4 and earlier do not support 64bit
Nick Zitzmann072b1ad2013-02-17 14:30:38 -070067 OLD_SDK64=`ls $SDK_PATH|egrep -v "10.[0-4]"|head -1`
xiangbin lica20ca52015-10-25 12:35:16 +010068 NEW_SDK64=`ls -r $SDK_PATH|egrep -v "10.[0-4][^0-9]" | head -1`
Hendrik Visage70a025f2010-09-21 00:07:45 +020069 if test $USE_OLD -gt 0
70 then
71 SDK64=$OLD_SDK64
72 else
73 SDK64=$NEW_SDK64
74 fi
75fi
76
Nick Zitzmann072b1ad2013-02-17 14:30:38 -070077SDK64_DIR=$SDK_PATH/$SDK64
Hendrik Visage70a025f2010-09-21 00:07:45 +020078MACVER64=`echo $SDK64|sed -e s/[a-zA-Z]//g -e s/.\$//`
79
80MINVER64='-mmacosx-version-min='$MACVER64
81
82if test ! -z $SDK32; then
Yang Tseeed4a132009-04-10 02:50:21 +000083 echo "----Configuring libcurl for 32 bit universal framework..."
Hendrik Visage70a025f2010-09-21 00:07:45 +020084 make clean
Nick Zitzmann072b1ad2013-02-17 14:30:38 -070085 ./configure --disable-dependency-tracking --disable-static --with-gssapi --with-darwinssl \
86 CFLAGS="-Os -isysroot $SDK32_DIR $ARCHES32" \
87 LDFLAGS="-Wl,-syslibroot,$SDK32_DIR $ARCHES32 -Wl,-headerpad_max_install_names" \
Yang Tseeed4a132009-04-10 02:50:21 +000088 CC=$CC
Yang Tsea07bc792010-02-14 19:40:18 +000089
Yang Tseeed4a132009-04-10 02:50:21 +000090 echo "----Building 32 bit libcurl..."
Nick Zitzmann072b1ad2013-02-17 14:30:38 -070091 make -j `sysctl -n hw.logicalcpu_max`
Yang Tsea07bc792010-02-14 19:40:18 +000092
Yang Tseeed4a132009-04-10 02:50:21 +000093 echo "----Creating 32 bit framework..."
Yang Tsef5548972009-02-23 12:39:06 +000094 rm -r libcurl.framework
Hendrik Visage70a025f2010-09-21 00:07:45 +020095 mkdir -p libcurl.framework/${FRAMEWORK_VERSION}/Resources
96 cp lib/.libs/libcurl.dylib libcurl.framework/${FRAMEWORK_VERSION}/libcurl
stopiccot0f24df62015-03-09 22:46:22 +030097 install_name_tool -id @rpath/libcurl.framework/${FRAMEWORK_VERSION}/libcurl libcurl.framework/${FRAMEWORK_VERSION}/libcurl
Hendrik Visage70a025f2010-09-21 00:07:45 +020098 /usr/bin/sed -e "s/7\.12\.3/$VERSION/" lib/libcurl.plist >libcurl.framework/${FRAMEWORK_VERSION}/Resources/Info.plist
99 mkdir -p libcurl.framework/${FRAMEWORK_VERSION}/Headers/curl
100 cp include/curl/*.h libcurl.framework/${FRAMEWORK_VERSION}/Headers/curl
Yang Tseeed4a132009-04-10 02:50:21 +0000101 pushd libcurl.framework
Hendrik Visage70a025f2010-09-21 00:07:45 +0200102 ln -fs ${FRAMEWORK_VERSION}/libcurl libcurl
103 ln -fs ${FRAMEWORK_VERSION}/Resources Resources
104 ln -fs ${FRAMEWORK_VERSION}/Headers Headers
Yang Tsef5548972009-02-23 12:39:06 +0000105 cd Versions
Renaud Guillard992bee52013-05-09 17:31:56 +0200106 ln -fs $(basename "${FRAMEWORK_VERSION}") Current
Yang Tsea07bc792010-02-14 19:40:18 +0000107
Nick Zitzmann072b1ad2013-02-17 14:30:38 -0700108 echo Testing for SDK64
Hendrik Visage70a025f2010-09-21 00:07:45 +0200109 if test -d $SDK64_DIR; then
110 echo entering...
Yang Tseeed4a132009-04-10 02:50:21 +0000111 popd
112 make clean
113 echo "----Configuring libcurl for 64 bit universal framework..."
Nick Zitzmann072b1ad2013-02-17 14:30:38 -0700114 ./configure --disable-dependency-tracking --disable-static --with-gssapi --with-darwinssl \
115 CFLAGS="-Os -isysroot $SDK64_DIR $ARCHES64" \
116 LDFLAGS="-Wl,-syslibroot,$SDK64_DIR $ARCHES64 -Wl,-headerpad_max_install_names" \
Yang Tseeed4a132009-04-10 02:50:21 +0000117 CC=$CC
Yang Tsea07bc792010-02-14 19:40:18 +0000118
Yang Tseeed4a132009-04-10 02:50:21 +0000119 echo "----Building 64 bit libcurl..."
Nick Zitzmann072b1ad2013-02-17 14:30:38 -0700120 make -j `sysctl -n hw.logicalcpu_max`
Yang Tsea07bc792010-02-14 19:40:18 +0000121
Yang Tseeed4a132009-04-10 02:50:21 +0000122 echo "----Appending 64 bit framework to 32 bit framework..."
Hendrik Visage70a025f2010-09-21 00:07:45 +0200123 cp lib/.libs/libcurl.dylib libcurl.framework/${FRAMEWORK_VERSION}/libcurl64
stopiccot0f24df62015-03-09 22:46:22 +0300124 install_name_tool -id @rpath/libcurl.framework/${FRAMEWORK_VERSION}/libcurl libcurl.framework/${FRAMEWORK_VERSION}/libcurl64
Hendrik Visage70a025f2010-09-21 00:07:45 +0200125 cp libcurl.framework/${FRAMEWORK_VERSION}/libcurl libcurl.framework/${FRAMEWORK_VERSION}/libcurl32
126 pwd
127 lipo libcurl.framework/${FRAMEWORK_VERSION}/libcurl32 libcurl.framework/${FRAMEWORK_VERSION}/libcurl64 -create -output libcurl.framework/${FRAMEWORK_VERSION}/libcurl
128 rm libcurl.framework/${FRAMEWORK_VERSION}/libcurl32 libcurl.framework/${FRAMEWORK_VERSION}/libcurl64
Yang Tseeed4a132009-04-10 02:50:21 +0000129 fi
Yang Tsea07bc792010-02-14 19:40:18 +0000130
Hendrik Visage70a025f2010-09-21 00:07:45 +0200131 pwd
132 lipo -info libcurl.framework/${FRAMEWORK_VERSION}/libcurl
Yang Tsef5548972009-02-23 12:39:06 +0000133 echo "libcurl.framework is built and can now be included in other projects."
Yang Tseeed4a132009-04-10 02:50:21 +0000134 echo "Copy libcurl.framework to your bundle's Contents/Frameworks folder, ~/Library/Frameworks or /Library/Frameworks."
Yang Tsef5548972009-02-23 12:39:06 +0000135else
Hendrik Visage70a025f2010-09-21 00:07:45 +0200136 echo "Building libcurl.framework requires Mac OS X 10.4 or later with the MacOSX10.4/5/6 SDK installed."
Yang Tsef5548972009-02-23 12:39:06 +0000137fi