Last active
June 10, 2016 09:34
-
-
Save TimOliver/09ad68733c82feabff167bde9727ccbc to your computer and use it in GitHub Desktop.
A Bash script for building an iOS-compatible binary of the lhasa library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Global build settings | |
export SDKPATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk | |
export SIMSDKPATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk | |
export MIN_IOS_VERSION=7.0 | |
export HOST=arm-apple-darwin | |
export LDFLAGS_NATIVE="-isysroot $SDKPATH" | |
export LDFLAGS_SIMULATOR="-isysroot $SIMSDKPATH" | |
export TASN1_CFLAGS="-Ilibtasn1/include" | |
export TASN1_LIBS="-Llibtasn1 -ltasn1" | |
export ARCHES=(armv7 armv7s arm64 i386 x86_64) | |
# liblhasa defines | |
export LHA_URL="https://github.com/fragglet/lhasa/releases/download/v0.3.1/lhasa-0.3.1.tar.gz" | |
export LHA_DIR_NAME="lhasa-0.3.1" | |
echo "Checking liblhasa..." | |
# Download the latest version of liblhasa | |
if [ ! -d $LHA_DIR_NAME ]; then | |
echo "Downloading liiblhasa..." | |
curl -L -J -O $LHA_URL | |
tar -xf $LHA_DIR_NAME.tar.gz | |
fi | |
echo "...Done" | |
cd $LHA_DIR_NAME | |
rm -rf build | |
build_files="" | |
for i in "${ARCHES[@]}" | |
do | |
build_files="$build_files build/$i/lib/liblhasa.a" | |
export ARCH=$i | |
if [[ $i == *"arm"* ]] | |
then | |
export LDFLAGS=$LDFLAGS_NATIVE | |
else | |
export LDFLAGS=$LDFLAGS_SIMULATOR | |
fi | |
export CFLAGS="-arch $ARCH $LDFLAGS -miphoneos-version-min=$MIN_IOS_VERSION -fembed-bitcode -DNDEBUG" | |
./bootstrap | |
./configure --host=$HOST --prefix=$PWD/build/$ARCH && make && make install | |
make clean | |
done | |
#Merge the compiled binaries into a single universal one | |
mkdir -p build/universal | |
lipo -create $build_files -output build/universal/liblhasa.a | |
#Copy headers across | |
mkdir build/universal/include | |
cp -R build/armv7/include build/universal | |
#Move final product to parent directory | |
cp -R build/universal ../liblhasa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment