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 dynamic FAT framework for iOS in out_ios_framework. | 11 # Generates dynamic FAT framework for iOS in out_ios_framework. |
12 | 12 |
13 # Check for Darwin. | 13 # Exit on errors. |
14 if [[ ! $(uname) = "Darwin" ]]; then | 14 set -e |
15 echo "OS X required." >&2 | 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 | |
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.
| |
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;; | |
kjellander_webrtc
2016/04/15 04:59:41
indent according to https://engdoc.corp.google.com
tkchin_webrtc
2016/04/16 00:34:18
Done.
| |
97 c) PERFORM_CLEAN=1;; | |
98 esac | |
99 done | |
100 | |
101 if [ ${PERFORM_CLEAN} -ne 0 ]; then | |
102 clean_artifacts | |
103 exit 0 | |
16 fi | 104 fi |
17 | 105 |
18 # Check for iOS library build script. | 106 # Build static libraries for iOS. |
19 SCRIPT_DIR=$(dirname $0) | 107 ${BUILD_WEBRTC_SCRIPT} -o ${LIB_OUTPUT_DIR} |
20 WEBRTC_BASE_DIR=${SCRIPT_DIR}/../../.. | |
21 BUILD_WEBRTC_SCRIPT=${WEBRTC_BASE_DIR}/webrtc/build/ios/build_ios_libs.sh | |
22 if [[ ! -x ${BUILD_WEBRTC_SCRIPT} ]]; then | |
23 echo "Failed to find iOS library build script." >&2 | |
24 exit 1 | |
25 fi | |
26 # Check for flatten iOS headers script. | |
27 FLATTEN_HEADERS_SCRIPT=${WEBRTC_BASE_DIR}/webrtc/build/ios/flatten_ios_headers | |
28 if [[ ! -x ${FLATTEN_HEADERS_SCRIPT} ]]; then | |
29 echo "Failed to find flatten iOS headers script." >&2 | |
30 exit 1 | |
31 fi | |
32 | 108 |
33 pushd ${WEBRTC_BASE_DIR} | 109 # Flatten the directory structure for iOS headers generated from building the |
34 LIB_BASE_DIR=out_ios_libs | 110 # static libraries. |
35 FRAMEWORK_BASE_DIR=out_ios_framework | 111 ${FLATTEN_HEADERS_SCRIPT} ${INCLUDE_OUTPUT_DIR} ${FRAMEWORK_INCLUDE_DIR} |
36 | |
37 # Build static libraries for iOS. | |
38 ${BUILD_WEBRTC_SCRIPT} | |
39 if [ $? -ne 0 ]; then | |
40 echo "Failed to build iOS static libraries." >&2 | |
41 exit 1 | |
42 fi | |
43 | |
44 # Flatten the directory structure for iOS headers. | |
45 ${FLATTEN_HEADERS_SCRIPT} ${LIB_BASE_DIR} ${FRAMEWORK_BASE_DIR} | |
46 if [ $? -ne 0 ]; then | |
47 echo "Failed to flatten iOS headers." >&2 | |
48 exit 1 | |
49 fi | |
50 | 112 |
51 # Replace full paths for headers with framework paths. | 113 # Replace full paths for headers with framework paths. |
52 SED_PATTERN=' | 114 SED_PATTERN=' |
53 s/(\#import )\"webrtc\/api\/objc\/(.*)\"/\1<WebRTC\/\2>/g; | 115 s/(\#import )\"webrtc\/api\/objc\/(.*)\"/\1<WebRTC\/\2>/g; |
54 s/(\#import )\"webrtc\/base\/objc\/(.*)\"/\1<WebRTC\/\2>/g; | 116 s/(\#import )\"webrtc\/base\/objc\/(.*)\"/\1<WebRTC\/\2>/g; |
55 s/(\#include )\"webrtc\/base\/objc\/(.*)\"/\1<WebRTC\/\2>/g; | 117 s/(\#include )\"webrtc\/base\/objc\/(.*)\"/\1<WebRTC\/\2>/g; |
56 ' | 118 ' |
57 sed -E -i '' "$SED_PATTERN" ${FRAMEWORK_BASE_DIR}/include/*.h | 119 sed -E -i '' "$SED_PATTERN" ${FRAMEWORK_INCLUDE_DIR}/*.h |
58 | 120 |
59 SDK_DIR=webrtc/build/ios/SDK | |
60 PROJECT_DIR=${SDK_DIR}/Framework | |
61 # Build the framework. | 121 # Build the framework. |
62 pushd ${PROJECT_DIR} | 122 xcodebuild -project ${FRAMEWORK_PROJECT_PATH} -scheme WebRTC \ |
63 xcodebuild -project WebRTC.xcodeproj -scheme WebRTC -configuration Release \ | 123 -configuration Release build \ |
64 build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | 124 CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO |
65 xcodebuild -project WebRTC.xcodeproj -scheme WebRTC -configuration Release \ | 125 xcodebuild -project ${FRAMEWORK_PROJECT_PATH} -scheme WebRTC \ |
66 build -destination 'platform=iOS Simulator,name=iPhone 6' | 126 -configuration Release build \ |
67 popd | 127 -destination "platform=iOS Simulator,name=iPhone 6" |
68 | 128 |
69 # Copy podspec, framework, dSYM and LICENSE to FRAMEWORK_BASE_DIR | 129 # XCode should output the build artifacts to the following directories. |
70 DEVICE_BUILD_DIR=${PROJECT_DIR}/build/Release-iphoneos | 130 DEVICE_BUILD_DIR=${FRAMEWORK_PROJECT_DIR}/build/Release-iphoneos |
71 cp ${SDK_DIR}/WebRTC.podspec ${FRAMEWORK_BASE_DIR}/ | 131 SIMULATOR_BUILD_DIR=${FRAMEWORK_PROJECT_DIR}/build/Release-iphonesimulator |
72 cp -R ${DEVICE_BUILD_DIR}/WebRTC.framework ${FRAMEWORK_BASE_DIR}/ | |
73 cp -R ${DEVICE_BUILD_DIR}/WebRTC.framework.dSYM ${FRAMEWORK_BASE_DIR}/ | |
74 cp -R webrtc/LICENSE ${FRAMEWORK_BASE_DIR}/ | |
75 | 132 |
76 # Combine multiple architectures | 133 # Copy podspec, framework, dSYM and LICENSE to FRAMEWORK_OUTPUT_DIR. |
77 SIMULATOR_BUILD_DIR=${PROJECT_DIR}/build/Release-iphonesimulator | 134 mkdir -p ${FRAMEWORK_OUTPUT_DIR} |
135 cp ${SDK_DIR}/WebRTC.podspec ${FRAMEWORK_OUTPUT_DIR}/ | |
136 cp -R ${DEVICE_BUILD_DIR}/WebRTC.framework ${FRAMEWORK_OUTPUT_DIR}/ | |
137 cp -R ${DEVICE_BUILD_DIR}/WebRTC.framework.dSYM ${FRAMEWORK_OUTPUT_DIR}/ | |
138 cp -R webrtc/LICENSE ${FRAMEWORK_OUTPUT_DIR}/ | |
139 | |
140 # Combine multiple architectures. | |
78 DYLIB_PATH=WebRTC.framework/WebRTC | 141 DYLIB_PATH=WebRTC.framework/WebRTC |
79 DWARF_PATH=WebRTC.framework.dSYM/Contents/Resources/DWARF/WebRTC | 142 DWARF_PATH=WebRTC.framework.dSYM/Contents/Resources/DWARF/WebRTC |
80 lipo ${FRAMEWORK_BASE_DIR}/${DYLIB_PATH} ${SIMULATOR_BUILD_DIR}/${DYLIB_PATH} \ | 143 lipo ${FRAMEWORK_OUTPUT_DIR}/${DYLIB_PATH} \ |
81 -create -output ${FRAMEWORK_BASE_DIR}/${DYLIB_PATH} | 144 ${SIMULATOR_BUILD_DIR}/${DYLIB_PATH} \ |
82 lipo ${FRAMEWORK_BASE_DIR}/${DWARF_PATH} ${SIMULATOR_BUILD_DIR}/${DWARF_PATH} \ | 145 -create -output ${FRAMEWORK_OUTPUT_DIR}/${DYLIB_PATH} |
83 -create -output ${FRAMEWORK_BASE_DIR}/${DWARF_PATH} | 146 lipo ${FRAMEWORK_OUTPUT_DIR}/${DWARF_PATH} \ |
147 ${SIMULATOR_BUILD_DIR}/${DWARF_PATH} \ | |
148 -create -output ${FRAMEWORK_OUTPUT_DIR}/${DWARF_PATH} | |
84 | 149 |
85 popd | 150 |
kjellander_webrtc
2016/04/15 04:59:41
Remove these ending blank lines
tkchin_webrtc
2016/04/16 00:34:18
Done.
| |
151 | |
152 | |
OLD | NEW |