Skip to content

Instantly share code, notes, and snippets.

@i36lib
Last active October 28, 2015 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i36lib/bb27680fc8058c98aa92 to your computer and use it in GitHub Desktop.
Save i36lib/bb27680fc8058c98aa92 to your computer and use it in GitHub Desktop.
lz4 build script for iOS (armv7, armv7s, arm64), iOS Simulator (i386, x86_64)
A shell script to build lz4 for iOS:
==> Default lz4 version: lz4-r112
==> Minimum deployment target start with 7.0
==> Works with Xcode 7 and produce bitcode enabled binaries
==> Currently builds: iOS (armv7, armv7s,arm64), iOS Simulator (i386, x86_64)
#!/bin/bash
# By i36.lib@gmail.com
# Blog: http://i36.Me/
set -e
# LZ4 Version
#=================================
LZ4_VERSION="lz4-r112"
# SDK Version
#=================================
SDK_VERSION=$(xcodebuild -version -sdk iphoneos | grep SDKVersion | cut -f2 -d ':' | tr -d '[[:space:]]')
# Minimum iOS deployment target version
#=================================
MIN_IOS_VERSION="7.0"
echo "========================================"
echo "LZ4 version: ${LZ4_VERSION}"
echo "iOS SDK version: ${SDK_VERSION}"
echo "iOS deployment target: ${MIN_IOS_VERSION}"
echo "========================================"
AR=ar
RANLIB=ranlib
DEVELOPER=`xcode-select -print-path`
buildIOS()
{
ARCH=$1
mkdir -p /tmp/${LZ4_VERSION}/iOS/${ARCH}
OUTPT=/tmp/${LZ4_VERSION}/iOS/${ARCH}
pushd . > /dev/null
cd "${LZ4_VERSION}"
if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]]; then
PLATFORM="iPhoneSimulator"
else
PLATFORM="iPhoneOS"
fi
echo "Start Building ${LZ4_VERSION} for ${PLATFORM} ${SDK_VERSION} ${ARCH} ..."
export $PLATFORM
export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export CROSS_SDK="${PLATFORM}${SDK_VERSION}.sdk"
export BUILD_TOOLS="${DEVELOPER}"
export CC="${BUILD_TOOLS}/usr/bin/gcc -fembed-bitcode -isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -mios-version-min=${MIN_IOS_VERSION} -O3 -arch ${ARCH}"
$CC -c lz4.c -o $OUTPT/lz4.o >> "/tmp/${LZ4_VERSION}/iOS/${ARCH}_lz4.log" 2>&1
$CC -c lz4hc.c -o $OUTPT/lz4hc.o >> "/tmp/${LZ4_VERSION}/iOS/${ARCH}_lz4hc.log" 2>&1
$AR rc $OUTPT/liblz4.a $OUTPT/lz4.o $OUTPT/lz4hc.o
$RANLIB $OUTPT/liblz4.a
popd > /dev/null
echo "Done Building ${LZ4_VERSION} for ${ARCH}!"
}
## Start building ...
################################################
#echo "Cleaning up ..."
rm -rf build/
rm -rf ${LZ4_VERSION}
rm -rf /tmp/${LZ4_VERSION}
mkdir -p build/src
mkdir -p build/lz4/lib
mkdir -p build/lz4/include/
if [ ! -e ${LZ4_VERSION}.tar.gz ]; then
echo "Downloading ${LZ4_VERSION}.tar.gz"
curl -O https://lz4.googlecode.com/files/${LZ4_VERSION}.tar.gz
else
echo "Using ${LZ4_VERSION}.tar.gz"
fi
echo "Unpacking ${LZ4_VERSION}.tar.gz ..."
tar xfz "${LZ4_VERSION}.tar.gz"
cp -R ${LZ4_VERSION}/* build/src/
buildIOS "armv7"
buildIOS "armv7s"
buildIOS "arm64"
buildIOS "x86_64"
buildIOS "i386"
echo "Building iOS libraries ..."
lipo \
"/tmp/${LZ4_VERSION}/iOS/armv7/liblz4.a" \
"/tmp/${LZ4_VERSION}/iOS/arm64/liblz4.a" \
"/tmp/${LZ4_VERSION}/iOS/i386/liblz4.a" \
"/tmp/${LZ4_VERSION}/iOS/x86_64/liblz4.a" \
-create -output build/lz4/lib/liblz4.a
cp build/src/lz4.h build/lz4/include/
cp build/src/lz4hc.h build/lz4/include/
echo "Cleaning up ..."
rm -rf ${LZ4_VERSION}
rm -rf /tmp/${LZ4_VERSION}
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment