blob: b38be6fc329dcb88b3bbdbf0ee757d8ee28a9d95 [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 \
Vikas Arorafe4d25d2013-01-25 16:06:21 -080016 | grep iphoneos | sort | tail -n 1 | awk '{print substr($NF, 9)}'
Vikas Arora79fe39e2013-01-24 14:25:58 -080017)
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} \
Vikas Arorafe4d25d2013-01-25 16:06:21 -080075 --build=$(${SRCDIR}/config.guess) \
Vikas Arora79fe39e2013-01-24 14:25:58 -080076 --disable-shared --enable-static \
77 --enable-libwebpdecoder --enable-swap-16bit-csp
78
79 # run make only in the src/ directory to create libwebpdecoder.a
80 cd src/
Vikas Arorafe4d25d2013-01-25 16:06:21 -080081 make V=0
Vikas Arora79fe39e2013-01-24 14:25:58 -080082 make install
83
84 LIBLIST+=" ${ROOTDIR}/lib/libwebpdecoder.a"
85
86 make clean
87 cd ..
88
89 export PATH=${OLDPATH}
90done
91
Vikas Arorafe4d25d2013-01-25 16:06:21 -080092cp -a ${SRCDIR}/src/webp/* ${TARGETDIR}/Headers/
Vikas Arora79fe39e2013-01-24 14:25:58 -080093${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP