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 webrtc/build/gyp_webrtc webrtc/build/ios/merge_ios_libs.gyp | |
71 if [[ ${USE_LEGACY_API} -eq 1 ]]; then | |
72 ninja -C ${ninja_output_dir}/${flavor} libjingle_peerconnection_objc_no_op | |
73 else | |
74 ninja -C ${ninja_output_dir}/${flavor} webrtc_api_objc_no_op | |
75 fi | |
76 mkdir -p ${library_output_dir} | |
77 | |
78 for f in ${ninja_output_dir}/${flavor}/*.a | |
79 do | |
80 ln -sf "${f}" "${library_output_dir}/$(basename ${f})" | |
81 done | |
82 } | |
83 | |
84 function clean_artifacts { | |
85 local output_dir=$1 | |
86 if [ -d ${output_dir} ]; then | |
kjellander_webrtc
2016/04/15 04:59:41
Use double-brackets https://engdoc.corp.google.com
tkchin_webrtc
2016/04/16 00:34:18
Done.
| |
87 rm -r ${output_dir} | |
88 fi | |
89 } | |
90 | |
91 function usage { | |
92 echo "WebRTC iOS FAT libraries build script." | |
93 echo "Each architecture is compiled separately before being merged together." | |
94 echo "By default, the fat libraries will be created in out_ios_libs/fat_libs." | |
95 echo "The headers will be copied to out_ios_libs/include." | |
96 echo "Usage: $0 [-h] [-c] [-o]" | |
97 echo " -h Print this help." | |
98 echo " -c Removes generated build output." | |
99 echo " -o Specifies a directory to output build artifacts to." | |
100 echo " If specified together with -c, deletes the dir." | |
101 exit 0 | |
102 } | |
103 | |
104 check_preconditions | |
105 | |
106 # Set default arguments. | |
107 # Output directory for build artifacts. | |
108 OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs | |
13 # Flag to build the new or legacy version of the API. | 109 # Flag to build the new or legacy version of the API. |
14 USE_LEGACY_API=0 | 110 USE_LEGACY_API=0 |
111 PERFORM_CLEAN=0 | |
15 | 112 |
16 # Check for Darwin. | 113 # Parse arguments. |
17 if [[ ! $(uname) = "Darwin" ]]; then | 114 while getopts "hco:" opt; do |
18 echo "OS/X required." >&2 | 115 case "${opt}" in |
116 h) usage;; | |
kjellander_webrtc
2016/04/15 04:59:41
-2 spaces indent https://engdoc.corp.google.com/en
tkchin_webrtc
2016/04/16 00:34:18
Done.
| |
117 c) PERFORM_CLEAN=1;; | |
118 o) OUTPUT_DIR="${OPTARG}";; | |
119 esac | |
120 done | |
121 | |
122 if [ ${PERFORM_CLEAN} -ne 0 ]; then | |
kjellander_webrtc
2016/04/15 04:59:41
Use double-brackets https://engdoc.corp.google.com
tkchin_webrtc
2016/04/16 00:34:18
Done.
| |
123 clean_artifacts ${OUTPUT_DIR} | |
124 exit 0 | |
19 fi | 125 fi |
20 | 126 |
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. | 127 # Build all the common architectures. |
74 build_webrtc "out_ios_arm" "Release" "arm" | 128 archs=( "arm" "arm64" "ia32" "x64" ) |
75 build_webrtc "out_ios_arm64" "Release" "arm64" | 129 for arch in "${archs[@]}" |
76 build_webrtc "out_ios_ia32" "Release" "ia32" | 130 do |
77 build_webrtc "out_ios_x86_64" "Release" "x64" | 131 echo "Building WebRTC arch: ${arch}" |
78 | 132 build_webrtc ${OUTPUT_DIR} "Release" $arch |
79 popd | 133 done |
80 | 134 |
81 # Export header files. | 135 # Export header files. |
82 ${EXPORT_HEADERS_SCRIPT} ${WEBRTC_BASE_DIR}/${LIBRARY_BASE_DIR} \ | 136 ${EXPORT_HEADERS_SCRIPT} ${OUTPUT_DIR} ${USE_LEGACY_API} |
83 ${USE_LEGACY_API} | |
84 | 137 |
85 # Merge the libraries together. | 138 # Merge the libraries together. |
86 ${MERGE_SCRIPT} ${WEBRTC_BASE_DIR}/${LIBRARY_BASE_DIR} | 139 ${MERGE_SCRIPT} ${OUTPUT_DIR} |
OLD | NEW |