OLD | NEW |
(Empty) | |
| 1 #!/bin/sh |
| 2 ## |
| 3 ## Copyright (c) 2014 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 ## |
| 12 ## This script generates 'VPX.framework'. An iOS app can encode and decode VPx |
| 13 ## video by including 'VPX.framework'. |
| 14 ## |
| 15 ## Run iosbuild.sh to create 'VPX.framework' in the current directory. |
| 16 ## |
| 17 set -e |
| 18 devnull='> /dev/null 2>&1' |
| 19 |
| 20 BUILD_ROOT="_iosbuild" |
| 21 DIST_DIR="_dist" |
| 22 FRAMEWORK_DIR="VPX.framework" |
| 23 HEADER_DIR="${FRAMEWORK_DIR}/Headers/vpx" |
| 24 MAKE_JOBS=1 |
| 25 LIBVPX_SOURCE_DIR=$(dirname "$0" | sed -e s,/build/make,,) |
| 26 LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo) |
| 27 ORIG_PWD="$(pwd)" |
| 28 TARGETS="armv6-darwin-gcc |
| 29 armv7-darwin-gcc |
| 30 armv7s-darwin-gcc |
| 31 x86-iphonesimulator-gcc |
| 32 x86_64-iphonesimulator-gcc" |
| 33 |
| 34 # Configures for the target specified by $1, and invokes make with the dist |
| 35 # target using $DIST_DIR as the distribution output directory. |
| 36 build_target() { |
| 37 local target="$1" |
| 38 local old_pwd="$(pwd)" |
| 39 |
| 40 vlog "***Building target: ${target}***" |
| 41 |
| 42 mkdir "${target}" |
| 43 cd "${target}" |
| 44 eval "../../${LIBVPX_SOURCE_DIR}/configure" --target="${target}" \ |
| 45 --disable-docs ${devnull} |
| 46 export DIST_DIR |
| 47 eval make -j ${MAKE_JOBS} dist ${devnull} |
| 48 cd "${old_pwd}" |
| 49 |
| 50 vlog "***Done building target: ${target}***" |
| 51 } |
| 52 |
| 53 # Returns the preprocessor symbol for the target specified by $1. |
| 54 target_to_preproc_symbol() { |
| 55 target="$1" |
| 56 case "${target}" in |
| 57 armv6-*) |
| 58 echo "__ARM_ARCH_6__" |
| 59 ;; |
| 60 armv7-*) |
| 61 echo "__ARM_ARCH_7__" |
| 62 ;; |
| 63 armv7s-*) |
| 64 echo "__ARM_ARCH_7S__" |
| 65 ;; |
| 66 x86-*) |
| 67 echo "__i386__" |
| 68 ;; |
| 69 x86_64-*) |
| 70 echo "__x86_64__" |
| 71 ;; |
| 72 *) |
| 73 echo "#error ${target} unknown/unsupported" |
| 74 return 1 |
| 75 ;; |
| 76 esac |
| 77 } |
| 78 |
| 79 # Create a vpx_config.h shim that, based on preprocessor settings for the |
| 80 # current target CPU, includes the real vpx_config.h for the current target. |
| 81 # $1 is the list of targets. |
| 82 create_vpx_framework_config_shim() { |
| 83 local targets="$1" |
| 84 local config_file="${HEADER_DIR}/vpx_config.h" |
| 85 local preproc_symbol="" |
| 86 local target="" |
| 87 local include_guard="VPX_FRAMEWORK_HEADERS_VPX_VPX_CONFIG_H_" |
| 88 |
| 89 local file_header="/* |
| 90 * Copyright (c) $(date +%Y) The WebM project authors. All Rights Reserved. |
| 91 * |
| 92 * Use of this source code is governed by a BSD-style license |
| 93 * that can be found in the LICENSE file in the root of the source |
| 94 * tree. An additional intellectual property rights grant can be found |
| 95 * in the file PATENTS. All contributing project authors may |
| 96 * be found in the AUTHORS file in the root of the source tree. |
| 97 */ |
| 98 |
| 99 /* GENERATED FILE: DO NOT EDIT! */ |
| 100 |
| 101 #ifndef ${include_guard} |
| 102 #define ${include_guard} |
| 103 |
| 104 #if defined" |
| 105 |
| 106 printf "%s" "${file_header}" > "${config_file}" |
| 107 for target in ${targets}; do |
| 108 preproc_symbol=$(target_to_preproc_symbol "${target}") |
| 109 printf " ${preproc_symbol}\n" >> "${config_file}" |
| 110 printf "#include \"VPX/vpx/${target}/vpx_config.h\"\n" >> "${config_file}" |
| 111 printf "#elif defined" >> "${config_file}" |
| 112 mkdir "${HEADER_DIR}/${target}" |
| 113 cp -p "${BUILD_ROOT}/${target}/vpx_config.h" "${HEADER_DIR}/${target}" |
| 114 done |
| 115 |
| 116 # Consume the last line of output from the loop: We don't want it. |
| 117 sed -i '' -e '$d' "${config_file}" |
| 118 |
| 119 printf "#endif\n\n" >> "${config_file}" |
| 120 printf "#endif // ${include_guard}" >> "${config_file}" |
| 121 } |
| 122 |
| 123 # Configures and builds each target specified by $1, and then builds |
| 124 # VPX.framework. |
| 125 build_framework() { |
| 126 local lib_list="" |
| 127 local targets="$1" |
| 128 local target="" |
| 129 local target_dist_dir="" |
| 130 |
| 131 # Clean up from previous build(s). |
| 132 rm -rf "${BUILD_ROOT}" "${FRAMEWORK_DIR}" |
| 133 |
| 134 # Create output dirs. |
| 135 mkdir -p "${BUILD_ROOT}" |
| 136 mkdir -p "${HEADER_DIR}" |
| 137 |
| 138 cd "${BUILD_ROOT}" |
| 139 |
| 140 for target in ${targets}; do |
| 141 build_target "${target}" |
| 142 target_dist_dir="${BUILD_ROOT}/${target}/${DIST_DIR}" |
| 143 lib_list="${lib_list} ${target_dist_dir}/lib/libvpx.a" |
| 144 done |
| 145 |
| 146 cd "${ORIG_PWD}" |
| 147 |
| 148 # The basic libvpx API includes are all the same; just grab the most recent |
| 149 # set. |
| 150 cp -p "${target_dist_dir}"/include/vpx/* "${HEADER_DIR}" |
| 151 |
| 152 # Build the fat library. |
| 153 ${LIPO} -create ${lib_list} -output ${FRAMEWORK_DIR}/VPX |
| 154 |
| 155 # Create the vpx_config.h shim that allows usage of vpx_config.h from |
| 156 # within VPX.framework. |
| 157 create_vpx_framework_config_shim "${targets}" |
| 158 |
| 159 # Copy in vpx_version.h. |
| 160 cp -p "${BUILD_ROOT}/${target}/vpx_version.h" "${HEADER_DIR}" |
| 161 |
| 162 vlog "Created fat library ${FRAMEWORK_DIR}/VPX containing:" |
| 163 for lib in ${lib_list}; do |
| 164 vlog " $(echo ${lib} | awk -F / '{print $2, $NF}')" |
| 165 done |
| 166 |
| 167 # TODO(tomfinegan): Verify that expected targets are included within |
| 168 # VPX.framework/VPX via lipo -info. |
| 169 } |
| 170 |
| 171 # Trap function. Cleans up the subtree used to build all targets contained in |
| 172 # $TARGETS. |
| 173 cleanup() { |
| 174 cd "${ORIG_PWD}" |
| 175 |
| 176 if [ "${PRESERVE_BUILD_OUTPUT}" != "yes" ]; then |
| 177 rm -rf "${BUILD_ROOT}" |
| 178 fi |
| 179 } |
| 180 |
| 181 iosbuild_usage() { |
| 182 cat << EOF |
| 183 Usage: ${0##*/} [arguments] |
| 184 --help: Display this message and exit. |
| 185 --jobs: Number of make jobs. |
| 186 --preserve-build-output: Do not delete the build directory. |
| 187 --show-build-output: Show output from each library build. |
| 188 --verbose: Output information about the environment and each stage of the |
| 189 build. |
| 190 EOF |
| 191 } |
| 192 |
| 193 vlog() { |
| 194 if [ "${VERBOSE}" = "yes" ]; then |
| 195 echo "$@" |
| 196 fi |
| 197 } |
| 198 |
| 199 trap cleanup EXIT |
| 200 |
| 201 # Parse the command line. |
| 202 while [ -n "$1" ]; do |
| 203 case "$1" in |
| 204 --help) |
| 205 iosbuild_usage |
| 206 exit |
| 207 ;; |
| 208 --jobs) |
| 209 MAKE_JOBS="$2" |
| 210 shift |
| 211 ;; |
| 212 --preserve-build-output) |
| 213 PRESERVE_BUILD_OUTPUT=yes |
| 214 ;; |
| 215 --show-build-output) |
| 216 devnull= |
| 217 ;; |
| 218 --verbose) |
| 219 VERBOSE=yes |
| 220 ;; |
| 221 *) |
| 222 iosbuild_usage |
| 223 exit 1 |
| 224 ;; |
| 225 esac |
| 226 shift |
| 227 done |
| 228 |
| 229 if [ "${VERBOSE}" = "yes" ]; then |
| 230 cat << EOF |
| 231 BUILD_ROOT=${BUILD_ROOT} |
| 232 DIST_DIR=${DIST_DIR} |
| 233 FRAMEWORK_DIR=${FRAMEWORK_DIR} |
| 234 HEADER_DIR=${HEADER_DIR} |
| 235 MAKE_JOBS=${MAKE_JOBS} |
| 236 PRESERVE_BUILD_OUTPUT=${PRESERVE_BUILD_OUTPUT} |
| 237 LIBVPX_SOURCE_DIR=${LIBVPX_SOURCE_DIR} |
| 238 LIPO=${LIPO} |
| 239 ORIG_PWD=${ORIG_PWD} |
| 240 TARGETS="${TARGETS}" |
| 241 EOF |
| 242 fi |
| 243 |
| 244 build_framework "${TARGETS}" |
OLD | NEW |