3 ## Copyright (c) 2014 The WebM project authors. All Rights Reserved.
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.
12 ## This script generates 'VPX.framework'. An iOS app can encode and decode VPx
13 ## video by including 'VPX.framework'.
15 ## Run iosbuild.sh to create 'VPX.framework' in the current directory.
18 devnull='> /dev/null 2>&1'
20 BUILD_ROOT="_iosbuild"
21 CONFIGURE_ARGS="--disable-docs
26 FRAMEWORK_DIR="VPX.framework"
27 HEADER_DIR="${FRAMEWORK_DIR}/Headers/vpx"
29 SCRIPT_DIR=$(dirname "$0")
30 LIBVPX_SOURCE_DIR=$(cd ${SCRIPT_DIR}/../..; pwd)
31 LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo)
33 TARGETS="arm64-darwin-gcc
36 x86-iphonesimulator-gcc
37 x86_64-iphonesimulator-gcc"
39 # Configures for the target specified by $1, and invokes make with the dist
40 # target using $DIST_DIR as the distribution output directory.
43 local old_pwd="$(pwd)"
45 vlog "***Building target: ${target}***"
49 eval "${LIBVPX_SOURCE_DIR}/configure" --target="${target}" \
50 ${CONFIGURE_ARGS} ${EXTRA_CONFIGURE_ARGS} ${devnull}
52 eval make -j ${MAKE_JOBS} dist ${devnull}
55 vlog "***Done building target: ${target}***"
58 # Returns the preprocessor symbol for the target specified by $1.
59 target_to_preproc_symbol() {
66 echo "__ARM_ARCH_7A__"
69 echo "__ARM_ARCH_7S__"
78 echo "#error ${target} unknown/unsupported"
84 # Create a vpx_config.h shim that, based on preprocessor settings for the
85 # current target CPU, includes the real vpx_config.h for the current target.
86 # $1 is the list of targets.
87 create_vpx_framework_config_shim() {
89 local config_file="${HEADER_DIR}/vpx_config.h"
90 local preproc_symbol=""
92 local include_guard="VPX_FRAMEWORK_HEADERS_VPX_VPX_CONFIG_H_"
95 * Copyright (c) $(date +%Y) The WebM project authors. All Rights Reserved.
97 * Use of this source code is governed by a BSD-style license
98 * that can be found in the LICENSE file in the root of the source
99 * tree. An additional intellectual property rights grant can be found
100 * in the file PATENTS. All contributing project authors may
101 * be found in the AUTHORS file in the root of the source tree.
104 /* GENERATED FILE: DO NOT EDIT! */
106 #ifndef ${include_guard}
107 #define ${include_guard}
111 printf "%s" "${file_header}" > "${config_file}"
112 for target in ${targets}; do
113 preproc_symbol=$(target_to_preproc_symbol "${target}")
114 printf " ${preproc_symbol}\n" >> "${config_file}"
115 printf "#define VPX_FRAMEWORK_TARGET \"${target}\"\n" >> "${config_file}"
116 printf "#include \"VPX/vpx/${target}/vpx_config.h\"\n" >> "${config_file}"
117 printf "#elif defined" >> "${config_file}"
118 mkdir "${HEADER_DIR}/${target}"
119 cp -p "${BUILD_ROOT}/${target}/vpx_config.h" "${HEADER_DIR}/${target}"
122 # Consume the last line of output from the loop: We don't want it.
123 sed -i '' -e '$d' "${config_file}"
125 printf "#endif\n\n" >> "${config_file}"
126 printf "#endif // ${include_guard}" >> "${config_file}"
129 # Configures and builds each target specified by $1, and then builds
135 local target_dist_dir=""
137 # Clean up from previous build(s).
138 rm -rf "${BUILD_ROOT}" "${FRAMEWORK_DIR}"
140 # Create output dirs.
141 mkdir -p "${BUILD_ROOT}"
142 mkdir -p "${HEADER_DIR}"
146 for target in ${targets}; do
147 build_target "${target}"
148 target_dist_dir="${BUILD_ROOT}/${target}/${DIST_DIR}"
149 lib_list="${lib_list} ${target_dist_dir}/lib/libvpx.a"
154 # The basic libvpx API includes are all the same; just grab the most recent
156 cp -p "${target_dist_dir}"/include/vpx/* "${HEADER_DIR}"
158 # Build the fat library.
159 ${LIPO} -create ${lib_list} -output ${FRAMEWORK_DIR}/VPX
161 # Create the vpx_config.h shim that allows usage of vpx_config.h from
162 # within VPX.framework.
163 create_vpx_framework_config_shim "${targets}"
165 # Copy in vpx_version.h.
166 cp -p "${BUILD_ROOT}/${target}/vpx_version.h" "${HEADER_DIR}"
168 vlog "Created fat library ${FRAMEWORK_DIR}/VPX containing:"
169 for lib in ${lib_list}; do
170 vlog " $(echo ${lib} | awk -F / '{print $2, $NF}')"
173 # TODO(tomfinegan): Verify that expected targets are included within
174 # VPX.framework/VPX via lipo -info.
177 # Trap function. Cleans up the subtree used to build all targets contained in
180 local readonly res=$?
183 if [ $res -ne 0 ]; then
184 elog "build exited with error ($res)"
187 if [ "${PRESERVE_BUILD_OUTPUT}" != "yes" ]; then
188 rm -rf "${BUILD_ROOT}"
194 Usage: ${0##*/} [arguments]
195 --help: Display this message and exit.
196 --extra-configure-args <args>: Extra args to pass when configuring libvpx.
197 --jobs: Number of make jobs.
198 --preserve-build-output: Do not delete the build directory.
199 --show-build-output: Show output from each library build.
200 --targets <targets>: Override default target list. Defaults:
202 --verbose: Output information about the environment and each stage of the
208 echo "${0##*/} failed because: $@" 1>&2
212 if [ "${VERBOSE}" = "yes" ]; then
219 # Parse the command line.
220 while [ -n "$1" ]; do
222 --extra-configure-args)
223 EXTRA_CONFIGURE_ARGS="$2"
234 --preserve-build-output)
235 PRESERVE_BUILD_OUTPUT=yes
255 if [ "${VERBOSE}" = "yes" ]; then
257 BUILD_ROOT=${BUILD_ROOT}
259 CONFIGURE_ARGS=${CONFIGURE_ARGS}
260 EXTRA_CONFIGURE_ARGS=${EXTRA_CONFIGURE_ARGS}
261 FRAMEWORK_DIR=${FRAMEWORK_DIR}
262 HEADER_DIR=${HEADER_DIR}
263 MAKE_JOBS=${MAKE_JOBS}
264 PRESERVE_BUILD_OUTPUT=${PRESERVE_BUILD_OUTPUT}
265 LIBVPX_SOURCE_DIR=${LIBVPX_SOURCE_DIR}
272 build_framework "${TARGETS}"
273 echo "Successfully built '${FRAMEWORK_DIR}' for:"