3 # This script generates 'WebP.framework' and 'WebPDecoder.framework',
4 # 'WebPDemux.framework' and 'WebPMux.framework'.
5 # An iOS app can decode WebP images by including 'WebPDecoder.framework' and
6 # both encode and decode WebP images by including 'WebP.framework'.
8 # Run ./iosbuild.sh to generate the frameworks under the current directory
9 # (the previous build will be erased if it exists).
11 # This script is inspired by the build script written by Carson McDonald.
12 # (https://www.ioncannon.net/programming/1483/using-webp-to-reduce-native-ios-app-size/).
16 # Set this variable based on the desired minimum deployment target.
17 readonly IOS_MIN_VERSION=6.0
19 # Extract the latest SDK version from the final field of the form: iphoneosX.Y
20 readonly SDK=$(xcodebuild -showsdks \
21 | grep iphoneos | sort | tail -n 1 | awk '{print substr($NF, 9)}'
23 # Extract Xcode version.
24 readonly XCODE=$(xcodebuild -version | grep Xcode | cut -d " " -f2)
25 if [[ -z "${XCODE}" ]]; then
26 echo "Xcode not available"
30 readonly OLDPATH=${PATH}
32 # Add iPhoneOS-V6 to the list of platforms below if you need armv6 support.
33 # Note that iPhoneOS-V6 support is not available with the iOS6 SDK.
34 PLATFORMS="iPhoneSimulator iPhoneSimulator64"
35 PLATFORMS+=" iPhoneOS-V7 iPhoneOS-V7s iPhoneOS-V7-arm64"
37 readonly SRCDIR=$(dirname $0)
38 readonly TOPDIR=$(pwd)
39 readonly BUILDDIR="${TOPDIR}/iosbuild"
40 readonly TARGETDIR="${TOPDIR}/WebP.framework"
41 readonly DECTARGETDIR="${TOPDIR}/WebPDecoder.framework"
42 readonly MUXTARGETDIR="${TOPDIR}/WebPMux.framework"
43 readonly DEMUXTARGETDIR="${TOPDIR}/WebPDemux.framework"
44 readonly DEVELOPER=$(xcode-select --print-path)
45 readonly PLATFORMSROOT="${DEVELOPER}/Platforms"
46 readonly LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo)
52 if [[ -z "${SDK}" ]]; then
53 echo "iOS SDK not available"
55 elif [[ ${SDK%%.*} -gt 8 ]]; then
56 EXTRA_CFLAGS="-fembed-bitcode"
57 elif [[ ${SDK%%.*} -le 6 ]]; then
58 echo "You need iOS SDK version 6.0 or above"
62 echo "Xcode Version: ${XCODE}"
63 echo "iOS SDK Version: ${SDK}"
65 if [[ -e "${BUILDDIR}" || -e "${TARGETDIR}" || -e "${DECTARGETDIR}" \
66 || -e "${MUXTARGETDIR}" || -e "${DEMUXTARGETDIR}" ]]; then
68 WARNING: The following directories will be deleted:
71 WARNING: ${DECTARGETDIR}
72 WARNING: ${MUXTARGETDIR}
73 WARNING: ${DEMUXTARGETDIR}
74 WARNING: The build will continue in 5 seconds...
78 rm -rf ${BUILDDIR} ${TARGETDIR} ${DECTARGETDIR} \
79 ${MUXTARGETDIR} ${DEMUXTARGETDIR}
80 mkdir -p ${BUILDDIR} ${TARGETDIR}/Headers/ ${DECTARGETDIR}/Headers/ \
81 ${MUXTARGETDIR}/Headers/ ${DEMUXTARGETDIR}/Headers/
83 if [[ ! -e ${SRCDIR}/configure ]]; then
84 if ! (cd ${SRCDIR} && sh autogen.sh); then
86 Error creating configure script!
87 This script requires the autoconf/automake and libtool to build. MacPorts can
88 be used to obtain these:
89 https://www.macports.org/install.php
95 for PLATFORM in ${PLATFORMS}; do
97 if [[ "${PLATFORM}" == "iPhoneOS-V7-arm64" ]]; then
101 elif [[ "${PLATFORM}" == "iPhoneOS-V7s" ]]; then
104 elif [[ "${PLATFORM}" == "iPhoneOS-V7" ]]; then
107 elif [[ "${PLATFORM}" == "iPhoneOS-V6" ]]; then
110 elif [[ "${PLATFORM}" == "iPhoneSimulator64" ]]; then
111 PLATFORM="iPhoneSimulator"
117 ROOTDIR="${BUILDDIR}/${PLATFORM}-${SDK}-${ARCH}"
118 mkdir -p "${ROOTDIR}"
120 DEVROOT="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain"
121 SDKROOT="${PLATFORMSROOT}/"
122 SDKROOT+="${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDK}.sdk/"
123 CFLAGS="-arch ${ARCH2:-${ARCH}} -pipe -isysroot ${SDKROOT} -O3 -DNDEBUG"
124 CFLAGS+=" -miphoneos-version-min=${IOS_MIN_VERSION} ${EXTRA_CFLAGS}"
127 export PATH="${DEVROOT}/usr/bin:${OLDPATH}"
128 ${SRCDIR}/configure --host=${ARCH}-apple-darwin --prefix=${ROOTDIR} \
129 --build=$(${SRCDIR}/config.guess) \
130 --disable-shared --enable-static \
131 --enable-libwebpdecoder --enable-swap-16bit-csp \
132 --enable-libwebpmux \
136 # Build only the libraries, skip the examples.
138 make V=0 -C src install
140 LIBLIST+=" ${ROOTDIR}/lib/libwebp.a"
141 DECLIBLIST+=" ${ROOTDIR}/lib/libwebpdecoder.a"
142 MUXLIBLIST+=" ${ROOTDIR}/lib/libwebpmux.a"
143 DEMUXLIBLIST+=" ${ROOTDIR}/lib/libwebpdemux.a"
147 export PATH=${OLDPATH}
150 echo "LIBLIST = ${LIBLIST}"
151 cp -a ${SRCDIR}/src/webp/{decode,encode,types}.h ${TARGETDIR}/Headers/
152 ${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP
154 echo "DECLIBLIST = ${DECLIBLIST}"
155 cp -a ${SRCDIR}/src/webp/{decode,types}.h ${DECTARGETDIR}/Headers/
156 ${LIPO} -create ${DECLIBLIST} -output ${DECTARGETDIR}/WebPDecoder
158 echo "MUXLIBLIST = ${MUXLIBLIST}"
159 cp -a ${SRCDIR}/src/webp/{types,mux,mux_types}.h \
160 ${MUXTARGETDIR}/Headers/
161 ${LIPO} -create ${MUXLIBLIST} -output ${MUXTARGETDIR}/WebPMux
163 echo "DEMUXLIBLIST = ${DEMUXLIBLIST}"
164 cp -a ${SRCDIR}/src/webp/{decode,types,mux_types,demux}.h \
165 ${DEMUXTARGETDIR}/Headers/
166 ${LIPO} -create ${DEMUXLIBLIST} -output ${DEMUXTARGETDIR}/WebPDemux