blob: 0094fded9eaf583ad3dae0ab0763632d318b3e7e [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)
Vikas Arorae8124012013-11-26 15:13:03 -080018# Extract Xcode version.
19declare -r XCODE=$(xcodebuild -version | grep Xcode | cut -d " " -f2)
20
Vikas Arora79fe39e2013-01-24 14:25:58 -080021declare -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 Zernb5c75252014-05-02 20:33:01 -070025declare -r PLATFORMS="iPhoneSimulator iPhoneOS-V7 iPhoneOS-V7s iPhoneOS-V7-arm64"
Vikas Arora79fe39e2013-01-24 14:25:58 -080026declare -r SRCDIR=$(dirname $0)
27declare -r TOPDIR=$(pwd)
28declare -r BUILDDIR="${TOPDIR}/iosbuild"
29declare -r TARGETDIR="${TOPDIR}/WebP.framework"
30declare -r DEVELOPER=$(xcode-select --print-path)
31declare -r PLATFORMSROOT="${DEVELOPER}/Platforms"
32declare -r LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo)
33LIBLIST=''
34
35if [[ -z "${SDK}" ]]; then
36 echo "iOS SDK not available"
37 exit 1
38elif [[ ${SDK} < 4.0 ]]; then
39 echo "You need iOS SDK version 4.0 or above"
40 exit 1
41else
42 echo "iOS SDK Version ${SDK}"
43fi
44
45rm -rf ${BUILDDIR}
46rm -rf ${TARGETDIR}
47mkdir -p ${BUILDDIR}
48mkdir -p ${TARGETDIR}/Headers/
49
50[[ -e ${SRCDIR}/configure ]] || (cd ${SRCDIR} && sh autogen.sh)
51
52for PLATFORM in ${PLATFORMS}; do
James Zernb5c75252014-05-02 20:33:01 -070053 ARCH2=""
54 if [[ "${PLATFORM}" == "iPhoneOS-V7-arm64" ]]; then
55 PLATFORM="iPhoneOS"
56 ARCH="aarch64"
57 ARCH2="arm64"
58 elif [[ "${PLATFORM}" == "iPhoneOS-V7s" ]]; then
Vikas Arora79fe39e2013-01-24 14:25:58 -080059 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 Arorae8124012013-11-26 15:13:03 -080074 SDKROOT="${PLATFORMSROOT}/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDK}.sdk/"
James Zernb5c75252014-05-02 20:33:01 -070075 CFLAGS="-arch ${ARCH2:-${ARCH}} -pipe -isysroot ${SDKROOT}"
76 LDFLAGS="-arch ${ARCH2:-${ARCH}} -pipe -isysroot ${SDKROOT}"
Vikas Arora79fe39e2013-01-24 14:25:58 -080077
Vikas Arorae8124012013-11-26 15:13:03 -080078 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 Arora79fe39e2013-01-24 14:25:58 -080091 export CXXFLAGS=${CFLAGS}
Vikas Arora79fe39e2013-01-24 14:25:58 -080092 export PATH="${DEVROOT}/usr/bin:${OLDPATH}"
93
94 ${SRCDIR}/configure --host=${ARCH}-apple-darwin --prefix=${ROOTDIR} \
Vikas Arorafe4d25d2013-01-25 16:06:21 -080095 --build=$(${SRCDIR}/config.guess) \
Vikas Arora79fe39e2013-01-24 14:25:58 -080096 --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 Arorafe4d25d2013-01-25 16:06:21 -0800101 make V=0
Vikas Arora79fe39e2013-01-24 14:25:58 -0800102 make install
103
104 LIBLIST+=" ${ROOTDIR}/lib/libwebpdecoder.a"
105
106 make clean
107 cd ..
108
109 export PATH=${OLDPATH}
110done
111
Vikas Arorafe4d25d2013-01-25 16:06:21 -0800112cp -a ${SRCDIR}/src/webp/* ${TARGETDIR}/Headers/
Vikas Arora79fe39e2013-01-24 14:25:58 -0800113${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP