Skip to content

Instantly share code, notes, and snippets.

@TimOliver
Last active June 10, 2016 09:34
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 TimOliver/09ad68733c82feabff167bde9727ccbc to your computer and use it in GitHub Desktop.
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
#!/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