1#!/bin/bash 2# 3# This script generates 'WebP.framework' and 'WebPDecoder.framework'. An iOS 4# app can decode WebP images by including 'WebPDecoder.framework' and both 5# encode and decode WebP images by including 'WebP.framework'. 6# 7# Run ./iosbuild.sh to generate the frameworks under the current directory 8# (the previous build will be erased if it exists). 9# 10# This script is inspired by the build script written by Carson McDonald. 11# (http://www.ioncannon.net/programming/1483/using-webp-to-reduce-native-ios-app-size/). 12 13set -e 14 15# Extract the latest SDK version from the final field of the form: iphoneosX.Y 16readonly SDK=$(xcodebuild -showsdks \ 17 | grep iphoneos | sort | tail -n 1 | awk '{print substr($NF, 9)}' 18) 19# Extract Xcode version. 20readonly XCODE=$(xcodebuild -version | grep Xcode | cut -d " " -f2) 21if [[ -z "${XCODE}" ]]; then 22 echo "Xcode not available" 23 exit 1 24fi 25 26readonly OLDPATH=${PATH} 27 28# Add iPhoneOS-V6 to the list of platforms below if you need armv6 support. 29# Note that iPhoneOS-V6 support is not available with the iOS6 SDK. 30PLATFORMS="iPhoneSimulator iPhoneSimulator64" 31PLATFORMS+=" iPhoneOS-V7 iPhoneOS-V7s iPhoneOS-V7-arm64" 32readonly PLATFORMS 33readonly SRCDIR=$(dirname $0) 34readonly TOPDIR=$(pwd) 35readonly BUILDDIR="${TOPDIR}/iosbuild" 36readonly TARGETDIR="${TOPDIR}/WebP.framework" 37readonly DECTARGETDIR="${TOPDIR}/WebPDecoder.framework" 38readonly MUXTARGETDIR="${TOPDIR}/WebPMux.framework" 39readonly DEMUXTARGETDIR="${TOPDIR}/WebPDemux.framework" 40readonly DEVELOPER=$(xcode-select --print-path) 41readonly PLATFORMSROOT="${DEVELOPER}/Platforms" 42readonly LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo) 43LIBLIST='' 44DECLIBLIST='' 45MUXLIBLIST='' 46DEMUXLIBLIST='' 47 48if [[ -z "${SDK}" ]]; then 49 echo "iOS SDK not available" 50 exit 1 51elif [[ ${SDK%%.*} -gt 8 ]]; then 52 EXTRA_CFLAGS="-fembed-bitcode" 53elif [[ ${SDK} < 6.0 ]]; then 54 echo "You need iOS SDK version 6.0 or above" 55 exit 1 56else 57 echo "iOS SDK Version ${SDK}" 58fi 59 60rm -rf ${BUILDDIR} ${TARGETDIR} ${DECTARGETDIR} \ 61 ${MUXTARGETDIR} ${DEMUXTARGETDIR} 62mkdir -p ${BUILDDIR} ${TARGETDIR}/Headers/ ${DECTARGETDIR}/Headers/ \ 63 ${MUXTARGETDIR}/Headers/ ${DEMUXTARGETDIR}/Headers/ 64 65if [[ ! -e ${SRCDIR}/configure ]]; then 66 if ! (cd ${SRCDIR} && sh autogen.sh); then 67 cat <<EOT 68Error creating configure script! 69This script requires the autoconf/automake and libtool to build. MacPorts can 70be used to obtain these: 71http://www.macports.org/install.php 72EOT 73 exit 1 74 fi 75fi 76 77for PLATFORM in ${PLATFORMS}; do 78 ARCH2="" 79 if [[ "${PLATFORM}" == "iPhoneOS-V7-arm64" ]]; then 80 PLATFORM="iPhoneOS" 81 ARCH="aarch64" 82 ARCH2="arm64" 83 elif [[ "${PLATFORM}" == "iPhoneOS-V7s" ]]; then 84 PLATFORM="iPhoneOS" 85 ARCH="armv7s" 86 elif [[ "${PLATFORM}" == "iPhoneOS-V7" ]]; then 87 PLATFORM="iPhoneOS" 88 ARCH="armv7" 89 elif [[ "${PLATFORM}" == "iPhoneOS-V6" ]]; then 90 PLATFORM="iPhoneOS" 91 ARCH="armv6" 92 elif [[ "${PLATFORM}" == "iPhoneSimulator64" ]]; then 93 PLATFORM="iPhoneSimulator" 94 ARCH="x86_64" 95 else 96 ARCH="i386" 97 fi 98 99 ROOTDIR="${BUILDDIR}/${PLATFORM}-${SDK}-${ARCH}" 100 mkdir -p "${ROOTDIR}" 101 102 DEVROOT="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain" 103 SDKROOT="${PLATFORMSROOT}/" 104 SDKROOT+="${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDK}.sdk/" 105 CFLAGS="-arch ${ARCH2:-${ARCH}} -pipe -isysroot ${SDKROOT} -O3 -DNDEBUG" 106 CFLAGS+=" -miphoneos-version-min=6.0 ${EXTRA_CFLAGS}" 107 108 set -x 109 export PATH="${DEVROOT}/usr/bin:${OLDPATH}" 110 ${SRCDIR}/configure --host=${ARCH}-apple-darwin --prefix=${ROOTDIR} \ 111 --build=$(${SRCDIR}/config.guess) \ 112 --disable-shared --enable-static \ 113 --enable-libwebpdecoder --enable-swap-16bit-csp \ 114 --enable-libwebpmux \ 115 CFLAGS="${CFLAGS}" 116 set +x 117 118 # run make only in the src/ directory to create libwebp.a/libwebpdecoder.a 119 cd src/ 120 make V=0 121 make install 122 123 LIBLIST+=" ${ROOTDIR}/lib/libwebp.a" 124 DECLIBLIST+=" ${ROOTDIR}/lib/libwebpdecoder.a" 125 MUXLIBLIST+=" ${ROOTDIR}/lib/libwebpmux.a" 126 DEMUXLIBLIST+=" ${ROOTDIR}/lib/libwebpdemux.a" 127 128 make clean 129 cd .. 130 131 export PATH=${OLDPATH} 132done 133 134echo "LIBLIST = ${LIBLIST}" 135cp -a ${SRCDIR}/src/webp/{decode,encode,types}.h ${TARGETDIR}/Headers/ 136${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP 137 138echo "DECLIBLIST = ${DECLIBLIST}" 139cp -a ${SRCDIR}/src/webp/{decode,types}.h ${DECTARGETDIR}/Headers/ 140${LIPO} -create ${DECLIBLIST} -output ${DECTARGETDIR}/WebPDecoder 141 142echo "MUXLIBLIST = ${MUXLIBLIST}" 143cp -a ${SRCDIR}/src/webp/{types,mux,mux_types}.h \ 144 ${MUXTARGETDIR}/Headers/ 145${LIPO} -create ${MUXLIBLIST} -output ${MUXTARGETDIR}/WebPMux 146 147echo "DEMUXLIBLIST = ${DEMUXLIBLIST}" 148cp -a ${SRCDIR}/src/webp/{decode,types,mux_types,demux}.h \ 149 ${DEMUXTARGETDIR}/Headers/ 150${LIPO} -create ${DEMUXLIBLIST} -output ${DEMUXTARGETDIR}/WebPDemux 151