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 or dynamic 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. | 13 # Exit on errors. |
14 set -e | 14 set -e |
15 | 15 |
16 # Environment | |
17 export PATH=/usr/libexec:$PATH | |
18 | |
19 # Globals. | |
20 SCRIPT_DIR=$(cd $(dirname $0) && pwd) | 16 SCRIPT_DIR=$(cd $(dirname $0) && pwd) |
21 WEBRTC_BASE_DIR=${SCRIPT_DIR}/../../.. | 17 WEBRTC_BASE_DIR=${SCRIPT_DIR}/../../.. |
22 GYP_WEBRTC_SCRIPT=${WEBRTC_BASE_DIR}/webrtc/build/gyp_webrtc.py | |
23 MERGE_SCRIPT=${SCRIPT_DIR}/merge_ios_libs.py | |
24 LICENSE_SCRIPT=${SCRIPT_DIR}/generate_licenses.py | |
25 | 18 |
26 function check_preconditions { | 19 SDK_OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs |
27 # Check for Darwin. | 20 SDK_LIB_NAME="librtc_sdk_objc.a" |
28 if [[ ! $(uname) = "Darwin" ]]; then | 21 GN_BASE_ARGS="target_os=\"ios\" is_debug=false ios_enable_code_signing=false \ |
29 echo "OS/X required." >&2 | 22 rtc_libvpx_build_vp9=false" |
30 exit 1 | 23 GN_STATIC_TARGET_NAMES="rtc_sdk_peerconnection_objc field_trial_default \ |
31 fi | 24 metrics_default" |
32 | 25 |
33 # Check for libtool. | 26 # TODO(tkchin): Restore functionality of old script to build dynamic framework, |
34 if [[ -z $(which libtool) ]]; then | 27 # symbols and license file. |
35 echo "Missing libtool binary." >&2 | |
36 exit 1 | |
37 fi | |
38 | 28 |
39 # Check for GYP generator. | 29 function build_static_webrtc { |
40 if [[ ! -x ${GYP_WEBRTC_SCRIPT} ]]; then | 30 local arch=$1 |
41 echo "Failed to find gyp generator." >&2 | 31 local xcode_arch=$2 |
42 exit 1 | |
43 fi | |
44 | 32 |
45 # Check for merge script. | 33 OUTPUT_DIR=${SDK_OUTPUT_DIR}/${arch}_libs |
46 if [[ ! -x ${MERGE_SCRIPT} ]]; then | 34 OUTPUT_LIB=${OUTPUT_DIR}/${SDK_LIB_NAME} |
47 echo "Failed to find library merging script." >&2 | 35 GN_ARGS="${GN_BASE_ARGS} target_cpu=\"${arch}\"" |
48 exit 1 | 36 gn gen ${OUTPUT_DIR} --args="${GN_ARGS}" |
49 fi | 37 ninja -C ${OUTPUT_DIR} ${GN_STATIC_TARGET_NAMES} |
| 38 # Combine the object files together into a single archive and strip debug |
| 39 # symbols. |
| 40 find ${OUTPUT_DIR}/obj -type f -name "*.o" | |
| 41 xargs ld -r -static -S -all_load -arch ${xcode_arch} -o ${OUTPUT_LIB} |
50 } | 42 } |
51 | 43 |
52 function build_webrtc { | 44 # Build all the common architectures. |
53 local base_output_dir=$1 | 45 build_static_webrtc "arm" "armv7" |
54 local flavor=$2 | 46 build_static_webrtc "arm64" "arm64" |
55 local target_arch=$3 | 47 build_static_webrtc "x86" "i386" |
56 local build_type=$4 | 48 build_static_webrtc "x64" "x86_64" |
57 local libvpx_build_vp9=$5 | |
58 | 49 |
59 local ninja_output_dir=${base_output_dir}/${target_arch}_ninja | 50 # Combine the libraries. |
60 local library_output_dir=${base_output_dir}/${target_arch}_libs | 51 lipo ${SDK_OUTPUT_DIR}/arm_libs/${SDK_LIB_NAME} \ |
61 if [[ ${target_arch} = 'arm' || ${target_arch} = 'arm64' ]]; then | 52 ${SDK_OUTPUT_DIR}/arm64_libs/${SDK_LIB_NAME} \ |
62 flavor="${flavor}-iphoneos" | 53 ${SDK_OUTPUT_DIR}/x86_libs/${SDK_LIB_NAME} \ |
63 else | 54 ${SDK_OUTPUT_DIR}/x64_libs/${SDK_LIB_NAME} \ |
64 flavor="${flavor}-iphonesimulator" | 55 -create -output ${SDK_OUTPUT_DIR}/${SDK_LIB_NAME} |
65 fi | |
66 local ninja_flavor_dir=${ninja_output_dir}/${flavor} | |
67 | 56 |
68 # Compile framework by default. | 57 echo "Done." |
69 local gyp_file=webrtc/sdk/sdk.gyp | |
70 local gyp_target=rtc_sdk_framework_objc | |
71 # Set to 1 to explicitly not hide symbols. We'll want this if we're just | |
72 # generating static libs. | |
73 local override_visibility=0 | |
74 if [[ ${build_type} = "legacy" ]]; then | |
75 echo "Building objc legacy libraries no longer supported." | |
76 exit 1 | |
77 elif [[ ${build_type} = "static_only" ]]; then | |
78 echo "Building static only." | |
79 gyp_file=webrtc/build/ios/merge_ios_libs.gyp | |
80 gyp_target=rtc_sdk_peerconnection_objc_no_op | |
81 override_visibility=1 | |
82 elif [[ ${build_type} == "framework" ]]; then | |
83 echo "Building framework." | |
84 else | |
85 echo "Unexpected build type: ${build_type}" | |
86 exit 1 | |
87 fi | |
88 | |
89 export GYP_DEFINES="OS=ios target_arch=${target_arch} \ | |
90 clang_xcode=1 ios_deployment_target=8.0 \ | |
91 ios_override_visibility=${override_visibility} \ | |
92 libvpx_build_vp9=${libvpx_build_vp9}" | |
93 export GYP_GENERATORS="ninja" | |
94 export GYP_GENERATOR_FLAGS="output_dir=${ninja_output_dir}" | |
95 | |
96 # GYP generation requires relative path for some reason. | |
97 pushd ${WEBRTC_BASE_DIR} | |
98 webrtc/build/gyp_webrtc.py ${gyp_file} | |
99 popd | |
100 # Compile the target we're interested in. | |
101 ninja -C ${ninja_flavor_dir} ${gyp_target} | |
102 | |
103 if [[ ${build_type} = "framework" ]]; then | |
104 # Manually generate the dSYM files before stripping them. GYP does not seem | |
105 # to instruct ninja to generate dSYM files. | |
106 dsymutil --out=${ninja_flavor_dir}/WebRTC.framework.dSYM \ | |
107 ${ninja_flavor_dir}/WebRTC.framework/WebRTC | |
108 fi | |
109 | |
110 # Make links to the generated static archives. | |
111 mkdir -p ${library_output_dir} | |
112 for f in ${ninja_flavor_dir}/*.a | |
113 do | |
114 ln -sf "${f}" "${library_output_dir}/$(basename ${f})" | |
115 done | |
116 } | |
117 | |
118 function clean_artifacts { | |
119 local output_dir=$1 | |
120 if [[ -d ${output_dir} ]]; then | |
121 rm -r ${output_dir} | |
122 fi | |
123 } | |
124 | |
125 function usage { | |
126 echo "WebRTC iOS FAT libraries build script." | |
127 echo "Each architecture is compiled separately before being merged together." | |
128 echo "By default, the fat libraries will be created in out_ios_libs/fat_libs." | |
129 echo "The headers will be copied to out_ios_libs/include." | |
130 echo "Usage: $0 [-h] [-b build_type] [-c] [-o output_dir]" | |
131 echo " -h Print this help." | |
132 echo " -b The build type. Can be framework or static_only." | |
133 echo " Defaults to framework." | |
134 echo " -c Removes generated build output." | |
135 echo " -o Specifies a directory to output build artifacts to." | |
136 echo " If specified together with -c, deletes the dir." | |
137 echo " -r Specifies a revision number to embed if building the framework." | |
138 exit 0 | |
139 } | |
140 | |
141 check_preconditions | |
142 | |
143 # Set default arguments. | |
144 # Output directory for build artifacts. | |
145 OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs | |
146 # The type of build to perform. Valid arguments are framework and static_only. | |
147 BUILD_TYPE="framework" | |
148 PERFORM_CLEAN=0 | |
149 FLAVOR="Profile" | |
150 POINT_VERSION="0" | |
151 # TODO(tkchin): Add ability to pass in a flag to build vp9. Odds are mobile | |
152 # clients will not want it though because of the higher CPU usage. | |
153 LIBVPX_BUILD_VP9=0 | |
154 | |
155 # Parse arguments. | |
156 while getopts "hb:co:r:" opt; do | |
157 case "${opt}" in | |
158 h) usage;; | |
159 b) BUILD_TYPE="${OPTARG}";; | |
160 c) PERFORM_CLEAN=1;; | |
161 o) OUTPUT_DIR="${OPTARG}";; | |
162 r) POINT_VERSION="${OPTARG}";; | |
163 *) | |
164 usage | |
165 exit 1 | |
166 ;; | |
167 esac | |
168 done | |
169 | |
170 if [[ ${PERFORM_CLEAN} -ne 0 ]]; then | |
171 clean_artifacts ${OUTPUT_DIR} | |
172 exit 0 | |
173 fi | |
174 | |
175 # Build all the common architectures. | |
176 ARCHS=( "arm" "arm64" "ia32" "x64" ) | |
177 for ARCH in "${ARCHS[@]}" | |
178 do | |
179 echo "Building WebRTC arch: ${ARCH}" | |
180 build_webrtc ${OUTPUT_DIR} ${FLAVOR} $ARCH ${BUILD_TYPE} ${LIBVPX_BUILD_VP9} | |
181 done | |
182 | |
183 ARM_NINJA_DIR=${OUTPUT_DIR}/arm_ninja/${FLAVOR}-iphoneos | |
184 ARM64_NINJA_DIR=${OUTPUT_DIR}/arm64_ninja/${FLAVOR}-iphoneos | |
185 IA32_NINJA_DIR=${OUTPUT_DIR}/ia32_ninja/${FLAVOR}-iphonesimulator | |
186 X64_NINJA_DIR=${OUTPUT_DIR}/x64_ninja/${FLAVOR}-iphonesimulator | |
187 | |
188 if [[ ${BUILD_TYPE} = "framework" ]]; then | |
189 # Merge the framework slices together into a FAT library by copying one arch | |
190 # output and merging the rest in. | |
191 DYLIB_PATH="WebRTC.framework/WebRTC" | |
192 cp -R ${ARM_NINJA_DIR}/WebRTC.framework ${OUTPUT_DIR} | |
193 rm ${OUTPUT_DIR}/${DYLIB_PATH} | |
194 echo "Merging framework slices." | |
195 lipo ${ARM_NINJA_DIR}/${DYLIB_PATH} \ | |
196 ${ARM64_NINJA_DIR}/${DYLIB_PATH} \ | |
197 ${IA32_NINJA_DIR}/${DYLIB_PATH} \ | |
198 ${X64_NINJA_DIR}/${DYLIB_PATH} \ | |
199 -create -output ${OUTPUT_DIR}/${DYLIB_PATH} | |
200 | |
201 # Merge the dSYM files together in a similar fashion. | |
202 DSYM_PATH="WebRTC.framework.dSYM/Contents/Resources/DWARF/WebRTC" | |
203 cp -R ${ARM_NINJA_DIR}/WebRTC.framework.dSYM ${OUTPUT_DIR} | |
204 rm ${OUTPUT_DIR}/${DSYM_PATH} | |
205 echo "Merging dSYM slices." | |
206 lipo ${ARM_NINJA_DIR}/${DSYM_PATH} \ | |
207 ${ARM64_NINJA_DIR}/${DSYM_PATH} \ | |
208 ${IA32_NINJA_DIR}/${DSYM_PATH} \ | |
209 ${X64_NINJA_DIR}/${DSYM_PATH} \ | |
210 -create -output ${OUTPUT_DIR}/${DSYM_PATH} | |
211 | |
212 # Strip the dynamic framework of non-global symbols. | |
213 # TODO(tkchin): Override chromium strip settings in supplement.gypi instead. | |
214 echo "Stripping non-global symbols." | |
215 strip -x ${OUTPUT_DIR}/${DYLIB_PATH} | |
216 | |
217 # Modify the version number. | |
218 INFOPLIST_PATH=${OUTPUT_DIR}/WebRTC.framework/Info.plist | |
219 MAJOR_MINOR=$(PlistBuddy -c "Print :CFBundleShortVersionString" \ | |
220 ${INFOPLIST_PATH}) | |
221 VERSION_NUMBER="${MAJOR_MINOR}.${POINT_VERSION}" | |
222 echo "Substituting revision number: ${VERSION_NUMBER}" | |
223 PlistBuddy -c "Set :CFBundleVersion ${VERSION_NUMBER}" ${INFOPLIST_PATH} | |
224 plutil -convert binary1 ${INFOPLIST_PATH} | |
225 | |
226 # Copy pod file. | |
227 FORMAT_STRING=s/\${FRAMEWORK_VERSION_NUMBER}/${VERSION_NUMBER}/g | |
228 sed -e ${FORMAT_STRING} ${WEBRTC_BASE_DIR}/webrtc/sdk/objc/WebRTC.podspec > \ | |
229 ${OUTPUT_DIR}/WebRTC.podspec | |
230 elif [[ ${BUILD_TYPE} = "static_only" ]]; then | |
231 echo "Merging static library slices." | |
232 # Merge the static libraries together into individual FAT archives. | |
233 ${MERGE_SCRIPT} ${OUTPUT_DIR} | |
234 | |
235 # Merge the dSYM files together. | |
236 TARGET_NAME="rtc_sdk_peerconnection_objc_no_op" | |
237 DSYM_PATH="${TARGET_NAME}.app.dSYM/Contents/Resources/DWARF/${TARGET_NAME}" | |
238 cp -R ${ARM_NINJA_DIR}/${TARGET_NAME}.app.dSYM ${OUTPUT_DIR} | |
239 echo "Merging dSYM slices." | |
240 lipo ${ARM_NINJA_DIR}/${DSYM_PATH} \ | |
241 ${ARM64_NINJA_DIR}/${DSYM_PATH} \ | |
242 ${IA32_NINJA_DIR}/${DSYM_PATH} \ | |
243 ${X64_NINJA_DIR}/${DSYM_PATH} \ | |
244 -create -output ${OUTPUT_DIR}/${DSYM_PATH} | |
245 | |
246 # Strip debugging symbols. | |
247 # TODO(tkchin): Override chromium settings in supplement.gypi instead to do | |
248 # stripping at build time. | |
249 echo "Stripping debug symbols." | |
250 strip -S ${OUTPUT_DIR}/fat_libs/*.a | |
251 | |
252 # Symlink the headers. | |
253 echo "Symlinking headers." | |
254 INPUT_HEADER_DIR="${WEBRTC_BASE_DIR}/webrtc/sdk/objc/Framework/Headers/WebRTC" | |
255 OUTPUT_HEADER_DIR="${OUTPUT_DIR}/include" | |
256 if [[ -d ${OUTPUT_HEADER_DIR} ]]; then | |
257 rm -rf ${OUTPUT_HEADER_DIR} | |
258 fi | |
259 mkdir -p ${OUTPUT_HEADER_DIR} | |
260 ln -sf ${INPUT_HEADER_DIR} ${OUTPUT_HEADER_DIR}/WebRTC | |
261 else | |
262 echo "BUILD_TYPE ${BUILD_TYPE} not supported." | |
263 exit 1 | |
264 fi | |
265 | |
266 echo "Generating LICENSE.html." | |
267 ${LICENSE_SCRIPT} ${OUTPUT_DIR}/arm64_libs ${OUTPUT_DIR} | |
268 | |
269 echo "Done!" | |
OLD | NEW |