blob: ac0f1464cf39a1721dbd0dbc7cb814cea508f8eb [file] [log] [blame]
Vikas Arora79fe39e2013-01-24 14:25:58 -08001#!/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
12set -e
13
14# Extract the latest SDK version from the final field of the form: iphoneosX.Y
15declare -r SDK=$(xcodebuild -showsdks \
16 | grep iphoneos | sort | tail -n 1 | awk '{ print substr($NF, 9)}'
17)
18declare -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.
22declare -r PLATFORMS="iPhoneSimulator iPhoneOS-V7 iPhoneOS-V7s"
23declare -r SRCDIR=$(dirname $0)
24declare -r TOPDIR=$(pwd)
25declare -r BUILDDIR="${TOPDIR}/iosbuild"
26declare -r TARGETDIR="${TOPDIR}/WebP.framework"
27declare -r DEVELOPER=$(xcode-select --print-path)
28declare -r PLATFORMSROOT="${DEVELOPER}/Platforms"
29declare -r LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo)
30LIBLIST=''
31
32if [[ -z "${SDK}" ]]; then
33 echo "iOS SDK not available"
34 exit 1
35elif [[ ${SDK} < 4.0 ]]; then
36 echo "You need iOS SDK version 4.0 or above"
37 exit 1
38else
39 echo "iOS SDK Version ${SDK}"
40fi
41
42rm -rf ${BUILDDIR}
43rm -rf ${TARGETDIR}
44mkdir -p ${BUILDDIR}
45mkdir -p ${TARGETDIR}/Headers/
46
47[[ -e ${SRCDIR}/configure ]] || (cd ${SRCDIR} && sh autogen.sh)
48
49for 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}
89done
90
91cp -a src/webp/* ${TARGETDIR}/Headers/
92${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP