• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
22cleanup() {
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
37trap cleanup EXIT
38
39check_dir libwebm
40
41iosbuild_usage() {
42cat << 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.
49EOF
50}
51
52# Extract the latest SDK version from the final field of the form: iphoneosX.Y
53readonly SDK=$(xcodebuild -showsdks \
54  | grep iphoneos | sort | tail -n 1 | awk '{print substr($NF, 9)}'
55)
56
57# Extract Xcode version.
58readonly XCODE=$(xcodebuild -version | grep Xcode | cut -d " " -f2)
59if [ -z "${XCODE}" ]; then
60  echo "Xcode not available"
61  exit 1
62fi
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.
66readonly 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"
75readonly PLATFORMS="iPhoneSimulator
76                    iPhoneSimulator64
77                    iPhoneOS-V7
78                    iPhoneOS-V7s
79                    iPhoneOS-V7-arm64"
80readonly TARGETDIR="WebM.framework"
81readonly DEVELOPER="$(xcode-select --print-path)"
82readonly PLATFORMSROOT="${DEVELOPER}/Platforms"
83readonly LIPO="$(xcrun -sdk iphoneos${SDK} -find lipo)"
84LIBLIST=""
85OPT_FLAGS="-DNDEBUG -O3"
86readonly SDK_MAJOR_VERSION="$(echo ${SDK} | awk -F '.' '{ print $1 }')"
87
88if [ -z "${SDK_MAJOR_VERSION}" ]; then
89  elog "iOS SDK not available"
90  exit 1
91elif [ "${SDK_MAJOR_VERSION}" -lt "6" ]; then
92  elog "You need iOS SDK version 6 or above"
93  exit 1
94else
95  vlog "iOS SDK Version ${SDK}"
96fi
97
98
99# Parse the command line.
100while [ -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
125done
126
127readonly OPT_FLAGS="${OPT_FLAGS}"
128readonly OUTDIR="${OUTDIR:-framework}"
129
130if [ "${VERBOSE}" = "yes" ]; then
131cat << 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}
140EOF
141fi
142
143rm -rf "${OUTDIR}/${TARGETDIR}"
144mkdir -p "${OUTDIR}/${TARGETDIR}/Headers/"
145
146for 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
179  # enable bitcode if available
180  if [ "${SDK_MAJOR_VERSION}" -gt 8 ]; then
181    CXXFLAGS="${CXXFLAGS} -fembed-bitcode"
182  fi
183
184  # Build using the legacy makefile (instead of generating via cmake).
185  eval make -f Makefile.unix libwebm.a CXXFLAGS=\"${CXXFLAGS}\" ${devnull}
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.
192  eval make -f Makefile.unix clean ${devnull}
193done
194
195# create include sub dirs in framework dir.
196readonly framework_header_dir="${OUTDIR}/${TARGETDIR}/Headers"
197readonly framework_header_sub_dirs="common mkvmuxer mkvparser"
198for dir in ${framework_header_sub_dirs}; do
199  mkdir "${framework_header_dir}/${dir}"
200done
201
202for header_file in ${INCLUDES}; do
203  eval cp -p ${header_file} "${framework_header_dir}/${header_file}" ${devnull}
204done
205
206eval ${LIPO} -create ${LIBLIST} -output "${OUTDIR}/${TARGETDIR}/WebM" ${devnull}
207echo "Succesfully built ${TARGETDIR} in ${OUTDIR}."
208