1#! /bin/sh 2# 3# Step 1. 4# Configure for base system so simulator is covered 5# 6# Step 2. 7# Make for iOS and iOS simulator 8# 9# Step 3. 10# Merge libs into final version for xcode import 11 12export PREFIX="$(pwd)/libsodium-ios" 13export IOS32_PREFIX="$PREFIX/tmp/ios32" 14export IOS32s_PREFIX="$PREFIX/tmp/ios32s" 15export IOS64_PREFIX="$PREFIX/tmp/ios64" 16export SIMULATOR32_PREFIX="$PREFIX/tmp/simulator32" 17export SIMULATOR64_PREFIX="$PREFIX/tmp/simulator64" 18export XCODEDIR=$(xcode-select -p) 19 20export IOS_SIMULATOR_VERSION_MIN=${IOS_SIMULATOR_VERSION_MIN-"6.0.0"} 21export IOS_VERSION_MIN=${IOS_VERSION_MIN-"6.0.0"} 22 23mkdir -p $SIMULATOR32_PREFIX $SIMULATOR64_PREFIX $IOS32_PREFIX $IOS32s_PREFIX $IOS64_PREFIX || exit 1 24 25# Build for the simulator 26export BASEDIR="${XCODEDIR}/Platforms/iPhoneSimulator.platform/Developer" 27export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH" 28export SDK="${BASEDIR}/SDKs/iPhoneSimulator.sdk" 29 30## i386 simulator 31export CFLAGS="-O2 -arch i386 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN}" 32export LDFLAGS="-arch i386 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN}" 33 34make distclean > /dev/null 35 36if [ -z "$LIBSODIUM_FULL_BUILD" ]; then 37 export LIBSODIUM_ENABLE_MINIMAL_FLAG="--enable-minimal" 38else 39 export LIBSODIUM_ENABLE_MINIMAL_FLAG="" 40fi 41 42./configure --host=i686-apple-darwin10 \ 43 --disable-shared \ 44 ${LIBSODIUM_ENABLE_MINIMAL_FLAG} \ 45 --prefix="$SIMULATOR32_PREFIX" || exit 1 46 47 48NPROCESSORS=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null) 49PROCESSORS=${NPROCESSORS:-3} 50 51make -j${PROCESSORS} install || exit 1 52 53## x86_64 simulator 54export CFLAGS="-O2 -arch x86_64 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN}" 55export LDFLAGS="-arch x86_64 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN}" 56 57make distclean > /dev/null 58 59./configure --host=x86_64-apple-darwin10 \ 60 --disable-shared \ 61 ${LIBSODIUM_ENABLE_MINIMAL_FLAG} \ 62 --prefix="$SIMULATOR64_PREFIX" 63 64make -j${PROCESSORS} install || exit 1 65 66# Build for iOS 67export BASEDIR="${XCODEDIR}/Platforms/iPhoneOS.platform/Developer" 68export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH" 69export SDK="${BASEDIR}/SDKs/iPhoneOS.sdk" 70 71## 32-bit iOS 72export CFLAGS="-fembed-bitcode -O2 -mthumb -arch armv7 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN}" 73export LDFLAGS="-fembed-bitcode -mthumb -arch armv7 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN}" 74 75make distclean > /dev/null 76 77./configure --host=arm-apple-darwin10 \ 78 --disable-shared \ 79 ${LIBSODIUM_ENABLE_MINIMAL_FLAG} \ 80 --prefix="$IOS32_PREFIX" || exit 1 81 82make -j${PROCESSORS} install || exit 1 83 84## 32-bit armv7s iOS 85export CFLAGS="-fembed-bitcode -O2 -mthumb -arch armv7s -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN}" 86export LDFLAGS="-fembed-bitcode -mthumb -arch armv7s -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN}" 87 88make distclean > /dev/null 89 90./configure --host=arm-apple-darwin10 \ 91 --disable-shared \ 92 ${LIBSODIUM_ENABLE_MINIMAL_FLAG} \ 93 --prefix="$IOS32s_PREFIX" || exit 1 94 95make -j${PROCESSORS} install || exit 1 96 97## 64-bit iOS 98export CFLAGS="-fembed-bitcode -O2 -arch arm64 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN} -fembed-bitcode" 99export LDFLAGS="-fembed-bitcode -arch arm64 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN} -fembed-bitcode" 100 101make distclean > /dev/null 102 103./configure --host=arm-apple-darwin10 \ 104 --disable-shared \ 105 ${LIBSODIUM_ENABLE_MINIMAL_FLAG} \ 106 --prefix="$IOS64_PREFIX" || exit 1 107 108make -j${PROCESSORS} install || exit 1 109 110# Create universal binary and include folder 111rm -fr -- "$PREFIX/include" "$PREFIX/libsodium.a" 2> /dev/null 112mkdir -p -- "$PREFIX/lib" 113lipo -create \ 114 "$SIMULATOR32_PREFIX/lib/libsodium.a" \ 115 "$SIMULATOR64_PREFIX/lib/libsodium.a" \ 116 "$IOS32_PREFIX/lib/libsodium.a" \ 117 "$IOS32s_PREFIX/lib/libsodium.a" \ 118 "$IOS64_PREFIX/lib/libsodium.a" \ 119 -output "$PREFIX/lib/libsodium.a" 120mv -f -- "$IOS32_PREFIX/include" "$PREFIX/" 121 122echo 123echo "libsodium has been installed into $PREFIX" 124echo 125file -- "$PREFIX/lib/libsodium.a" 126 127# Cleanup 128rm -rf -- "$PREFIX/tmp" 129make distclean > /dev/null 130