Tom Finegan | 4baaa2c | 2015-05-06 10:33:48 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | ## |
| 3 | ## Copyright (c) 2015 The WebM project authors. All Rights Reserved. |
| 4 | ## |
| 5 | ## Use of this source code is governed by a BSD-style license |
| 6 | ## that can be found in the LICENSE file in the root of the source |
| 7 | ## tree. An additional intellectual property rights grant can be found |
| 8 | ## in the file PATENTS. All contributing project authors may |
| 9 | ## be found in the AUTHORS file in the root of the source tree. |
| 10 | ## |
| 11 | ## This script generates 'WebM.framework'. An iOS app can mux/demux WebM |
| 12 | ## container files by including 'WebM.framework'. |
| 13 | ## |
| 14 | ## Run ./iosbuild.sh to generate 'WebM.framework'. By default the framework |
| 15 | ## bundle will be created in a directory called framework. Use --out-dir to |
| 16 | ## change the output directory. |
| 17 | ## |
| 18 | ## This script is based on iosbuild.sh from the libwebp project. |
| 19 | . $(dirname $0)/common/common.sh |
| 20 | |
| 21 | # Trap function. Cleans up build output. |
| 22 | cleanup() { |
| 23 | local readonly res=$? |
| 24 | cd "${ORIG_PWD}" |
| 25 | |
| 26 | for dir in ${LIBDIRS}; do |
| 27 | if [ -d "${dir}" ]; then |
| 28 | rm -rf "${dir}" |
| 29 | fi |
| 30 | done |
| 31 | |
| 32 | if [ $res -ne 0 ]; then |
| 33 | elog "build exited with error ($res)" |
| 34 | fi |
| 35 | } |
| 36 | |
| 37 | trap cleanup EXIT |
| 38 | |
| 39 | check_dir libwebm |
| 40 | |
| 41 | iosbuild_usage() { |
| 42 | cat << EOF |
| 43 | Usage: ${0##*/} [arguments] |
| 44 | --help: Display this message and exit. |
| 45 | --out-dir: Override output directory (default is ${OUTDIR}). |
| 46 | --show-build-output: Show output from each library build. |
| 47 | --verbose: Output information about the environment and each stage of the |
| 48 | build. |
| 49 | EOF |
| 50 | } |
| 51 | |
| 52 | # Extract the latest SDK version from the final field of the form: iphoneosX.Y |
| 53 | readonly SDK=$(xcodebuild -showsdks \ |
| 54 | | grep iphoneos | sort | tail -n 1 | awk '{print substr($NF, 9)}' |
| 55 | ) |
| 56 | |
| 57 | # Extract Xcode version. |
| 58 | readonly XCODE=$(xcodebuild -version | grep Xcode | cut -d " " -f2) |
| 59 | if [ -z "${XCODE}" ]; then |
| 60 | echo "Xcode not available" |
| 61 | exit 1 |
| 62 | fi |
| 63 | |
| 64 | # Add iPhoneOS-V6 to the list of platforms below if you need armv6 support. |
| 65 | # Note that iPhoneOS-V6 support is not available with the iOS6 SDK. |
Tom Finegan | 2e0e906 | 2016-03-23 10:09:59 -0700 | [diff] [blame] | 66 | readonly INCLUDES="common/file_util.h |
| 67 | common/hdr_util.h |
| 68 | common/webmids.h |
| 69 | mkvmuxer/mkvmuxer.h |
| 70 | mkvmuxer/mkvmuxertypes.h |
| 71 | mkvmuxer/mkvmuxerutil.h |
| 72 | mkvmuxer/mkvwriter.h |
| 73 | mkvparser/mkvparser.h |
| 74 | mkvparser/mkvreader.h" |
Tom Finegan | 4baaa2c | 2015-05-06 10:33:48 -0700 | [diff] [blame] | 75 | readonly PLATFORMS="iPhoneSimulator |
| 76 | iPhoneSimulator64 |
| 77 | iPhoneOS-V7 |
| 78 | iPhoneOS-V7s |
| 79 | iPhoneOS-V7-arm64" |
| 80 | readonly TARGETDIR="WebM.framework" |
| 81 | readonly DEVELOPER="$(xcode-select --print-path)" |
| 82 | readonly PLATFORMSROOT="${DEVELOPER}/Platforms" |
| 83 | readonly LIPO="$(xcrun -sdk iphoneos${SDK} -find lipo)" |
| 84 | LIBLIST="" |
| 85 | OPT_FLAGS="-DNDEBUG -O3" |
| 86 | readonly SDK_MAJOR_VERSION="$(echo ${SDK} | awk -F '.' '{ print $1 }')" |
| 87 | |
| 88 | if [ -z "${SDK_MAJOR_VERSION}" ]; then |
| 89 | elog "iOS SDK not available" |
| 90 | exit 1 |
| 91 | elif [ "${SDK_MAJOR_VERSION}" -lt "6" ]; then |
| 92 | elog "You need iOS SDK version 6 or above" |
| 93 | exit 1 |
| 94 | else |
| 95 | vlog "iOS SDK Version ${SDK}" |
| 96 | fi |
| 97 | |
| 98 | |
| 99 | # Parse the command line. |
| 100 | while [ -n "$1" ]; do |
| 101 | case "$1" in |
| 102 | --help) |
| 103 | iosbuild_usage |
| 104 | exit |
| 105 | ;; |
| 106 | --out-dir) |
| 107 | OUTDIR="$2" |
| 108 | shift |
| 109 | ;; |
| 110 | --enable-debug) |
| 111 | OPT_FLAGS="-g" |
| 112 | ;; |
| 113 | --show-build-output) |
| 114 | devnull= |
| 115 | ;; |
| 116 | --verbose) |
| 117 | VERBOSE=yes |
| 118 | ;; |
| 119 | *) |
| 120 | iosbuild_usage |
| 121 | exit 1 |
| 122 | ;; |
| 123 | esac |
| 124 | shift |
| 125 | done |
| 126 | |
| 127 | readonly OPT_FLAGS="${OPT_FLAGS}" |
| 128 | readonly OUTDIR="${OUTDIR:-framework}" |
| 129 | |
| 130 | if [ "${VERBOSE}" = "yes" ]; then |
| 131 | cat << EOF |
| 132 | OUTDIR=${OUTDIR} |
| 133 | INCLUDES=${INCLUDES} |
| 134 | PLATFORMS=${PLATFORMS} |
| 135 | TARGETDIR=${TARGETDIR} |
| 136 | DEVELOPER=${DEVELOPER} |
| 137 | LIPO=${LIPO} |
| 138 | OPT_FLAGS=${OPT_FLAGS} |
| 139 | ORIG_PWD=${ORIG_PWD} |
| 140 | EOF |
| 141 | fi |
| 142 | |
| 143 | rm -rf "${OUTDIR}/${TARGETDIR}" |
| 144 | mkdir -p "${OUTDIR}/${TARGETDIR}/Headers/" |
| 145 | |
| 146 | for PLATFORM in ${PLATFORMS}; do |
| 147 | ARCH2="" |
| 148 | if [ "${PLATFORM}" = "iPhoneOS-V7-arm64" ]; then |
| 149 | PLATFORM="iPhoneOS" |
| 150 | ARCH="aarch64" |
| 151 | ARCH2="arm64" |
| 152 | elif [ "${PLATFORM}" = "iPhoneOS-V7s" ]; then |
| 153 | PLATFORM="iPhoneOS" |
| 154 | ARCH="armv7s" |
| 155 | elif [ "${PLATFORM}" = "iPhoneOS-V7" ]; then |
| 156 | PLATFORM="iPhoneOS" |
| 157 | ARCH="armv7" |
| 158 | elif [ "${PLATFORM}" = "iPhoneOS-V6" ]; then |
| 159 | PLATFORM="iPhoneOS" |
| 160 | ARCH="armv6" |
| 161 | elif [ "${PLATFORM}" = "iPhoneSimulator64" ]; then |
| 162 | PLATFORM="iPhoneSimulator" |
| 163 | ARCH="x86_64" |
| 164 | else |
| 165 | ARCH="i386" |
| 166 | fi |
| 167 | |
| 168 | LIBDIR="${OUTDIR}/${PLATFORM}-${SDK}-${ARCH}" |
| 169 | LIBDIRS="${LIBDIRS} ${LIBDIR}" |
| 170 | LIBFILE="${LIBDIR}/libwebm.a" |
| 171 | eval mkdir -p "${LIBDIR}" ${devnull} |
| 172 | |
| 173 | DEVROOT="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain" |
| 174 | SDKROOT="${PLATFORMSROOT}/" |
| 175 | SDKROOT="${SDKROOT}${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDK}.sdk/" |
| 176 | CXXFLAGS="-arch ${ARCH2:-${ARCH}} -isysroot ${SDKROOT} ${OPT_FLAGS} |
| 177 | -miphoneos-version-min=6.0" |
| 178 | |
TETRA2000 | 0cfb2dc | 2016-01-23 18:39:47 +0900 | [diff] [blame] | 179 | # enable bitcode if available |
| 180 | if [ "${SDK_MAJOR_VERSION}" -gt 8 ]; then |
| 181 | CXXFLAGS="${CXXFLAGS} -fembed-bitcode" |
| 182 | fi |
| 183 | |
Tom Finegan | 4baaa2c | 2015-05-06 10:33:48 -0700 | [diff] [blame] | 184 | # Build using the legacy makefile (instead of generating via cmake). |
Rob Gaunt | 7f7d898 | 2015-08-21 12:27:30 -0700 | [diff] [blame] | 185 | eval make -f Makefile.unix libwebm.a CXXFLAGS=\"${CXXFLAGS}\" ${devnull} |
Tom Finegan | 4baaa2c | 2015-05-06 10:33:48 -0700 | [diff] [blame] | 186 | |
| 187 | # copy lib and add it to LIBLIST. |
| 188 | eval cp libwebm.a "${LIBFILE}" ${devnull} |
| 189 | LIBLIST="${LIBLIST} ${LIBFILE}" |
| 190 | |
| 191 | # clean build so we can go again. |
Rob Gaunt | 7f7d898 | 2015-08-21 12:27:30 -0700 | [diff] [blame] | 192 | eval make -f Makefile.unix clean ${devnull} |
Tom Finegan | 4baaa2c | 2015-05-06 10:33:48 -0700 | [diff] [blame] | 193 | done |
| 194 | |
Tom Finegan | 2e0e906 | 2016-03-23 10:09:59 -0700 | [diff] [blame] | 195 | # create include sub dirs in framework dir. |
| 196 | readonly framework_header_dir="${OUTDIR}/${TARGETDIR}/Headers" |
| 197 | readonly framework_header_sub_dirs="common mkvmuxer mkvparser" |
| 198 | for dir in ${framework_header_sub_dirs}; do |
| 199 | mkdir "${framework_header_dir}/${dir}" |
| 200 | done |
| 201 | |
| 202 | for header_file in ${INCLUDES}; do |
| 203 | eval cp -p ${header_file} "${framework_header_dir}/${header_file}" ${devnull} |
Tom Finegan | 4baaa2c | 2015-05-06 10:33:48 -0700 | [diff] [blame] | 204 | done |
| 205 | |
| 206 | eval ${LIPO} -create ${LIBLIST} -output "${OUTDIR}/${TARGETDIR}/WebM" ${devnull} |
| 207 | echo "Succesfully built ${TARGETDIR} in ${OUTDIR}." |