hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2015 The WebRTC 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 | # Generates static FAT libraries for ios in out_ios_libs. |
| 12 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 13 | # Exit on errors. |
| 14 | set -e |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 15 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 16 | # Globals. |
| 17 | SCRIPT_DIR=$(cd $(dirname $0) && pwd) |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 18 | WEBRTC_BASE_DIR=${SCRIPT_DIR}/../../.. |
| 19 | GYP_WEBRTC_SCRIPT=${WEBRTC_BASE_DIR}/webrtc/build/gyp_webrtc |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 20 | EXPORT_HEADERS_SCRIPT=${SCRIPT_DIR}/export_headers.py |
| 21 | MERGE_SCRIPT=${SCRIPT_DIR}/merge_ios_libs.py |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 22 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 23 | function check_preconditions { |
| 24 | # Check for Darwin. |
| 25 | if [[ ! $(uname) = "Darwin" ]]; then |
| 26 | echo "OS/X required." >&2 |
| 27 | exit 1 |
| 28 | fi |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 29 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 30 | # Check for libtool. |
| 31 | if [[ -z $(which libtool) ]]; then |
| 32 | echo "Missing libtool binary." >&2 |
| 33 | exit 1 |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 34 | fi |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 35 | |
| 36 | # Check for GYP generator. |
| 37 | if [[ ! -x ${GYP_WEBRTC_SCRIPT} ]]; then |
| 38 | echo "Failed to find gyp generator." >&2 |
| 39 | exit 1 |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 40 | fi |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 41 | |
| 42 | # Check for export headers script. |
| 43 | if [[ ! -x ${EXPORT_HEADERS_SCRIPT} ]]; then |
| 44 | echo "Failed to find export headers script." >&2 |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
| 48 | # Check for merge script. |
| 49 | if [[ ! -x ${MERGE_SCRIPT} ]]; then |
| 50 | echo "Failed to find library merging script." >&2 |
| 51 | exit 1 |
| 52 | fi |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 53 | } |
| 54 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 55 | function build_webrtc { |
| 56 | local base_output_dir=$1 |
| 57 | local flavor=$2 |
| 58 | local target_arch=$3 |
| 59 | local ninja_output_dir=${base_output_dir}/${target_arch}_ninja |
| 60 | local library_output_dir=${base_output_dir}/${target_arch}_libs |
| 61 | if [[ ${target_arch} = 'arm' || ${target_arch} = 'arm64' ]]; then |
| 62 | flavor="${flavor}-iphoneos" |
| 63 | else |
| 64 | flavor="${flavor}-iphonesimulator" |
| 65 | fi |
| 66 | export GYP_DEFINES="OS=ios target_arch=${target_arch} use_objc_h264=1 \ |
| 67 | clang_xcode=1 ios_override_visibility=1" |
| 68 | export GYP_GENERATORS="ninja" |
| 69 | export GYP_GENERATOR_FLAGS="output_dir=${ninja_output_dir}" |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 70 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 71 | # GYP generation requires relative path for some reason. |
| 72 | pushd ${WEBRTC_BASE_DIR} |
| 73 | webrtc/build/gyp_webrtc webrtc/build/ios/merge_ios_libs.gyp |
| 74 | popd |
| 75 | if [[ ${USE_LEGACY_API} -eq 1 ]]; then |
| 76 | ninja -C ${ninja_output_dir}/${flavor} libjingle_peerconnection_objc_no_op |
| 77 | else |
| 78 | ninja -C ${ninja_output_dir}/${flavor} webrtc_api_objc_no_op |
| 79 | fi |
| 80 | mkdir -p ${library_output_dir} |
| 81 | |
| 82 | for f in ${ninja_output_dir}/${flavor}/*.a |
| 83 | do |
| 84 | ln -sf "${f}" "${library_output_dir}/$(basename ${f})" |
| 85 | done |
| 86 | } |
| 87 | |
| 88 | function clean_artifacts { |
| 89 | local output_dir=$1 |
| 90 | if [[ -d ${output_dir} ]]; then |
| 91 | rm -r ${output_dir} |
| 92 | fi |
| 93 | } |
| 94 | |
| 95 | function usage { |
| 96 | echo "WebRTC iOS FAT libraries build script." |
| 97 | echo "Each architecture is compiled separately before being merged together." |
| 98 | echo "By default, the fat libraries will be created in out_ios_libs/fat_libs." |
| 99 | echo "The headers will be copied to out_ios_libs/include." |
| 100 | echo "Usage: $0 [-h] [-c] [-o]" |
| 101 | echo " -h Print this help." |
| 102 | echo " -c Removes generated build output." |
| 103 | echo " -o Specifies a directory to output build artifacts to." |
| 104 | echo " If specified together with -c, deletes the dir." |
| 105 | exit 0 |
| 106 | } |
| 107 | |
| 108 | check_preconditions |
| 109 | |
| 110 | # Set default arguments. |
| 111 | # Output directory for build artifacts. |
| 112 | OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs |
| 113 | # Flag to build the new or legacy version of the API. |
| 114 | USE_LEGACY_API=0 |
| 115 | PERFORM_CLEAN=0 |
| 116 | |
| 117 | # Parse arguments. |
| 118 | while getopts "hco:" opt; do |
| 119 | case "${opt}" in |
| 120 | h) usage;; |
| 121 | c) PERFORM_CLEAN=1;; |
| 122 | o) OUTPUT_DIR="${OPTARG}";; |
| 123 | *) |
| 124 | usage |
| 125 | exit 1 |
| 126 | ;; |
| 127 | esac |
| 128 | done |
| 129 | |
| 130 | if [[ ${PERFORM_CLEAN} -ne 0 ]]; then |
| 131 | clean_artifacts ${OUTPUT_DIR} |
| 132 | exit 0 |
| 133 | fi |
| 134 | |
| 135 | # Build all the common architectures. |
| 136 | archs=( "arm" "arm64" "ia32" "x64" ) |
| 137 | for arch in "${archs[@]}" |
| 138 | do |
| 139 | echo "Building WebRTC arch: ${arch}" |
| 140 | build_webrtc ${OUTPUT_DIR} "Profile" $arch |
| 141 | done |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 142 | |
| 143 | # Export header files. |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 144 | ${EXPORT_HEADERS_SCRIPT} ${OUTPUT_DIR} ${USE_LEGACY_API} |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 145 | |
| 146 | # Merge the libraries together. |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 147 | ${MERGE_SCRIPT} ${OUTPUT_DIR} |