2013-01-24 23:25:58 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2016-12-10 04:08:53 +01:00
|
|
|
# This script generates 'WebP.framework' and 'WebPDecoder.framework'. An iOS
|
|
|
|
# app can decode WebP images by including 'WebPDecoder.framework' and both
|
|
|
|
# encode and decode WebP images by including 'WebP.framework'.
|
2013-01-24 23:25:58 +01:00
|
|
|
#
|
2016-12-10 04:08:53 +01:00
|
|
|
# Run ./iosbuild.sh to generate the frameworks under the current directory
|
|
|
|
# (the previous build will be erased if it exists).
|
2013-01-24 23:25:58 +01:00
|
|
|
#
|
|
|
|
# This script is inspired by the build script written by Carson McDonald.
|
|
|
|
# (http://www.ioncannon.net/programming/1483/using-webp-to-reduce-native-ios-app-size/).
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Extract the latest SDK version from the final field of the form: iphoneosX.Y
|
2014-09-27 04:28:45 +02:00
|
|
|
readonly SDK=$(xcodebuild -showsdks \
|
2013-01-26 01:06:21 +01:00
|
|
|
| grep iphoneos | sort | tail -n 1 | awk '{print substr($NF, 9)}'
|
2013-01-24 23:25:58 +01:00
|
|
|
)
|
2013-11-27 00:13:03 +01:00
|
|
|
# Extract Xcode version.
|
2014-09-27 04:28:45 +02:00
|
|
|
readonly XCODE=$(xcodebuild -version | grep Xcode | cut -d " " -f2)
|
|
|
|
if [[ -z "${XCODE}" ]]; then
|
|
|
|
echo "Xcode not available"
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-11-27 00:13:03 +01:00
|
|
|
|
2014-09-27 04:28:45 +02:00
|
|
|
readonly OLDPATH=${PATH}
|
2013-01-24 23:25:58 +01:00
|
|
|
|
|
|
|
# Add iPhoneOS-V6 to the list of platforms below if you need armv6 support.
|
|
|
|
# Note that iPhoneOS-V6 support is not available with the iOS6 SDK.
|
2014-11-15 01:38:42 +01:00
|
|
|
PLATFORMS="iPhoneSimulator iPhoneSimulator64"
|
|
|
|
PLATFORMS+=" iPhoneOS-V7 iPhoneOS-V7s iPhoneOS-V7-arm64"
|
|
|
|
readonly PLATFORMS
|
2014-09-27 04:28:45 +02:00
|
|
|
readonly SRCDIR=$(dirname $0)
|
|
|
|
readonly TOPDIR=$(pwd)
|
|
|
|
readonly BUILDDIR="${TOPDIR}/iosbuild"
|
|
|
|
readonly TARGETDIR="${TOPDIR}/WebP.framework"
|
2016-12-10 04:08:53 +01:00
|
|
|
readonly DECTARGETDIR="${TOPDIR}/WebPDecoder.framework"
|
2014-09-27 04:28:45 +02:00
|
|
|
readonly DEVELOPER=$(xcode-select --print-path)
|
|
|
|
readonly PLATFORMSROOT="${DEVELOPER}/Platforms"
|
|
|
|
readonly LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo)
|
2013-01-24 23:25:58 +01:00
|
|
|
LIBLIST=''
|
2016-12-10 04:08:53 +01:00
|
|
|
DECLIBLIST=''
|
2013-01-24 23:25:58 +01:00
|
|
|
|
|
|
|
if [[ -z "${SDK}" ]]; then
|
|
|
|
echo "iOS SDK not available"
|
|
|
|
exit 1
|
2015-10-08 03:16:12 +02:00
|
|
|
elif [[ ${SDK%%.*} -gt 8 ]]; then
|
|
|
|
EXTRA_CFLAGS="-fembed-bitcode"
|
2014-09-25 04:42:53 +02:00
|
|
|
elif [[ ${SDK} < 6.0 ]]; then
|
|
|
|
echo "You need iOS SDK version 6.0 or above"
|
2013-01-24 23:25:58 +01:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "iOS SDK Version ${SDK}"
|
|
|
|
fi
|
|
|
|
|
2016-12-10 04:08:53 +01:00
|
|
|
rm -rf ${BUILDDIR} ${TARGETDIR} ${DECTARGETDIR}
|
|
|
|
mkdir -p ${BUILDDIR} ${TARGETDIR}/Headers/ ${DECTARGETDIR}/Headers/
|
2013-01-24 23:25:58 +01:00
|
|
|
|
2014-09-26 08:44:45 +02:00
|
|
|
if [[ ! -e ${SRCDIR}/configure ]]; then
|
|
|
|
if ! (cd ${SRCDIR} && sh autogen.sh); then
|
|
|
|
cat <<EOT
|
|
|
|
Error creating configure script!
|
|
|
|
This script requires the autoconf/automake and libtool to build. MacPorts can
|
|
|
|
be used to obtain these:
|
|
|
|
http://www.macports.org/install.php
|
|
|
|
EOT
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2013-01-24 23:25:58 +01:00
|
|
|
|
|
|
|
for PLATFORM in ${PLATFORMS}; do
|
2014-05-03 05:33:01 +02:00
|
|
|
ARCH2=""
|
|
|
|
if [[ "${PLATFORM}" == "iPhoneOS-V7-arm64" ]]; then
|
|
|
|
PLATFORM="iPhoneOS"
|
|
|
|
ARCH="aarch64"
|
|
|
|
ARCH2="arm64"
|
|
|
|
elif [[ "${PLATFORM}" == "iPhoneOS-V7s" ]]; then
|
2013-01-24 23:25:58 +01:00
|
|
|
PLATFORM="iPhoneOS"
|
|
|
|
ARCH="armv7s"
|
|
|
|
elif [[ "${PLATFORM}" == "iPhoneOS-V7" ]]; then
|
|
|
|
PLATFORM="iPhoneOS"
|
|
|
|
ARCH="armv7"
|
|
|
|
elif [[ "${PLATFORM}" == "iPhoneOS-V6" ]]; then
|
|
|
|
PLATFORM="iPhoneOS"
|
|
|
|
ARCH="armv6"
|
2014-11-15 01:38:42 +01:00
|
|
|
elif [[ "${PLATFORM}" == "iPhoneSimulator64" ]]; then
|
|
|
|
PLATFORM="iPhoneSimulator"
|
|
|
|
ARCH="x86_64"
|
2013-01-24 23:25:58 +01:00
|
|
|
else
|
|
|
|
ARCH="i386"
|
|
|
|
fi
|
|
|
|
|
|
|
|
ROOTDIR="${BUILDDIR}/${PLATFORM}-${SDK}-${ARCH}"
|
|
|
|
mkdir -p "${ROOTDIR}"
|
|
|
|
|
2014-09-27 04:28:45 +02:00
|
|
|
DEVROOT="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain"
|
|
|
|
SDKROOT="${PLATFORMSROOT}/"
|
|
|
|
SDKROOT+="${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDK}.sdk/"
|
2014-07-27 05:40:51 +02:00
|
|
|
CFLAGS="-arch ${ARCH2:-${ARCH}} -pipe -isysroot ${SDKROOT} -O3 -DNDEBUG"
|
2015-10-08 03:16:12 +02:00
|
|
|
CFLAGS+=" -miphoneos-version-min=6.0 ${EXTRA_CFLAGS}"
|
2013-11-27 00:13:03 +01:00
|
|
|
|
2014-09-27 04:28:45 +02:00
|
|
|
set -x
|
2013-01-24 23:25:58 +01:00
|
|
|
export PATH="${DEVROOT}/usr/bin:${OLDPATH}"
|
|
|
|
${SRCDIR}/configure --host=${ARCH}-apple-darwin --prefix=${ROOTDIR} \
|
2013-01-26 01:06:21 +01:00
|
|
|
--build=$(${SRCDIR}/config.guess) \
|
2013-01-24 23:25:58 +01:00
|
|
|
--disable-shared --enable-static \
|
2014-09-27 04:28:45 +02:00
|
|
|
--enable-libwebpdecoder --enable-swap-16bit-csp \
|
|
|
|
CFLAGS="${CFLAGS}"
|
|
|
|
set +x
|
2013-01-24 23:25:58 +01:00
|
|
|
|
2016-12-10 04:08:53 +01:00
|
|
|
# run make only in the src/ directory to create libwebp.a/libwebpdecoder.a
|
2013-01-24 23:25:58 +01:00
|
|
|
cd src/
|
2013-01-26 01:06:21 +01:00
|
|
|
make V=0
|
2013-01-24 23:25:58 +01:00
|
|
|
make install
|
|
|
|
|
2016-12-10 04:08:53 +01:00
|
|
|
LIBLIST+=" ${ROOTDIR}/lib/libwebp.a"
|
|
|
|
DECLIBLIST+=" ${ROOTDIR}/lib/libwebpdecoder.a"
|
2013-01-24 23:25:58 +01:00
|
|
|
|
|
|
|
make clean
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
export PATH=${OLDPATH}
|
|
|
|
done
|
|
|
|
|
2017-01-19 21:50:37 +01:00
|
|
|
cp -a ${SRCDIR}/src/webp/{decode,encode,types}.h ${TARGETDIR}/Headers/
|
2013-01-24 23:25:58 +01:00
|
|
|
${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP
|
2016-12-10 04:08:53 +01:00
|
|
|
|
2017-01-19 21:50:37 +01:00
|
|
|
cp -a ${SRCDIR}/src/webp/{decode,types}.h ${DECTARGETDIR}/Headers/
|
2016-12-10 04:08:53 +01:00
|
|
|
${LIPO} -create ${DECLIBLIST} -output ${DECTARGETDIR}/WebPDecoder
|