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 \ |
Vikas Arora | fe4d25d | 2013-01-25 16:06:21 -0800 | [diff] [blame] | 16 | | grep iphoneos | sort | tail -n 1 | awk '{print substr($NF, 9)}' |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 17 | ) |
Vikas Arora | e812401 | 2013-11-26 15:13:03 -0800 | [diff] [blame] | 18 | # Extract Xcode version. |
| 19 | declare -r XCODE=$(xcodebuild -version | grep Xcode | cut -d " " -f2) |
| 20 | |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 21 | declare -r OLDPATH=${PATH} |
| 22 | |
| 23 | # Add iPhoneOS-V6 to the list of platforms below if you need armv6 support. |
| 24 | # Note that iPhoneOS-V6 support is not available with the iOS6 SDK. |
James Zern | b5c7525 | 2014-05-02 20:33:01 -0700 | [diff] [blame^] | 25 | declare -r PLATFORMS="iPhoneSimulator iPhoneOS-V7 iPhoneOS-V7s iPhoneOS-V7-arm64" |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 26 | declare -r SRCDIR=$(dirname $0) |
| 27 | declare -r TOPDIR=$(pwd) |
| 28 | declare -r BUILDDIR="${TOPDIR}/iosbuild" |
| 29 | declare -r TARGETDIR="${TOPDIR}/WebP.framework" |
| 30 | declare -r DEVELOPER=$(xcode-select --print-path) |
| 31 | declare -r PLATFORMSROOT="${DEVELOPER}/Platforms" |
| 32 | declare -r LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo) |
| 33 | LIBLIST='' |
| 34 | |
| 35 | if [[ -z "${SDK}" ]]; then |
| 36 | echo "iOS SDK not available" |
| 37 | exit 1 |
| 38 | elif [[ ${SDK} < 4.0 ]]; then |
| 39 | echo "You need iOS SDK version 4.0 or above" |
| 40 | exit 1 |
| 41 | else |
| 42 | echo "iOS SDK Version ${SDK}" |
| 43 | fi |
| 44 | |
| 45 | rm -rf ${BUILDDIR} |
| 46 | rm -rf ${TARGETDIR} |
| 47 | mkdir -p ${BUILDDIR} |
| 48 | mkdir -p ${TARGETDIR}/Headers/ |
| 49 | |
| 50 | [[ -e ${SRCDIR}/configure ]] || (cd ${SRCDIR} && sh autogen.sh) |
| 51 | |
| 52 | for PLATFORM in ${PLATFORMS}; do |
James Zern | b5c7525 | 2014-05-02 20:33:01 -0700 | [diff] [blame^] | 53 | ARCH2="" |
| 54 | if [[ "${PLATFORM}" == "iPhoneOS-V7-arm64" ]]; then |
| 55 | PLATFORM="iPhoneOS" |
| 56 | ARCH="aarch64" |
| 57 | ARCH2="arm64" |
| 58 | elif [[ "${PLATFORM}" == "iPhoneOS-V7s" ]]; then |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 59 | PLATFORM="iPhoneOS" |
| 60 | ARCH="armv7s" |
| 61 | elif [[ "${PLATFORM}" == "iPhoneOS-V7" ]]; then |
| 62 | PLATFORM="iPhoneOS" |
| 63 | ARCH="armv7" |
| 64 | elif [[ "${PLATFORM}" == "iPhoneOS-V6" ]]; then |
| 65 | PLATFORM="iPhoneOS" |
| 66 | ARCH="armv6" |
| 67 | else |
| 68 | ARCH="i386" |
| 69 | fi |
| 70 | |
| 71 | ROOTDIR="${BUILDDIR}/${PLATFORM}-${SDK}-${ARCH}" |
| 72 | mkdir -p "${ROOTDIR}" |
| 73 | |
Vikas Arora | e812401 | 2013-11-26 15:13:03 -0800 | [diff] [blame] | 74 | SDKROOT="${PLATFORMSROOT}/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDK}.sdk/" |
James Zern | b5c7525 | 2014-05-02 20:33:01 -0700 | [diff] [blame^] | 75 | CFLAGS="-arch ${ARCH2:-${ARCH}} -pipe -isysroot ${SDKROOT}" |
| 76 | LDFLAGS="-arch ${ARCH2:-${ARCH}} -pipe -isysroot ${SDKROOT}" |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 77 | |
Vikas Arora | e812401 | 2013-11-26 15:13:03 -0800 | [diff] [blame] | 78 | if [[ -z "${XCODE}" ]]; then |
| 79 | echo "XCODE not available" |
| 80 | exit 1 |
| 81 | elif [[ ${SDK} < 5.0.0 ]]; then |
| 82 | DEVROOT="${PLATFORMSROOT}/${PLATFORM}.platform/Developer/" |
| 83 | else |
| 84 | DEVROOT="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain" |
| 85 | CFLAGS+=" -miphoneos-version-min=5.0" |
| 86 | LDFLAGS+=" -miphoneos-version-min=5.0" |
| 87 | fi |
| 88 | |
| 89 | export CFLAGS |
| 90 | export LDFLAGS |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 91 | export CXXFLAGS=${CFLAGS} |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 92 | export PATH="${DEVROOT}/usr/bin:${OLDPATH}" |
| 93 | |
| 94 | ${SRCDIR}/configure --host=${ARCH}-apple-darwin --prefix=${ROOTDIR} \ |
Vikas Arora | fe4d25d | 2013-01-25 16:06:21 -0800 | [diff] [blame] | 95 | --build=$(${SRCDIR}/config.guess) \ |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 96 | --disable-shared --enable-static \ |
| 97 | --enable-libwebpdecoder --enable-swap-16bit-csp |
| 98 | |
| 99 | # run make only in the src/ directory to create libwebpdecoder.a |
| 100 | cd src/ |
Vikas Arora | fe4d25d | 2013-01-25 16:06:21 -0800 | [diff] [blame] | 101 | make V=0 |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 102 | make install |
| 103 | |
| 104 | LIBLIST+=" ${ROOTDIR}/lib/libwebpdecoder.a" |
| 105 | |
| 106 | make clean |
| 107 | cd .. |
| 108 | |
| 109 | export PATH=${OLDPATH} |
| 110 | done |
| 111 | |
Vikas Arora | fe4d25d | 2013-01-25 16:06:21 -0800 | [diff] [blame] | 112 | cp -a ${SRCDIR}/src/webp/* ${TARGETDIR}/Headers/ |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 113 | ${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP |