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)"
44 local target_specific_flags=""
46 vlog "***Building target: ${target}***"
50 target_specific_flags="--enable-pic"
51 vlog "Enabled PIC for ${target}"
57 eval "${LIBVPX_SOURCE_DIR}/configure" --target="${target}" \
58 ${CONFIGURE_ARGS} ${EXTRA_CONFIGURE_ARGS} ${target_specific_flags} \
61 eval make -j ${MAKE_JOBS} dist ${devnull}
64 vlog "***Done building target: ${target}***"
67 # Returns the preprocessor symbol for the target specified by $1.
68 target_to_preproc_symbol() {
75 echo "__ARM_ARCH_7A__"
78 echo "__ARM_ARCH_7S__"
87 echo "#error ${target} unknown/unsupported"
93 # Create a vpx_config.h shim that, based on preprocessor settings for the
94 # current target CPU, includes the real vpx_config.h for the current target.
95 # $1 is the list of targets.
96 create_vpx_framework_config_shim() {
98 local config_file="${HEADER_DIR}/vpx_config.h"
99 local preproc_symbol=""
101 local include_guard="VPX_FRAMEWORK_HEADERS_VPX_VPX_CONFIG_H_"
103 local file_header="/*
104 * Copyright (c) $(date +%Y) The WebM project authors. All Rights Reserved.
106 * Use of this source code is governed by a BSD-style license
107 * that can be found in the LICENSE file in the root of the source
108 * tree. An additional intellectual property rights grant can be found
109 * in the file PATENTS. All contributing project authors may
110 * be found in the AUTHORS file in the root of the source tree.
113 /* GENERATED FILE: DO NOT EDIT! */
115 #ifndef ${include_guard}
116 #define ${include_guard}
120 printf "%s" "${file_header}" > "${config_file}"
121 for target in ${targets}; do
122 preproc_symbol=$(target_to_preproc_symbol "${target}")
123 printf " ${preproc_symbol}\n" >> "${config_file}"
124 printf "#define VPX_FRAMEWORK_TARGET \"${target}\"\n" >> "${config_file}"
125 printf "#include \"VPX/vpx/${target}/vpx_config.h\"\n" >> "${config_file}"
126 printf "#elif defined" >> "${config_file}"
127 mkdir "${HEADER_DIR}/${target}"
128 cp -p "${BUILD_ROOT}/${target}/vpx_config.h" "${HEADER_DIR}/${target}"
131 # Consume the last line of output from the loop: We don't want it.
132 sed -i '' -e '$d' "${config_file}"
134 printf "#endif\n\n" >> "${config_file}"
135 printf "#endif // ${include_guard}" >> "${config_file}"
138 # Configures and builds each target specified by $1, and then builds
144 local target_dist_dir=""
146 # Clean up from previous build(s).
147 rm -rf "${BUILD_ROOT}" "${FRAMEWORK_DIR}"
149 # Create output dirs.
150 mkdir -p "${BUILD_ROOT}"
151 mkdir -p "${HEADER_DIR}"
155 for target in ${targets}; do
156 build_target "${target}"
157 target_dist_dir="${BUILD_ROOT}/${target}/${DIST_DIR}"
158 lib_list="${lib_list} ${target_dist_dir}/lib/libvpx.a"
163 # The basic libvpx API includes are all the same; just grab the most recent
165 cp -p "${target_dist_dir}"/include/vpx/* "${HEADER_DIR}"
167 # Build the fat library.
168 ${LIPO} -create ${lib_list} -output ${FRAMEWORK_DIR}/VPX
170 # Create the vpx_config.h shim that allows usage of vpx_config.h from
171 # within VPX.framework.
172 create_vpx_framework_config_shim "${targets}"
174 # Copy in vpx_version.h.
175 cp -p "${BUILD_ROOT}/${target}/vpx_version.h" "${HEADER_DIR}"
177 vlog "Created fat library ${FRAMEWORK_DIR}/VPX containing:"
178 for lib in ${lib_list}; do
179 vlog " $(echo ${lib} | awk -F / '{print $2, $NF}')"
182 # TODO(tomfinegan): Verify that expected targets are included within
183 # VPX.framework/VPX via lipo -info.
186 # Trap function. Cleans up the subtree used to build all targets contained in
189 local readonly res=$?
192 if [ $res -ne 0 ]; then
193 elog "build exited with error ($res)"
196 if [ "${PRESERVE_BUILD_OUTPUT}" != "yes" ]; then
197 rm -rf "${BUILD_ROOT}"
203 Usage: ${0##*/} [arguments]
204 --help: Display this message and exit.
205 --extra-configure-args <args>: Extra args to pass when configuring libvpx.
206 --jobs: Number of make jobs.
207 --preserve-build-output: Do not delete the build directory.
208 --show-build-output: Show output from each library build.
209 --targets <targets>: Override default target list. Defaults:
211 --test-link: Confirms all targets can be linked. Functionally identical to
212 passing --enable-examples via --extra-configure-args.
213 --verbose: Output information about the environment and each stage of the
219 echo "${0##*/} failed because: $@" 1>&2
223 if [ "${VERBOSE}" = "yes" ]; then
230 # Parse the command line.
231 while [ -n "$1" ]; do
233 --extra-configure-args)
234 EXTRA_CONFIGURE_ARGS="$2"
245 --preserve-build-output)
246 PRESERVE_BUILD_OUTPUT=yes
252 EXTRA_CONFIGURE_ARGS="${EXTRA_CONFIGURE_ARGS} --enable-examples"
269 if [ "${VERBOSE}" = "yes" ]; then
271 BUILD_ROOT=${BUILD_ROOT}
273 CONFIGURE_ARGS=${CONFIGURE_ARGS}
274 EXTRA_CONFIGURE_ARGS=${EXTRA_CONFIGURE_ARGS}
275 FRAMEWORK_DIR=${FRAMEWORK_DIR}
276 HEADER_DIR=${HEADER_DIR}
277 MAKE_JOBS=${MAKE_JOBS}
278 PRESERVE_BUILD_OUTPUT=${PRESERVE_BUILD_OUTPUT}
279 LIBVPX_SOURCE_DIR=${LIBVPX_SOURCE_DIR}
286 build_framework "${TARGETS}"
287 echo "Successfully built '${FRAMEWORK_DIR}' for:"