iOS的LibcURL编译

个人记录

原文
更改脚本执行权限
chmod u+x test.sh更改其可执行权限

https://curl.haxx.se/

依赖环境
安装m4

http://www.gnu.org/software/m4/

tar -xzvf m4-1.4.17.tar.gz
cd m4-1.4.17
./configure --prefix=/usr/local
make
sudo make install
安装autoconf

http://www.gnu.org/software/autoconf/

tar -xzvf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure --prefix=/usr/local
make
sudo make install
安装automake

http://www.gnu.org/software/automake/

tar xzvf automake-1.14.tar.gz
cd automake-1.14
./configure --prefix=/usr/local
make
sudo make install
安装libtool

http://www.gnu.org/software/libtool/

tar xzvf libtool-2.4.2.tar.gz
cd libtool-2.4.2
./configure --prefix=/usr/local
make
sudo make install

下载libcurl源码,运行libcurl初始化脚本
把下载的zip包和脚本放到一个文件夹内,运行打包脚步
./build.sh
xcode记得装select
xcode-select --install

脚本
#!/bin/bash
# iOS 7.1  arm64, armv7, arm7s, i386 and x86_64.
set -x
echo "start......"
CURL_VERSION="7.50.1"
DEVELOPER="/Applications/Xcode.app/Contents/Developer"
SDK_VERSION=""
MIN_VERSION="7.0"
IPHONEOS_PLATFORM="${DEVELOPER}/Platforms/iPhoneOS.platform"
IPHONEOS_SDK="${IPHONEOS_PLATFORM}/Developer/SDKs/iPhoneOS${SDK_VERSION}.sdk"
IPHONEOS_GCC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
IPHONESIMULATOR_PLATFORM="${DEVELOPER}/Platforms/iPhoneSimulator.platform"
IPHONESIMULATOR_SDK="${IPHONESIMULATOR_PLATFORM}/Developer/SDKs/iPhoneSimulator${SDK_VERSION}.sdk"
IPHONESIMULATOR_GCC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
if [ ! -d "$IPHONEOS_PLATFORM" ]; then
echo "Cannot find $IPHONEOS_PLATFORM"
exit 1
fi
if [ ! -d "$IPHONEOS_SDK" ]; then
echo "Cannot find $IPHONEOS_SDK"
exit 1
fi
if [ ! -x "$IPHONEOS_GCC" ]; then
echo "Cannot find $IPHONEOS_GCC"
exit 1
fi
if [ ! -d "$IPHONESIMULATOR_PLATFORM" ]; then
echo "Cannot find $IPHONESIMULATOR_PLATFORM"
exit 1
fi
if [ ! -d "$IPHONESIMULATOR_SDK" ]; then
echo "Cannot find $IPHONESIMULATOR_SDK"
exit 1
fi
if [ ! -x "$IPHONESIMULATOR_GCC" ]; then
echo "Cannot find $IPHONESIMULATOR_GCC"
exit 1
fi
rm -rf lib include-32 include-64
rm -rf /tmp/curl-${CURL_VERSION}-
rm -rf /tmp/curl-${CURL_VERSION}-.-log
build()
{
HOST=$1
ARCH=$2
GCC=$3
SDK=$4
MOREFLAGS=$5
rm -rf "curl-${CURL_VERSION}"
unzip "curl-${CURL_VERSION}.zip" -d "."
pushd .
cd "curl-${CURL_VERSION}"
export IPHONEOS_DEPLOYMENT_TARGET=${MIN_VERSION}
export CC=${GCC}
export CFLAGS="-arch ${ARCH} -pipe -Os -gdwarf-2 -isysroot ${SDK}"
export CPPFLAGS=${MOREFLAGS}
export LDFLAGS="-arch ${ARCH} -isysroot ${SDK}"
# ./configure --disable-shared --enable-static --host=${HOST} --without-ssl --without-libssh2 --without-ca-bundle --without-ldap --disable-ldap --prefix="/tmp/curl-${CURL_VERSION}-${ARCH}" &> "/tmp/curl-${CURL_VERSION}-${ARCH}.log"
./configure --disable-shared --enable-static --host=${HOST} --with-darwinssl --prefix="/tmp/curl-${CURL_VERSION}-${ARCH}" &> "/tmp/curl-${CURL_VERSION}-${ARCH}.log"
make -jsysctl-nhw.logicalcpu_max&> "/tmp/curl-${CURL_VERSION}-${ARCH}.build-log"
make install &> "/tmp/curl-${CURL_VERSION}-${ARCH}.install-log"
popd
rm -rf "curl-${CURL_VERSION}"
}
build "armv7-apple-darwin"  "armv7"  "${IPHONEOS_GCC}"        "${IPHONEOS_SDK}" ""
build "armv7s-apple-darwin" "armv7s" "${IPHONEOS_GCC}"        "${IPHONEOS_SDK}" ""
build "arm-apple-darwin"    "arm64"  "${IPHONEOS_GCC}"        "${IPHONEOS_SDK}" ""
# build "i386-apple-darwin"  "i386"  "${IPHONESIMULATOR_GCC}" "${IPHONESIMULATOR_SDK}" "-D__IPHONE_OS_VERSION_MIN_REQUIRED=${IPHONEOS_DEPLOYMENT_TARGET%%.}0000"
# build "x86_64-apple-darwin" "x86_64" "${IPHONESIMULATOR_GCC}" "${IPHONESIMULATOR_SDK}" "-D__IPHONE_OS_VERSION_MIN_REQUIRED=${IPHONEOS_DEPLOYMENT_TARGET%%.}0000"
#
mkdir -p lib include-32 include-64
cp -r /tmp/curl-${CURL_VERSION}-i386/include/curl include-32/
cp -r /tmp/curl-${CURL_VERSION}-x86_64/include/curl include-64/
lipo \\
"/tmp/curl-${CURL_VERSION}-armv7/lib/libcurl.a" \\
"/tmp/curl-${CURL_VERSION}-armv7s/lib/libcurl.a" \\
"/tmp/curl-${CURL_VERSION}-arm64/lib/libcurl.a" \\
-create -output lib/libcurl.a
# "/tmp/curl-${CURL_VERSION}-i386/lib/libcurl.a" \\
# "/tmp/curl-${CURL_VERSION}-x86_64/lib/libcurl.a" \\
rm -rf "/tmp/curl-${CURL_VERSION}-"
crm -rf "/tmp/curl-${CURL_VERSION}-.-log"
echo "end......"

你可能感兴趣的:(iOS的LibcURL编译)