Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # This script generates 'WebP.framework'. An iOS app can decode WebP images |
| 4 | # by including 'WebP.framework'. |
| 5 | # |
| 6 | # Run ./iosbuild.sh to generate 'WebP.framework' under the current directory |
| 7 | # (previous build will be erased if it exists). |
| 8 | # |
| 9 | # This script is inspired by the build script written by Carson McDonald. |
| 10 | # (http://www.ioncannon.net/programming/1483/using-webp-to-reduce-native-ios-app-size/). |
| 11 | |
| 12 | set -e |
| 13 | |
| 14 | # Extract the latest SDK version from the final field of the form: iphoneosX.Y |
| 15 | declare -r SDK=$(xcodebuild -showsdks \ |
| 16 | | grep iphoneos | sort | tail -n 1 | awk '{ print substr($NF, 9)}' |
| 17 | ) |
| 18 | declare -r OLDPATH=${PATH} |
| 19 | |
| 20 | # Add iPhoneOS-V6 to the list of platforms below if you need armv6 support. |
| 21 | # Note that iPhoneOS-V6 support is not available with the iOS6 SDK. |
| 22 | declare -r PLATFORMS="iPhoneSimulator iPhoneOS-V7 iPhoneOS-V7s" |
| 23 | declare -r SRCDIR=$(dirname $0) |
| 24 | declare -r TOPDIR=$(pwd) |
| 25 | declare -r BUILDDIR="${TOPDIR}/iosbuild" |
| 26 | declare -r TARGETDIR="${TOPDIR}/WebP.framework" |
| 27 | declare -r DEVELOPER=$(xcode-select --print-path) |
| 28 | declare -r PLATFORMSROOT="${DEVELOPER}/Platforms" |
| 29 | declare -r LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo) |
| 30 | LIBLIST='' |
| 31 | |
| 32 | if [[ -z "${SDK}" ]]; then |
| 33 | echo "iOS SDK not available" |
| 34 | exit 1 |
| 35 | elif [[ ${SDK} < 4.0 ]]; then |
| 36 | echo "You need iOS SDK version 4.0 or above" |
| 37 | exit 1 |
| 38 | else |
| 39 | echo "iOS SDK Version ${SDK}" |
| 40 | fi |
| 41 | |
| 42 | rm -rf ${BUILDDIR} |
| 43 | rm -rf ${TARGETDIR} |
| 44 | mkdir -p ${BUILDDIR} |
| 45 | mkdir -p ${TARGETDIR}/Headers/ |
| 46 | |
| 47 | [[ -e ${SRCDIR}/configure ]] || (cd ${SRCDIR} && sh autogen.sh) |
| 48 | |
| 49 | for PLATFORM in ${PLATFORMS}; do |
| 50 | if [[ "${PLATFORM}" == "iPhoneOS-V7s" ]]; then |
| 51 | PLATFORM="iPhoneOS" |
| 52 | ARCH="armv7s" |
| 53 | elif [[ "${PLATFORM}" == "iPhoneOS-V7" ]]; then |
| 54 | PLATFORM="iPhoneOS" |
| 55 | ARCH="armv7" |
| 56 | elif [[ "${PLATFORM}" == "iPhoneOS-V6" ]]; then |
| 57 | PLATFORM="iPhoneOS" |
| 58 | ARCH="armv6" |
| 59 | else |
| 60 | ARCH="i386" |
| 61 | fi |
| 62 | |
| 63 | ROOTDIR="${BUILDDIR}/${PLATFORM}-${SDK}-${ARCH}" |
| 64 | mkdir -p "${ROOTDIR}" |
| 65 | |
| 66 | export DEVROOT="${PLATFORMSROOT}/${PLATFORM}.platform/Developer" |
| 67 | export SDKROOT="${DEVROOT}/SDKs/${PLATFORM}${SDK}.sdk" |
| 68 | |
| 69 | export CFLAGS="-arch ${ARCH} -pipe -isysroot ${SDKROOT}" |
| 70 | export CXXFLAGS=${CFLAGS} |
| 71 | export LDFLAGS="-arch ${ARCH} -pipe -isysroot ${SDKROOT}" |
| 72 | export PATH="${DEVROOT}/usr/bin:${OLDPATH}" |
| 73 | |
| 74 | ${SRCDIR}/configure --host=${ARCH}-apple-darwin --prefix=${ROOTDIR} \ |
| 75 | --disable-shared --enable-static \ |
| 76 | --enable-libwebpdecoder --enable-swap-16bit-csp |
| 77 | |
| 78 | # run make only in the src/ directory to create libwebpdecoder.a |
| 79 | cd src/ |
| 80 | make |
| 81 | make install |
| 82 | |
| 83 | LIBLIST+=" ${ROOTDIR}/lib/libwebpdecoder.a" |
| 84 | |
| 85 | make clean |
| 86 | cd .. |
| 87 | |
| 88 | export PATH=${OLDPATH} |
| 89 | done |
| 90 | |
| 91 | cp -a src/webp/* ${TARGETDIR}/Headers/ |
| 92 | ${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP |