blob: 304c93b2c17956a498d04a86c05b7dd214f0e83d [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
James Zern041956f2014-09-26 19:28:45 -070015readonly 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.
James Zern041956f2014-09-26 19:28:45 -070019readonly XCODE=$(xcodebuild -version | grep Xcode | cut -d " " -f2)
20if [[ -z "${XCODE}" ]]; then
21 echo "Xcode not available"
22 exit 1
23fi
Vikas Arorae8124012013-11-26 15:13:03 -080024
James Zern041956f2014-09-26 19:28:45 -070025readonly OLDPATH=${PATH}
Vikas Arora79fe39e2013-01-24 14:25:58 -080026
27# Add iPhoneOS-V6 to the list of platforms below if you need armv6 support.
28# Note that iPhoneOS-V6 support is not available with the iOS6 SDK.
James Zern041956f2014-09-26 19:28:45 -070029readonly PLATFORMS="iPhoneSimulator iPhoneOS-V7 iPhoneOS-V7s iPhoneOS-V7-arm64"
30readonly SRCDIR=$(dirname $0)
31readonly TOPDIR=$(pwd)
32readonly BUILDDIR="${TOPDIR}/iosbuild"
33readonly TARGETDIR="${TOPDIR}/WebP.framework"
34readonly DEVELOPER=$(xcode-select --print-path)
35readonly PLATFORMSROOT="${DEVELOPER}/Platforms"
36readonly LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo)
Vikas Arora79fe39e2013-01-24 14:25:58 -080037LIBLIST=''
38
39if [[ -z "${SDK}" ]]; then
40 echo "iOS SDK not available"
41 exit 1
James Zern9f7d9e62014-09-24 19:42:53 -070042elif [[ ${SDK} < 6.0 ]]; then
43 echo "You need iOS SDK version 6.0 or above"
Vikas Arora79fe39e2013-01-24 14:25:58 -080044 exit 1
45else
46 echo "iOS SDK Version ${SDK}"
47fi
48
49rm -rf ${BUILDDIR}
50rm -rf ${TARGETDIR}
51mkdir -p ${BUILDDIR}
52mkdir -p ${TARGETDIR}/Headers/
53
James Zern767eb402014-09-25 23:44:45 -070054if [[ ! -e ${SRCDIR}/configure ]]; then
55 if ! (cd ${SRCDIR} && sh autogen.sh); then
56 cat <<EOT
57Error creating configure script!
58This script requires the autoconf/automake and libtool to build. MacPorts can
59be used to obtain these:
60http://www.macports.org/install.php
61EOT
62 exit 1
63 fi
64fi
Vikas Arora79fe39e2013-01-24 14:25:58 -080065
66for PLATFORM in ${PLATFORMS}; do
James Zernb5c75252014-05-02 20:33:01 -070067 ARCH2=""
68 if [[ "${PLATFORM}" == "iPhoneOS-V7-arm64" ]]; then
69 PLATFORM="iPhoneOS"
70 ARCH="aarch64"
71 ARCH2="arm64"
72 elif [[ "${PLATFORM}" == "iPhoneOS-V7s" ]]; then
Vikas Arora79fe39e2013-01-24 14:25:58 -080073 PLATFORM="iPhoneOS"
74 ARCH="armv7s"
75 elif [[ "${PLATFORM}" == "iPhoneOS-V7" ]]; then
76 PLATFORM="iPhoneOS"
77 ARCH="armv7"
78 elif [[ "${PLATFORM}" == "iPhoneOS-V6" ]]; then
79 PLATFORM="iPhoneOS"
80 ARCH="armv6"
81 else
82 ARCH="i386"
83 fi
84
85 ROOTDIR="${BUILDDIR}/${PLATFORM}-${SDK}-${ARCH}"
86 mkdir -p "${ROOTDIR}"
87
James Zern041956f2014-09-26 19:28:45 -070088 DEVROOT="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain"
89 SDKROOT="${PLATFORMSROOT}/"
90 SDKROOT+="${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDK}.sdk/"
James Zernf59c0b42014-07-26 20:40:51 -070091 CFLAGS="-arch ${ARCH2:-${ARCH}} -pipe -isysroot ${SDKROOT} -O3 -DNDEBUG"
James Zern041956f2014-09-26 19:28:45 -070092 CFLAGS+=" -miphoneos-version-min=6.0"
Vikas Arora79fe39e2013-01-24 14:25:58 -080093
James Zern041956f2014-09-26 19:28:45 -070094 set -x
Vikas Arora79fe39e2013-01-24 14:25:58 -080095 export PATH="${DEVROOT}/usr/bin:${OLDPATH}"
Vikas Arora79fe39e2013-01-24 14:25:58 -080096 ${SRCDIR}/configure --host=${ARCH}-apple-darwin --prefix=${ROOTDIR} \
Vikas Arorafe4d25d2013-01-25 16:06:21 -080097 --build=$(${SRCDIR}/config.guess) \
Vikas Arora79fe39e2013-01-24 14:25:58 -080098 --disable-shared --enable-static \
James Zern041956f2014-09-26 19:28:45 -070099 --enable-libwebpdecoder --enable-swap-16bit-csp \
100 CFLAGS="${CFLAGS}"
101 set +x
Vikas Arora79fe39e2013-01-24 14:25:58 -0800102
103 # run make only in the src/ directory to create libwebpdecoder.a
104 cd src/
Vikas Arorafe4d25d2013-01-25 16:06:21 -0800105 make V=0
Vikas Arora79fe39e2013-01-24 14:25:58 -0800106 make install
107
108 LIBLIST+=" ${ROOTDIR}/lib/libwebpdecoder.a"
109
110 make clean
111 cd ..
112
113 export PATH=${OLDPATH}
114done
115
James Zern38128cb2014-09-22 17:28:51 -0700116cp -a ${SRCDIR}/src/webp/*.h ${TARGETDIR}/Headers/
Vikas Arora79fe39e2013-01-24 14:25:58 -0800117${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP