OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright 2015 The WebRTC project authors. All Rights Reserved. | 3 # Copyright 2015 The WebRTC project authors. All Rights Reserved. |
4 # | 4 # |
5 # Use of this source code is governed by a BSD-style license | 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 | 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 | 7 # tree. An additional intellectual property rights grant can be found |
8 # in the file PATENTS. All contributing project authors may | 8 # in the file PATENTS. All contributing project authors may |
9 # be found in the AUTHORS file in the root of the source tree. | 9 # be found in the AUTHORS file in the root of the source tree. |
10 | 10 |
11 # Generates static FAT libraries for ios in out_ios_libs. | 11 # Generates static FAT libraries for ios in out_ios_libs. |
12 | 12 |
| 13 # Exit on errors. |
| 14 set -e |
| 15 |
| 16 # Globals. |
| 17 SCRIPT_DIR=$(cd $(dirname $0) && pwd) |
| 18 WEBRTC_BASE_DIR=${SCRIPT_DIR}/../../.. |
| 19 GYP_WEBRTC_SCRIPT=${WEBRTC_BASE_DIR}/webrtc/build/gyp_webrtc |
| 20 EXPORT_HEADERS_SCRIPT=${SCRIPT_DIR}/export_headers.py |
| 21 MERGE_SCRIPT=${SCRIPT_DIR}/merge_ios_libs.py |
| 22 |
| 23 function check_preconditions { |
| 24 # Check for Darwin. |
| 25 if [[ ! $(uname) = "Darwin" ]]; then |
| 26 echo "OS/X required." >&2 |
| 27 exit 1 |
| 28 fi |
| 29 |
| 30 # Check for libtool. |
| 31 if [[ -z $(which libtool) ]]; then |
| 32 echo "Missing libtool binary." >&2 |
| 33 exit 1 |
| 34 fi |
| 35 |
| 36 # Check for GYP generator. |
| 37 if [[ ! -x ${GYP_WEBRTC_SCRIPT} ]]; then |
| 38 echo "Failed to find gyp generator." >&2 |
| 39 exit 1 |
| 40 fi |
| 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 |
| 53 } |
| 54 |
| 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}" |
| 70 |
| 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 |
13 # Flag to build the new or legacy version of the API. | 113 # Flag to build the new or legacy version of the API. |
14 USE_LEGACY_API=0 | 114 USE_LEGACY_API=0 |
| 115 PERFORM_CLEAN=0 |
15 | 116 |
16 # Check for Darwin. | 117 # Parse arguments. |
17 if [[ ! $(uname) = "Darwin" ]]; then | 118 while getopts "hco:" opt; do |
18 echo "OS/X required." >&2 | 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 |
19 fi | 133 fi |
20 | 134 |
21 # Check for libtool. | |
22 if [[ -z $(which libtool) ]]; then | |
23 echo "Missing libtool binary." >&2 | |
24 fi | |
25 | |
26 # Check for GYP generator. | |
27 SCRIPT_DIR=$(dirname $0) | |
28 WEBRTC_BASE_DIR=${SCRIPT_DIR}/../../.. | |
29 GYP_WEBRTC_SCRIPT=${WEBRTC_BASE_DIR}/webrtc/build/gyp_webrtc | |
30 if [[ ! -x ${GYP_WEBRTC_SCRIPT} ]]; then | |
31 echo "Failed to find gyp generator." >&2 | |
32 exit 1 | |
33 fi | |
34 # Check for export headers script. | |
35 EXPORT_HEADERS_SCRIPT=${SCRIPT_DIR}/export_headers | |
36 if [[ ! -x ${EXPORT_HEADERS_SCRIPT} ]]; then | |
37 echo "Failed to find export headers script." >&2 | |
38 exit 1 | |
39 fi | |
40 # Check for merge script. | |
41 MERGE_SCRIPT=${SCRIPT_DIR}/merge_ios_libs | |
42 if [[ ! -x ${MERGE_SCRIPT} ]]; then | |
43 echo "Failed to find library merging script." >&2 | |
44 exit 1 | |
45 fi | |
46 | |
47 pushd ${WEBRTC_BASE_DIR} | |
48 LIBRARY_BASE_DIR="out_ios_libs" | |
49 | |
50 function build_webrtc { | |
51 OUTPUT_DIR=$1 | |
52 FLAVOR=$2 | |
53 TARGET_ARCH=$3 | |
54 if [[ ${TARGET_ARCH} = 'arm' || ${TARGET_ARCH} = 'arm64' ]]; then | |
55 FLAVOR="${FLAVOR}-iphoneos" | |
56 else | |
57 FLAVOR="${FLAVOR}-iphonesimulator" | |
58 fi | |
59 export GYP_DEFINES="OS=ios target_arch=${TARGET_ARCH} use_objc_h264=1 \ | |
60 clang_xcode=1 ios_override_visibility=1" | |
61 export GYP_GENERATORS="ninja" | |
62 export GYP_GENERATOR_FLAGS="output_dir=${OUTPUT_DIR}" | |
63 webrtc/build/gyp_webrtc webrtc/build/ios/merge_ios_libs.gyp | |
64 if [[ ${USE_LEGACY_API} -eq 1 ]]; then | |
65 ninja -C ${OUTPUT_DIR}/${FLAVOR} libjingle_peerconnection_objc_no_op | |
66 else | |
67 ninja -C ${OUTPUT_DIR}/${FLAVOR} webrtc_api_objc_no_op | |
68 fi | |
69 mkdir -p ${LIBRARY_BASE_DIR}/${TARGET_ARCH} | |
70 mv ${OUTPUT_DIR}/${FLAVOR}/*.a ${LIBRARY_BASE_DIR}/${TARGET_ARCH} | |
71 } | |
72 | |
73 # Build all the common architectures. | 135 # Build all the common architectures. |
74 build_webrtc "out_ios_arm" "Release" "arm" | 136 archs=( "arm" "arm64" "ia32" "x64" ) |
75 build_webrtc "out_ios_arm64" "Release" "arm64" | 137 for arch in "${archs[@]}" |
76 build_webrtc "out_ios_ia32" "Release" "ia32" | 138 do |
77 build_webrtc "out_ios_x86_64" "Release" "x64" | 139 echo "Building WebRTC arch: ${arch}" |
78 | 140 build_webrtc ${OUTPUT_DIR} "Profile" $arch |
79 popd | 141 done |
80 | 142 |
81 # Export header files. | 143 # Export header files. |
82 ${EXPORT_HEADERS_SCRIPT} ${WEBRTC_BASE_DIR}/${LIBRARY_BASE_DIR} \ | 144 ${EXPORT_HEADERS_SCRIPT} ${OUTPUT_DIR} ${USE_LEGACY_API} |
83 ${USE_LEGACY_API} | |
84 | 145 |
85 # Merge the libraries together. | 146 # Merge the libraries together. |
86 ${MERGE_SCRIPT} ${WEBRTC_BASE_DIR}/${LIBRARY_BASE_DIR} | 147 ${MERGE_SCRIPT} ${OUTPUT_DIR} |
OLD | NEW |