OLD | NEW |
| (Empty) |
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 dynamic FAT framework for iOS in out_ios_framework. | |
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 BUILD_WEBRTC_SCRIPT=${SCRIPT_DIR}/build_ios_libs.sh | |
20 FLATTEN_HEADERS_SCRIPT=${SCRIPT_DIR}/flatten_ios_headers.py | |
21 SDK_DIR=${SCRIPT_DIR}/SDK | |
22 FRAMEWORK_PROJECT_DIR=${SDK_DIR}/Framework | |
23 FRAMEWORK_PROJECT_PATH=${FRAMEWORK_PROJECT_DIR}/WebRTC.xcodeproj | |
24 | |
25 function check_preconditions { | |
26 # Check for Darwin. | |
27 if [[ ! $(uname) = "Darwin" ]]; then | |
28 echo "OS X required." >&2 | |
29 exit 1 | |
30 fi | |
31 if [[ ! -x ${BUILD_WEBRTC_SCRIPT} ]]; then | |
32 echo "Failed to find iOS library build script." >&2 | |
33 exit 1 | |
34 fi | |
35 if [[ ! -x ${FLATTEN_HEADERS_SCRIPT} ]]; then | |
36 echo "Failed to find flatten iOS headers script." >&2 | |
37 exit 1 | |
38 fi | |
39 if [[ ! -x ${FRAMEWORK_PROJECT_PATH} ]]; then | |
40 echo "Failed to find framework XCode project." >&2 | |
41 exit 1 | |
42 fi | |
43 } | |
44 | |
45 function clean_artifacts { | |
46 # Make XCode clean up after itself. | |
47 xcodebuild -project ${FRAMEWORK_PROJECT_PATH} -scheme WebRTC \ | |
48 -configuration Release clean | |
49 xcodebuild -project ${FRAMEWORK_PROJECT_PATH} -scheme WebRTC \ | |
50 -configuration Release clean \ | |
51 -destination "platform=iOS Simulator,name=iPhone 6" | |
52 # Remove remaining directory that XCode doesn't delete. | |
53 XCODE_BUILD_DIR=${FRAMEWORK_PROJECT_DIR}/build | |
54 if [[ -d ${XCODE_BUILD_DIR} ]]; then | |
55 rm -r ${XCODE_BUILD_DIR} | |
56 fi | |
57 | |
58 # Remove the temporary framework header dir. | |
59 if [[ -d ${FRAMEWORK_INCLUDE_DIR} ]]; then | |
60 rm -r ${FRAMEWORK_INCLUDE_DIR} | |
61 fi | |
62 | |
63 # Remove the generated framework. | |
64 if [[ -d ${FRAMEWORK_OUTPUT_DIR} ]]; then | |
65 rm -r ${FRAMEWORK_OUTPUT_DIR} | |
66 fi | |
67 | |
68 # Let the other script clean up after itself. | |
69 ${BUILD_WEBRTC_SCRIPT} -c | |
70 } | |
71 | |
72 function usage { | |
73 echo "WebRTC iOS Framework build script." | |
74 echo "Builds a dynamic Framework for the WebRTC APIs." | |
75 echo "Compiles various architectures and edits header paths as required." | |
76 echo "Usage: $0 [-h] [-c]" | |
77 echo " -h Print this help." | |
78 echo " -c Removes generated build output." | |
79 exit 0 | |
80 } | |
81 | |
82 check_preconditions | |
83 | |
84 # Set the output directories for the various build artifacts. | |
85 # For convenience we'll output some generated files in the same directory | |
86 # as the one we used to output the generated statis libraries. | |
87 LIB_OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs | |
88 INCLUDE_OUTPUT_DIR=${LIB_OUTPUT_DIR}/include | |
89 FRAMEWORK_INCLUDE_DIR=${LIB_OUTPUT_DIR}/framework_include | |
90 FRAMEWORK_OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_framework | |
91 PERFORM_CLEAN=0 | |
92 | |
93 # Parse arguments. | |
94 while getopts "hc" opt; do | |
95 case "${opt}" in | |
96 h) usage;; | |
97 c) PERFORM_CLEAN=1;; | |
98 *) | |
99 usage | |
100 exit 1 | |
101 ;; | |
102 esac | |
103 done | |
104 | |
105 if [[ ${PERFORM_CLEAN} -ne 0 ]]; then | |
106 clean_artifacts | |
107 exit 0 | |
108 fi | |
109 | |
110 # Build static libraries for iOS. | |
111 ${BUILD_WEBRTC_SCRIPT} -o ${LIB_OUTPUT_DIR} | |
112 | |
113 # Flatten the directory structure for iOS headers generated from building the | |
114 # static libraries. | |
115 ${FLATTEN_HEADERS_SCRIPT} ${INCLUDE_OUTPUT_DIR} ${FRAMEWORK_INCLUDE_DIR} | |
116 | |
117 # Replace full paths for headers with framework paths. | |
118 SED_PATTERN=' | |
119 s/(\#import )\"webrtc\/api\/objc\/(.*)\"/\1<WebRTC\/\2>/g; | |
120 s/(\#import )\"webrtc\/base\/objc\/(.*)\"/\1<WebRTC\/\2>/g; | |
121 s/(\#include )\"webrtc\/base\/objc\/(.*)\"/\1<WebRTC\/\2>/g; | |
122 ' | |
123 sed -E -i '' "$SED_PATTERN" ${FRAMEWORK_INCLUDE_DIR}/*.h | |
124 | |
125 # Build the framework. | |
126 xcodebuild -project ${FRAMEWORK_PROJECT_PATH} -scheme WebRTC \ | |
127 -configuration Release build \ | |
128 CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | |
129 xcodebuild -project ${FRAMEWORK_PROJECT_PATH} -scheme WebRTC \ | |
130 -configuration Release build \ | |
131 -destination "platform=iOS Simulator,name=iPhone 6" | |
132 | |
133 # XCode should output the build artifacts to the following directories. | |
134 DEVICE_BUILD_DIR=${FRAMEWORK_PROJECT_DIR}/build/Release-iphoneos | |
135 SIMULATOR_BUILD_DIR=${FRAMEWORK_PROJECT_DIR}/build/Release-iphonesimulator | |
136 | |
137 # Copy podspec, framework, dSYM and LICENSE to FRAMEWORK_OUTPUT_DIR. | |
138 mkdir -p ${FRAMEWORK_OUTPUT_DIR} | |
139 cp ${SDK_DIR}/WebRTC.podspec ${FRAMEWORK_OUTPUT_DIR}/ | |
140 cp -R ${DEVICE_BUILD_DIR}/WebRTC.framework ${FRAMEWORK_OUTPUT_DIR}/ | |
141 cp -R ${DEVICE_BUILD_DIR}/WebRTC.framework.dSYM ${FRAMEWORK_OUTPUT_DIR}/ | |
142 cp -R ${WEBRTC_BASE_DIR}/webrtc/LICENSE ${FRAMEWORK_OUTPUT_DIR}/ | |
143 | |
144 # Combine multiple architectures. | |
145 DYLIB_PATH=WebRTC.framework/WebRTC | |
146 DWARF_PATH=WebRTC.framework.dSYM/Contents/Resources/DWARF/WebRTC | |
147 lipo ${FRAMEWORK_OUTPUT_DIR}/${DYLIB_PATH} \ | |
148 ${SIMULATOR_BUILD_DIR}/${DYLIB_PATH} \ | |
149 -create -output ${FRAMEWORK_OUTPUT_DIR}/${DYLIB_PATH} | |
150 lipo ${FRAMEWORK_OUTPUT_DIR}/${DWARF_PATH} \ | |
151 ${SIMULATOR_BUILD_DIR}/${DWARF_PATH} \ | |
152 -create -output ${FRAMEWORK_OUTPUT_DIR}/${DWARF_PATH} | |
OLD | NEW |