Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 1 | #!/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 | |
| 12 | set -e |
| 13 | |
| 14 | # Extract the latest SDK version from the final field of the form: iphoneosX.Y |
James Zern | 041956f | 2014-09-26 19:28:45 -0700 | [diff] [blame] | 15 | readonly SDK=$(xcodebuild -showsdks \ |
Vikas Arora | fe4d25d | 2013-01-25 16:06:21 -0800 | [diff] [blame] | 16 | | grep iphoneos | sort | tail -n 1 | awk '{print substr($NF, 9)}' |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 17 | ) |
Vikas Arora | e812401 | 2013-11-26 15:13:03 -0800 | [diff] [blame] | 18 | # Extract Xcode version. |
James Zern | 041956f | 2014-09-26 19:28:45 -0700 | [diff] [blame] | 19 | readonly XCODE=$(xcodebuild -version | grep Xcode | cut -d " " -f2) |
| 20 | if [[ -z "${XCODE}" ]]; then |
| 21 | echo "Xcode not available" |
| 22 | exit 1 |
| 23 | fi |
Vikas Arora | e812401 | 2013-11-26 15:13:03 -0800 | [diff] [blame] | 24 | |
James Zern | 041956f | 2014-09-26 19:28:45 -0700 | [diff] [blame] | 25 | readonly OLDPATH=${PATH} |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 26 | |
| 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 Zern | a96ccf8 | 2014-11-14 16:38:42 -0800 | [diff] [blame^] | 29 | PLATFORMS="iPhoneSimulator iPhoneSimulator64" |
| 30 | PLATFORMS+=" iPhoneOS-V7 iPhoneOS-V7s iPhoneOS-V7-arm64" |
| 31 | readonly PLATFORMS |
James Zern | 041956f | 2014-09-26 19:28:45 -0700 | [diff] [blame] | 32 | readonly SRCDIR=$(dirname $0) |
| 33 | readonly TOPDIR=$(pwd) |
| 34 | readonly BUILDDIR="${TOPDIR}/iosbuild" |
| 35 | readonly TARGETDIR="${TOPDIR}/WebP.framework" |
| 36 | readonly DEVELOPER=$(xcode-select --print-path) |
| 37 | readonly PLATFORMSROOT="${DEVELOPER}/Platforms" |
| 38 | readonly LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo) |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 39 | LIBLIST='' |
| 40 | |
| 41 | if [[ -z "${SDK}" ]]; then |
| 42 | echo "iOS SDK not available" |
| 43 | exit 1 |
James Zern | 9f7d9e6 | 2014-09-24 19:42:53 -0700 | [diff] [blame] | 44 | elif [[ ${SDK} < 6.0 ]]; then |
| 45 | echo "You need iOS SDK version 6.0 or above" |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 46 | exit 1 |
| 47 | else |
| 48 | echo "iOS SDK Version ${SDK}" |
| 49 | fi |
| 50 | |
| 51 | rm -rf ${BUILDDIR} |
| 52 | rm -rf ${TARGETDIR} |
| 53 | mkdir -p ${BUILDDIR} |
| 54 | mkdir -p ${TARGETDIR}/Headers/ |
| 55 | |
James Zern | 767eb40 | 2014-09-25 23:44:45 -0700 | [diff] [blame] | 56 | if [[ ! -e ${SRCDIR}/configure ]]; then |
| 57 | if ! (cd ${SRCDIR} && sh autogen.sh); then |
| 58 | cat <<EOT |
| 59 | Error creating configure script! |
| 60 | This script requires the autoconf/automake and libtool to build. MacPorts can |
| 61 | be used to obtain these: |
| 62 | http://www.macports.org/install.php |
| 63 | EOT |
| 64 | exit 1 |
| 65 | fi |
| 66 | fi |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 67 | |
| 68 | for PLATFORM in ${PLATFORMS}; do |
James Zern | b5c7525 | 2014-05-02 20:33:01 -0700 | [diff] [blame] | 69 | ARCH2="" |
| 70 | if [[ "${PLATFORM}" == "iPhoneOS-V7-arm64" ]]; then |
| 71 | PLATFORM="iPhoneOS" |
| 72 | ARCH="aarch64" |
| 73 | ARCH2="arm64" |
| 74 | elif [[ "${PLATFORM}" == "iPhoneOS-V7s" ]]; then |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 75 | 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 Zern | a96ccf8 | 2014-11-14 16:38:42 -0800 | [diff] [blame^] | 83 | elif [[ "${PLATFORM}" == "iPhoneSimulator64" ]]; then |
| 84 | PLATFORM="iPhoneSimulator" |
| 85 | ARCH="x86_64" |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 86 | else |
| 87 | ARCH="i386" |
| 88 | fi |
| 89 | |
| 90 | ROOTDIR="${BUILDDIR}/${PLATFORM}-${SDK}-${ARCH}" |
| 91 | mkdir -p "${ROOTDIR}" |
| 92 | |
James Zern | 041956f | 2014-09-26 19:28:45 -0700 | [diff] [blame] | 93 | DEVROOT="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain" |
| 94 | SDKROOT="${PLATFORMSROOT}/" |
| 95 | SDKROOT+="${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDK}.sdk/" |
James Zern | f59c0b4 | 2014-07-26 20:40:51 -0700 | [diff] [blame] | 96 | CFLAGS="-arch ${ARCH2:-${ARCH}} -pipe -isysroot ${SDKROOT} -O3 -DNDEBUG" |
James Zern | 041956f | 2014-09-26 19:28:45 -0700 | [diff] [blame] | 97 | CFLAGS+=" -miphoneos-version-min=6.0" |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 98 | |
James Zern | 041956f | 2014-09-26 19:28:45 -0700 | [diff] [blame] | 99 | set -x |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 100 | export PATH="${DEVROOT}/usr/bin:${OLDPATH}" |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 101 | ${SRCDIR}/configure --host=${ARCH}-apple-darwin --prefix=${ROOTDIR} \ |
Vikas Arora | fe4d25d | 2013-01-25 16:06:21 -0800 | [diff] [blame] | 102 | --build=$(${SRCDIR}/config.guess) \ |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 103 | --disable-shared --enable-static \ |
James Zern | 041956f | 2014-09-26 19:28:45 -0700 | [diff] [blame] | 104 | --enable-libwebpdecoder --enable-swap-16bit-csp \ |
| 105 | CFLAGS="${CFLAGS}" |
| 106 | set +x |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 107 | |
| 108 | # run make only in the src/ directory to create libwebpdecoder.a |
| 109 | cd src/ |
Vikas Arora | fe4d25d | 2013-01-25 16:06:21 -0800 | [diff] [blame] | 110 | make V=0 |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 111 | make install |
| 112 | |
| 113 | LIBLIST+=" ${ROOTDIR}/lib/libwebpdecoder.a" |
| 114 | |
| 115 | make clean |
| 116 | cd .. |
| 117 | |
| 118 | export PATH=${OLDPATH} |
| 119 | done |
| 120 | |
James Zern | 38128cb | 2014-09-22 17:28:51 -0700 | [diff] [blame] | 121 | cp -a ${SRCDIR}/src/webp/*.h ${TARGETDIR}/Headers/ |
Vikas Arora | 79fe39e | 2013-01-24 14:25:58 -0800 | [diff] [blame] | 122 | ${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP |