blob: 5262627231f9112acde07fe156c52eb6db024fdd [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 Zerndb1321a2015-10-07 18:16:12 -070044elif [[ ${SDK%%.*} -gt 8 ]]; then
45 EXTRA_CFLAGS="-fembed-bitcode"
James Zern9f7d9e62014-09-24 19:42:53 -070046elif [[ ${SDK} < 6.0 ]]; then
47 echo "You need iOS SDK version 6.0 or above"
Vikas Arora79fe39e2013-01-24 14:25:58 -080048 exit 1
49else
50 echo "iOS SDK Version ${SDK}"
51fi
52
53rm -rf ${BUILDDIR}
54rm -rf ${TARGETDIR}
55mkdir -p ${BUILDDIR}
56mkdir -p ${TARGETDIR}/Headers/
57
James Zern767eb402014-09-25 23:44:45 -070058if [[ ! -e ${SRCDIR}/configure ]]; then
59 if ! (cd ${SRCDIR} && sh autogen.sh); then
60 cat <<EOT
61Error creating configure script!
62This script requires the autoconf/automake and libtool to build. MacPorts can
63be used to obtain these:
64http://www.macports.org/install.php
65EOT
66 exit 1
67 fi
68fi
Vikas Arora79fe39e2013-01-24 14:25:58 -080069
70for PLATFORM in ${PLATFORMS}; do
James Zernb5c75252014-05-02 20:33:01 -070071 ARCH2=""
72 if [[ "${PLATFORM}" == "iPhoneOS-V7-arm64" ]]; then
73 PLATFORM="iPhoneOS"
74 ARCH="aarch64"
75 ARCH2="arm64"
76 elif [[ "${PLATFORM}" == "iPhoneOS-V7s" ]]; then
Vikas Arora79fe39e2013-01-24 14:25:58 -080077 PLATFORM="iPhoneOS"
78 ARCH="armv7s"
79 elif [[ "${PLATFORM}" == "iPhoneOS-V7" ]]; then
80 PLATFORM="iPhoneOS"
81 ARCH="armv7"
82 elif [[ "${PLATFORM}" == "iPhoneOS-V6" ]]; then
83 PLATFORM="iPhoneOS"
84 ARCH="armv6"
James Zerna96ccf82014-11-14 16:38:42 -080085 elif [[ "${PLATFORM}" == "iPhoneSimulator64" ]]; then
86 PLATFORM="iPhoneSimulator"
87 ARCH="x86_64"
Vikas Arora79fe39e2013-01-24 14:25:58 -080088 else
89 ARCH="i386"
90 fi
91
92 ROOTDIR="${BUILDDIR}/${PLATFORM}-${SDK}-${ARCH}"
93 mkdir -p "${ROOTDIR}"
94
James Zern041956f2014-09-26 19:28:45 -070095 DEVROOT="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain"
96 SDKROOT="${PLATFORMSROOT}/"
97 SDKROOT+="${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDK}.sdk/"
James Zernf59c0b42014-07-26 20:40:51 -070098 CFLAGS="-arch ${ARCH2:-${ARCH}} -pipe -isysroot ${SDKROOT} -O3 -DNDEBUG"
James Zerndb1321a2015-10-07 18:16:12 -070099 CFLAGS+=" -miphoneos-version-min=6.0 ${EXTRA_CFLAGS}"
Vikas Arora79fe39e2013-01-24 14:25:58 -0800100
James Zern041956f2014-09-26 19:28:45 -0700101 set -x
Vikas Arora79fe39e2013-01-24 14:25:58 -0800102 export PATH="${DEVROOT}/usr/bin:${OLDPATH}"
Vikas Arora79fe39e2013-01-24 14:25:58 -0800103 ${SRCDIR}/configure --host=${ARCH}-apple-darwin --prefix=${ROOTDIR} \
Vikas Arorafe4d25d2013-01-25 16:06:21 -0800104 --build=$(${SRCDIR}/config.guess) \
Vikas Arora79fe39e2013-01-24 14:25:58 -0800105 --disable-shared --enable-static \
James Zern041956f2014-09-26 19:28:45 -0700106 --enable-libwebpdecoder --enable-swap-16bit-csp \
107 CFLAGS="${CFLAGS}"
108 set +x
Vikas Arora79fe39e2013-01-24 14:25:58 -0800109
110 # run make only in the src/ directory to create libwebpdecoder.a
111 cd src/
Vikas Arorafe4d25d2013-01-25 16:06:21 -0800112 make V=0
Vikas Arora79fe39e2013-01-24 14:25:58 -0800113 make install
114
115 LIBLIST+=" ${ROOTDIR}/lib/libwebpdecoder.a"
116
117 make clean
118 cd ..
119
120 export PATH=${OLDPATH}
121done
122
James Zern38128cb2014-09-22 17:28:51 -0700123cp -a ${SRCDIR}/src/webp/*.h ${TARGETDIR}/Headers/
Vikas Arora79fe39e2013-01-24 14:25:58 -0800124${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP