blob: edf8225bf25eb913002af4dc328d2ea2e975ccbd [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 Zerna96ccf82014-11-14 16:38:42 -080029PLATFORMS="iPhoneSimulator iPhoneSimulator64"
30PLATFORMS+=" iPhoneOS-V7 iPhoneOS-V7s iPhoneOS-V7-arm64"
31readonly PLATFORMS
James Zern041956f2014-09-26 19:28:45 -070032readonly SRCDIR=$(dirname $0)
33readonly TOPDIR=$(pwd)
34readonly BUILDDIR="${TOPDIR}/iosbuild"
35readonly TARGETDIR="${TOPDIR}/WebP.framework"
36readonly DEVELOPER=$(xcode-select --print-path)
37readonly PLATFORMSROOT="${DEVELOPER}/Platforms"
38readonly LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo)
Vikas Arora79fe39e2013-01-24 14:25:58 -080039LIBLIST=''
40
41if [[ -z "${SDK}" ]]; then
42 echo "iOS SDK not available"
43 exit 1
James Zern9f7d9e62014-09-24 19:42:53 -070044elif [[ ${SDK} < 6.0 ]]; then
45 echo "You need iOS SDK version 6.0 or above"
Vikas Arora79fe39e2013-01-24 14:25:58 -080046 exit 1
47else
48 echo "iOS SDK Version ${SDK}"
49fi
50
51rm -rf ${BUILDDIR}
52rm -rf ${TARGETDIR}
53mkdir -p ${BUILDDIR}
54mkdir -p ${TARGETDIR}/Headers/
55
James Zern767eb402014-09-25 23:44:45 -070056if [[ ! -e ${SRCDIR}/configure ]]; then
57 if ! (cd ${SRCDIR} && sh autogen.sh); then
58 cat <<EOT
59Error creating configure script!
60This script requires the autoconf/automake and libtool to build. MacPorts can
61be used to obtain these:
62http://www.macports.org/install.php
63EOT
64 exit 1
65 fi
66fi
Vikas Arora79fe39e2013-01-24 14:25:58 -080067
68for PLATFORM in ${PLATFORMS}; do
James Zernb5c75252014-05-02 20:33:01 -070069 ARCH2=""
70 if [[ "${PLATFORM}" == "iPhoneOS-V7-arm64" ]]; then
71 PLATFORM="iPhoneOS"
72 ARCH="aarch64"
73 ARCH2="arm64"
74 elif [[ "${PLATFORM}" == "iPhoneOS-V7s" ]]; then
Vikas Arora79fe39e2013-01-24 14:25:58 -080075 PLATFORM="iPhoneOS"
76 ARCH="armv7s"
77 elif [[ "${PLATFORM}" == "iPhoneOS-V7" ]]; then
78 PLATFORM="iPhoneOS"
79 ARCH="armv7"
80 elif [[ "${PLATFORM}" == "iPhoneOS-V6" ]]; then
81 PLATFORM="iPhoneOS"
82 ARCH="armv6"
James Zerna96ccf82014-11-14 16:38:42 -080083 elif [[ "${PLATFORM}" == "iPhoneSimulator64" ]]; then
84 PLATFORM="iPhoneSimulator"
85 ARCH="x86_64"
Vikas Arora79fe39e2013-01-24 14:25:58 -080086 else
87 ARCH="i386"
88 fi
89
90 ROOTDIR="${BUILDDIR}/${PLATFORM}-${SDK}-${ARCH}"
91 mkdir -p "${ROOTDIR}"
92
James Zern041956f2014-09-26 19:28:45 -070093 DEVROOT="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain"
94 SDKROOT="${PLATFORMSROOT}/"
95 SDKROOT+="${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDK}.sdk/"
James Zernf59c0b42014-07-26 20:40:51 -070096 CFLAGS="-arch ${ARCH2:-${ARCH}} -pipe -isysroot ${SDKROOT} -O3 -DNDEBUG"
James Zern041956f2014-09-26 19:28:45 -070097 CFLAGS+=" -miphoneos-version-min=6.0"
Vikas Arora79fe39e2013-01-24 14:25:58 -080098
James Zern041956f2014-09-26 19:28:45 -070099 set -x
Vikas Arora79fe39e2013-01-24 14:25:58 -0800100 export PATH="${DEVROOT}/usr/bin:${OLDPATH}"
Vikas Arora79fe39e2013-01-24 14:25:58 -0800101 ${SRCDIR}/configure --host=${ARCH}-apple-darwin --prefix=${ROOTDIR} \
Vikas Arorafe4d25d2013-01-25 16:06:21 -0800102 --build=$(${SRCDIR}/config.guess) \
Vikas Arora79fe39e2013-01-24 14:25:58 -0800103 --disable-shared --enable-static \
James Zern041956f2014-09-26 19:28:45 -0700104 --enable-libwebpdecoder --enable-swap-16bit-csp \
105 CFLAGS="${CFLAGS}"
106 set +x
Vikas Arora79fe39e2013-01-24 14:25:58 -0800107
108 # run make only in the src/ directory to create libwebpdecoder.a
109 cd src/
Vikas Arorafe4d25d2013-01-25 16:06:21 -0800110 make V=0
Vikas Arora79fe39e2013-01-24 14:25:58 -0800111 make install
112
113 LIBLIST+=" ${ROOTDIR}/lib/libwebpdecoder.a"
114
115 make clean
116 cd ..
117
118 export PATH=${OLDPATH}
119done
120
James Zern38128cb2014-09-22 17:28:51 -0700121cp -a ${SRCDIR}/src/webp/*.h ${TARGETDIR}/Headers/
Vikas Arora79fe39e2013-01-24 14:25:58 -0800122${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP