WebP.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/bin/bash
  2. #
  3. # This script generates 'WebP.framework' (static library).
  4. # An iOS app can decode WebP images by including 'WebP.framework'.
  5. #
  6. # 1. Download the latest libwebp source code from
  7. # http://downloads.webmproject.org/releases/webp/index.html
  8. # 2. Use this script instead of the original 'iosbuild.sh' to build the WebP.framework.
  9. # It will build all modules, include mux, demux, coder and decoder.
  10. #
  11. # Notice: You should use Xcode 7 (or above) to support bitcode.
  12. set -e
  13. # Extract the latest SDK version from the final field of the form: iphoneosX.Y
  14. readonly SDK=$(xcodebuild -showsdks \
  15. | grep iphoneos | sort | tail -n 1 | awk '{print substr($NF, 9)}'
  16. )
  17. # Extract Xcode version.
  18. readonly XCODE=$(xcodebuild -version | grep Xcode | cut -d " " -f2)
  19. if [[ -z "${XCODE}" ]]; then
  20. echo "Xcode not available"
  21. exit 1
  22. fi
  23. readonly OLDPATH=${PATH}
  24. # Add iPhoneOS-V6 to the list of platforms below if you need armv6 support.
  25. # Note that iPhoneOS-V6 support is not available with the iOS6 SDK.
  26. PLATFORMS="iPhoneSimulator iPhoneSimulator64"
  27. PLATFORMS+=" iPhoneOS-V7 iPhoneOS-V7s iPhoneOS-V7-arm64"
  28. readonly PLATFORMS
  29. readonly SRCDIR=$(dirname $0)
  30. readonly TOPDIR=$(pwd)
  31. readonly BUILDDIR="${TOPDIR}/iosbuild"
  32. readonly TARGETDIR="${TOPDIR}/WebP.framework"
  33. readonly DEVELOPER=$(xcode-select --print-path)
  34. readonly PLATFORMSROOT="${DEVELOPER}/Platforms"
  35. readonly LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo)
  36. LIBLIST=''
  37. if [[ -z "${SDK}" ]]; then
  38. echo "iOS SDK not available"
  39. exit 1
  40. else
  41. echo "iOS SDK Version ${SDK}"
  42. fi
  43. rm -rf ${BUILDDIR}
  44. rm -rf ${TARGETDIR}
  45. mkdir -p ${BUILDDIR}
  46. mkdir -p ${TARGETDIR}/Headers/
  47. if [[ ! -e ${SRCDIR}/configure ]]; then
  48. if ! (cd ${SRCDIR} && sh autogen.sh); then
  49. cat <<EOT
  50. Error creating configure script!
  51. This script requires the autoconf/automake and libtool to build. MacPorts can
  52. be used to obtain these:
  53. http://www.macports.org/install.php
  54. EOT
  55. exit 1
  56. fi
  57. fi
  58. for PLATFORM in ${PLATFORMS}; do
  59. ARCH2=""
  60. if [[ "${PLATFORM}" == "iPhoneOS-V7-arm64" ]]; then
  61. PLATFORM="iPhoneOS"
  62. ARCH="aarch64"
  63. ARCH2="arm64"
  64. elif [[ "${PLATFORM}" == "iPhoneOS-V7s" ]]; then
  65. PLATFORM="iPhoneOS"
  66. ARCH="armv7s"
  67. elif [[ "${PLATFORM}" == "iPhoneOS-V7" ]]; then
  68. PLATFORM="iPhoneOS"
  69. ARCH="armv7"
  70. elif [[ "${PLATFORM}" == "iPhoneOS-V6" ]]; then
  71. PLATFORM="iPhoneOS"
  72. ARCH="armv6"
  73. elif [[ "${PLATFORM}" == "iPhoneSimulator64" ]]; then
  74. PLATFORM="iPhoneSimulator"
  75. ARCH="x86_64"
  76. else
  77. ARCH="i386"
  78. fi
  79. ROOTDIR="${BUILDDIR}/${PLATFORM}-${SDK}-${ARCH}"
  80. mkdir -p "${ROOTDIR}"
  81. DEVROOT="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain"
  82. SDKROOT="${PLATFORMSROOT}/"
  83. SDKROOT+="${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDK}.sdk/"
  84. CFLAGS="-arch ${ARCH2:-${ARCH}} -pipe -isysroot ${SDKROOT} -O3 -DNDEBUG"
  85. CFLAGS+=" -miphoneos-version-min=6.0 -fembed-bitcode"
  86. set -x
  87. export PATH="${DEVROOT}/usr/bin:${OLDPATH}"
  88. ${SRCDIR}/configure --host=${ARCH}-apple-darwin --prefix=${ROOTDIR} \
  89. --build=$(${SRCDIR}/config.guess) \
  90. --disable-shared --enable-static \
  91. --enable-libwebpmux \
  92. --enable-libwebpdemux \
  93. --enable-swap-16bit-csp \
  94. CFLAGS="${CFLAGS}"
  95. set +x
  96. # run make only in the src/ directory to create libwebpdecoder.a
  97. cd src/
  98. make V=0
  99. make install
  100. MAKEPATH=$(pwd)
  101. cd ${ROOTDIR}/lib/
  102. ar x libwebp.a
  103. ar x libwebpmux.a
  104. ar x libwebpdemux.a
  105. ar q webp.a *.o
  106. LIBLIST+=" ${ROOTDIR}/lib/webp.a"
  107. cd ${MAKEPATH}
  108. make clean
  109. cd ..
  110. export PATH=${OLDPATH}
  111. done
  112. cp -a ${SRCDIR}/src/webp/*.h ${TARGETDIR}/Headers/
  113. ${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP