2013-01-24 23:25:58 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# This script generates 'WebP.framework'. An iOS app can decode WebP images
|
|
|
|
# by including 'WebP.framework'.
|
|
|
|
#
|
|
|
|
# Run ./iosbuild.sh to generate 'WebP.framework' under the current directory
|
|
|
|
# (previous build will be erased if it exists).
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
declare -r 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.
|
|
|
|
declare -r XCODE=$(xcodebuild -version | grep Xcode | cut -d " " -f2)
|
|
|
|
|
2013-01-24 23:25:58 +01:00
|
|
|
declare -r OLDPATH=${PATH}
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
declare -r PLATFORMS="iPhoneSimulator iPhoneOS-V7 iPhoneOS-V7s"
|
|
|
|
declare -r SRCDIR=$(dirname $0)
|
|
|
|
declare -r TOPDIR=$(pwd)
|
|
|
|
declare -r BUILDDIR="${TOPDIR}/iosbuild"
|
|
|
|
declare -r TARGETDIR="${TOPDIR}/WebP.framework"
|
|
|
|
declare -r DEVELOPER=$(xcode-select --print-path)
|
|
|
|
declare -r PLATFORMSROOT="${DEVELOPER}/Platforms"
|
|
|
|
declare -r LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo)
|
|
|
|
LIBLIST=''
|
|
|
|
|
|
|
|
if [[ -z "${SDK}" ]]; then
|
|
|
|
echo "iOS SDK not available"
|
|
|
|
exit 1
|
|
|
|
elif [[ ${SDK} < 4.0 ]]; then
|
|
|
|
echo "You need iOS SDK version 4.0 or above"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "iOS SDK Version ${SDK}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -rf ${BUILDDIR}
|
|
|
|
rm -rf ${TARGETDIR}
|
|
|
|
mkdir -p ${BUILDDIR}
|
|
|
|
mkdir -p ${TARGETDIR}/Headers/
|
|
|
|
|
|
|
|
[[ -e ${SRCDIR}/configure ]] || (cd ${SRCDIR} && sh autogen.sh)
|
|
|
|
|
|
|
|
for PLATFORM in ${PLATFORMS}; do
|
|
|
|
if [[ "${PLATFORM}" == "iPhoneOS-V7s" ]]; then
|
|
|
|
PLATFORM="iPhoneOS"
|
|
|
|
ARCH="armv7s"
|
|
|
|
elif [[ "${PLATFORM}" == "iPhoneOS-V7" ]]; then
|
|
|
|
PLATFORM="iPhoneOS"
|
|
|
|
ARCH="armv7"
|
|
|
|
elif [[ "${PLATFORM}" == "iPhoneOS-V6" ]]; then
|
|
|
|
PLATFORM="iPhoneOS"
|
|
|
|
ARCH="armv6"
|
|
|
|
else
|
|
|
|
ARCH="i386"
|
|
|
|
fi
|
|
|
|
|
|
|
|
ROOTDIR="${BUILDDIR}/${PLATFORM}-${SDK}-${ARCH}"
|
|
|
|
mkdir -p "${ROOTDIR}"
|
|
|
|
|
2013-11-27 00:13:03 +01:00
|
|
|
SDKROOT="${PLATFORMSROOT}/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDK}.sdk/"
|
|
|
|
CFLAGS="-arch ${ARCH} -pipe -isysroot ${SDKROOT}"
|
|
|
|
LDFLAGS="-arch ${ARCH} -pipe -isysroot ${SDKROOT}"
|
|
|
|
|
|
|
|
if [[ -z "${XCODE}" ]]; then
|
|
|
|
echo "XCODE not available"
|
|
|
|
exit 1
|
|
|
|
elif [[ ${SDK} < 5.0.0 ]]; then
|
|
|
|
DEVROOT="${PLATFORMSROOT}/${PLATFORM}.platform/Developer/"
|
|
|
|
else
|
|
|
|
DEVROOT="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain"
|
|
|
|
CFLAGS+=" -miphoneos-version-min=5.0"
|
|
|
|
LDFLAGS+=" -miphoneos-version-min=5.0"
|
|
|
|
fi
|
2013-01-24 23:25:58 +01:00
|
|
|
|
2013-11-27 00:13:03 +01:00
|
|
|
export CFLAGS
|
|
|
|
export LDFLAGS
|
2013-01-24 23:25:58 +01:00
|
|
|
export CXXFLAGS=${CFLAGS}
|
|
|
|
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 \
|
|
|
|
--enable-libwebpdecoder --enable-swap-16bit-csp
|
|
|
|
|
|
|
|
# run make only in the src/ directory to create libwebpdecoder.a
|
|
|
|
cd src/
|
2013-01-26 01:06:21 +01:00
|
|
|
make V=0
|
2013-01-24 23:25:58 +01:00
|
|
|
make install
|
|
|
|
|
|
|
|
LIBLIST+=" ${ROOTDIR}/lib/libwebpdecoder.a"
|
|
|
|
|
|
|
|
make clean
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
export PATH=${OLDPATH}
|
|
|
|
done
|
|
|
|
|
2013-01-26 01:06:21 +01:00
|
|
|
cp -a ${SRCDIR}/src/webp/* ${TARGETDIR}/Headers/
|
2013-01-24 23:25:58 +01:00
|
|
|
${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP
|