blob: 8e5f16fd946481d88a1b5ea617561cb89a7b8f61 [file] [log] [blame]
hjonbc73fe12016-03-21 11:38:26 -07001#!/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
tkchin9eeb6242016-04-27 01:54:20 -070011# Generates static or dynamic FAT libraries for ios in out_ios_libs.
hjonbc73fe12016-03-21 11:38:26 -070012
tkchin5209d672016-04-16 12:06:33 -070013# Exit on errors.
14set -e
hjonbc73fe12016-03-21 11:38:26 -070015
tkchin5209d672016-04-16 12:06:33 -070016# Globals.
17SCRIPT_DIR=$(cd $(dirname $0) && pwd)
hjonbc73fe12016-03-21 11:38:26 -070018WEBRTC_BASE_DIR=${SCRIPT_DIR}/../../..
kjellander@webrtc.org001c20d2016-04-18 16:32:52 +020019GYP_WEBRTC_SCRIPT=${WEBRTC_BASE_DIR}/webrtc/build/gyp_webrtc.py
tkchin5209d672016-04-16 12:06:33 -070020MERGE_SCRIPT=${SCRIPT_DIR}/merge_ios_libs.py
tkchin0090b682016-04-28 18:02:27 -070021LICENSE_SCRIPT=${SCRIPT_DIR}/generate_licenses.py
hjonbc73fe12016-03-21 11:38:26 -070022
tkchin5209d672016-04-16 12:06:33 -070023function check_preconditions {
24 # Check for Darwin.
25 if [[ ! $(uname) = "Darwin" ]]; then
26 echo "OS/X required." >&2
27 exit 1
28 fi
hjonbc73fe12016-03-21 11:38:26 -070029
tkchin5209d672016-04-16 12:06:33 -070030 # Check for libtool.
31 if [[ -z $(which libtool) ]]; then
32 echo "Missing libtool binary." >&2
33 exit 1
hjonbc73fe12016-03-21 11:38:26 -070034 fi
tkchin5209d672016-04-16 12:06:33 -070035
36 # Check for GYP generator.
37 if [[ ! -x ${GYP_WEBRTC_SCRIPT} ]]; then
38 echo "Failed to find gyp generator." >&2
39 exit 1
hjonbc73fe12016-03-21 11:38:26 -070040 fi
tkchin5209d672016-04-16 12:06:33 -070041
tkchin5209d672016-04-16 12:06:33 -070042 # Check for merge script.
43 if [[ ! -x ${MERGE_SCRIPT} ]]; then
44 echo "Failed to find library merging script." >&2
45 exit 1
46 fi
hjonbc73fe12016-03-21 11:38:26 -070047}
48
tkchin5209d672016-04-16 12:06:33 -070049function build_webrtc {
50 local base_output_dir=$1
51 local flavor=$2
52 local target_arch=$3
tkchin9eeb6242016-04-27 01:54:20 -070053 local build_type=$4
54
tkchin5209d672016-04-16 12:06:33 -070055 local ninja_output_dir=${base_output_dir}/${target_arch}_ninja
56 local library_output_dir=${base_output_dir}/${target_arch}_libs
57 if [[ ${target_arch} = 'arm' || ${target_arch} = 'arm64' ]]; then
58 flavor="${flavor}-iphoneos"
59 else
60 flavor="${flavor}-iphonesimulator"
61 fi
tkchin9eeb6242016-04-27 01:54:20 -070062 local ninja_flavor_dir=${ninja_output_dir}/${flavor}
63
64 # Compile framework by default.
65 local gyp_file=webrtc/sdk/sdk.gyp
66 local gyp_target=rtc_sdk_framework_objc
67 # Set to 1 to explicitly not hide symbols. We'll want this if we're just
68 # generating static libs.
69 local override_visibility=0
70 if [[ ${build_type} = "legacy" ]]; then
71 echo "Building legacy."
72 gyp_file=webrtc/build/ios/merge_ios_libs.gyp
73 gyp_target=libjingle_peerconnection_objc_no_op
74 override_visibility=1
75 elif [[ ${build_type} = "static_only" ]]; then
76 echo "Building static only."
77 gyp_file=webrtc/build/ios/merge_ios_libs.gyp
78 gyp_target=rtc_sdk_peerconnection_objc_no_op
79 override_visibility=1
80 elif [[ ${build_type} == "framework" ]]; then
81 echo "Building framework."
82 else
83 echo "Unexpected build type: ${build_type}"
84 exit 1
85 fi
86
tkchin5209d672016-04-16 12:06:33 -070087 export GYP_DEFINES="OS=ios target_arch=${target_arch} use_objc_h264=1 \
tkchin9eeb6242016-04-27 01:54:20 -070088clang_xcode=1 ios_deployment_target=8.0 \
89ios_override_visibility=${override_visibility}"
tkchin5209d672016-04-16 12:06:33 -070090 export GYP_GENERATORS="ninja"
91 export GYP_GENERATOR_FLAGS="output_dir=${ninja_output_dir}"
hjonbc73fe12016-03-21 11:38:26 -070092
tkchin5209d672016-04-16 12:06:33 -070093 # GYP generation requires relative path for some reason.
94 pushd ${WEBRTC_BASE_DIR}
tkchin9eeb6242016-04-27 01:54:20 -070095 webrtc/build/gyp_webrtc.py ${gyp_file}
tkchin5209d672016-04-16 12:06:33 -070096 popd
tkchin9eeb6242016-04-27 01:54:20 -070097 # Compile the target we're interested in.
98 ninja -C ${ninja_flavor_dir} ${gyp_target}
tkchin5209d672016-04-16 12:06:33 -070099
tkchin9eeb6242016-04-27 01:54:20 -0700100 if [[ ${build_type} = "framework" ]]; then
101 # Manually generate the dSYM files before stripping them. GYP does not seem
102 # to instruct ninja to generate dSYM files.
103 dsymutil --out=${ninja_flavor_dir}/WebRTC.framework.dSYM \
104 ${ninja_flavor_dir}/WebRTC.framework/WebRTC
105 fi
106
107 # Make links to the generated static archives.
108 mkdir -p ${library_output_dir}
109 for f in ${ninja_flavor_dir}/*.a
tkchin5209d672016-04-16 12:06:33 -0700110 do
111 ln -sf "${f}" "${library_output_dir}/$(basename ${f})"
112 done
113}
114
115function clean_artifacts {
116 local output_dir=$1
117 if [[ -d ${output_dir} ]]; then
118 rm -r ${output_dir}
119 fi
120}
121
122function usage {
123 echo "WebRTC iOS FAT libraries build script."
124 echo "Each architecture is compiled separately before being merged together."
125 echo "By default, the fat libraries will be created in out_ios_libs/fat_libs."
126 echo "The headers will be copied to out_ios_libs/include."
tkchin9eeb6242016-04-27 01:54:20 -0700127 echo "Usage: $0 [-h] [-b build_type] [-c] [-o output_dir]"
tkchin5209d672016-04-16 12:06:33 -0700128 echo " -h Print this help."
tkchin9eeb6242016-04-27 01:54:20 -0700129 echo " -b The build type. Can be framework, static_only or legacy."
130 echo " Defaults to framework."
tkchin5209d672016-04-16 12:06:33 -0700131 echo " -c Removes generated build output."
132 echo " -o Specifies a directory to output build artifacts to."
133 echo " If specified together with -c, deletes the dir."
tkchin9eeb6242016-04-27 01:54:20 -0700134 echo " -r Specifies a revision number to embed if building the framework."
tkchin5209d672016-04-16 12:06:33 -0700135 exit 0
136}
137
138check_preconditions
139
140# Set default arguments.
141# Output directory for build artifacts.
142OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs
tkchin9eeb6242016-04-27 01:54:20 -0700143# The type of build to perform. Valid arguments are framework, static_only and
144# legacy.
145BUILD_TYPE="framework"
tkchin5209d672016-04-16 12:06:33 -0700146PERFORM_CLEAN=0
tkchin9eeb6242016-04-27 01:54:20 -0700147FLAVOR="Profile"
148POINT_VERSION="0"
tkchin5209d672016-04-16 12:06:33 -0700149
150# Parse arguments.
tkchin9eeb6242016-04-27 01:54:20 -0700151while getopts "hb:co:r:" opt; do
tkchin5209d672016-04-16 12:06:33 -0700152 case "${opt}" in
153 h) usage;;
tkchin9eeb6242016-04-27 01:54:20 -0700154 b) BUILD_TYPE="${OPTARG}";;
tkchin5209d672016-04-16 12:06:33 -0700155 c) PERFORM_CLEAN=1;;
156 o) OUTPUT_DIR="${OPTARG}";;
tkchin9eeb6242016-04-27 01:54:20 -0700157 r) POINT_VERSION="${OPTARG}";;
tkchin5209d672016-04-16 12:06:33 -0700158 *)
159 usage
160 exit 1
161 ;;
162 esac
163done
164
165if [[ ${PERFORM_CLEAN} -ne 0 ]]; then
166 clean_artifacts ${OUTPUT_DIR}
167 exit 0
168fi
169
170# Build all the common architectures.
tkchin9eeb6242016-04-27 01:54:20 -0700171ARCHS=( "arm" "arm64" "ia32" "x64" )
172for ARCH in "${ARCHS[@]}"
tkchin5209d672016-04-16 12:06:33 -0700173do
tkchin9eeb6242016-04-27 01:54:20 -0700174 echo "Building WebRTC arch: ${ARCH}"
175 build_webrtc ${OUTPUT_DIR} ${FLAVOR} $ARCH ${BUILD_TYPE}
tkchin5209d672016-04-16 12:06:33 -0700176done
hjonbc73fe12016-03-21 11:38:26 -0700177
tkchin9eeb6242016-04-27 01:54:20 -0700178ARM_NINJA_DIR=${OUTPUT_DIR}/arm_ninja/${FLAVOR}-iphoneos
179ARM64_NINJA_DIR=${OUTPUT_DIR}/arm64_ninja/${FLAVOR}-iphoneos
180IA32_NINJA_DIR=${OUTPUT_DIR}/ia32_ninja/${FLAVOR}-iphonesimulator
181X64_NINJA_DIR=${OUTPUT_DIR}/x64_ninja/${FLAVOR}-iphonesimulator
hjonbc73fe12016-03-21 11:38:26 -0700182
tkchin9eeb6242016-04-27 01:54:20 -0700183if [[ ${BUILD_TYPE} = "framework" ]]; then
184 # Merge the framework slices together into a FAT library by copying one arch
185 # output and merging the rest in.
186 DYLIB_PATH="WebRTC.framework/WebRTC"
187 cp -R ${ARM_NINJA_DIR}/WebRTC.framework ${OUTPUT_DIR}
188 rm ${OUTPUT_DIR}/${DYLIB_PATH}
189 echo "Merging framework slices."
190 lipo ${ARM_NINJA_DIR}/${DYLIB_PATH} \
191 ${ARM64_NINJA_DIR}/${DYLIB_PATH} \
192 ${IA32_NINJA_DIR}/${DYLIB_PATH} \
193 ${X64_NINJA_DIR}/${DYLIB_PATH} \
194 -create -output ${OUTPUT_DIR}/${DYLIB_PATH}
195
196 # Merge the dSYM files together in a similar fashion.
197 DSYM_PATH="WebRTC.framework.dSYM/Contents/Resources/DWARF/WebRTC"
198 cp -R ${ARM_NINJA_DIR}/WebRTC.framework.dSYM ${OUTPUT_DIR}
199 rm ${OUTPUT_DIR}/${DSYM_PATH}
200 echo "Merging dSYM slices."
201 lipo ${ARM_NINJA_DIR}/${DSYM_PATH} \
202 ${ARM64_NINJA_DIR}/${DSYM_PATH} \
203 ${IA32_NINJA_DIR}/${DSYM_PATH} \
204 ${X64_NINJA_DIR}/${DSYM_PATH} \
205 -create -output ${OUTPUT_DIR}/${DSYM_PATH}
206
207 # Strip the dynamic framework of non-global symbols.
208 # TODO(tkchin): Override chromium strip settings in supplement.gypi instead.
209 echo "Stripping non-global symbols."
210 strip -x ${OUTPUT_DIR}/${DYLIB_PATH}
211
212 # Modify the version number.
213 INFOPLIST_PATH=${OUTPUT_DIR}/WebRTC.framework/Resources/Info.plist
214 MAJOR_MINOR=$(plistbuddy -c "Print :CFBundleShortVersionString" \
215 ${INFOPLIST_PATH})
216 VERSION_NUMBER="${MAJOR_MINOR}.${POINT_VERSION}"
217 echo "Substituting revision number: ${VERSION_NUMBER}"
218 plistbuddy -c "Set :CFBundleVersion ${VERSION_NUMBER}" ${INFOPLIST_PATH}
219 plutil -convert binary1 ${INFOPLIST_PATH}
220
221 # Copy pod file.
222 FORMAT_STRING=s/\${FRAMEWORK_VERSION_NUMBER}/${VERSION_NUMBER}/g
223 sed -e ${FORMAT_STRING} ${WEBRTC_BASE_DIR}/webrtc/sdk/objc/WebRTC.podspec > \
224 ${OUTPUT_DIR}/WebRTC.podspec
225else
226 echo "Merging static library slices."
227 # Merge the static libraries together into individual FAT archives.
228 ${MERGE_SCRIPT} ${OUTPUT_DIR}
229
230 # Merge the dSYM files together.
231 TARGET_NAME="rtc_sdk_peerconnection_objc_no_op"
232 if [[ ${BUILD_TYPE} = "legacy" ]]; then
233 TARGET_NAME="libjingle_peerconnection_objc_no_op"
234 fi
235 DSYM_PATH="${TARGET_NAME}.app.dSYM/Contents/Resources/DWARF/${TARGET_NAME}"
236 cp -R ${ARM_NINJA_DIR}/${TARGET_NAME}.app.dSYM ${OUTPUT_DIR}
237 echo "Merging dSYM slices."
238 lipo ${ARM_NINJA_DIR}/${DSYM_PATH} \
239 ${ARM64_NINJA_DIR}/${DSYM_PATH} \
240 ${IA32_NINJA_DIR}/${DSYM_PATH} \
241 ${X64_NINJA_DIR}/${DSYM_PATH} \
242 -create -output ${OUTPUT_DIR}/${DSYM_PATH}
243
244 # Strip debugging symbols.
245 # TODO(tkchin): Override chromium settings in supplement.gypi instead to do
246 # stripping at build time.
247 echo "Stripping debug symbols."
248 strip -S ${OUTPUT_DIR}/fat_libs/*.a
249
250 # Symlink the headers.
251 echo "Symlinking headers."
252 INPUT_HEADER_DIR="${WEBRTC_BASE_DIR}/webrtc/sdk/objc/Framework/Headers/WebRTC"
253 OUTPUT_HEADER_DIR="${OUTPUT_DIR}/include"
254 if [[ -d ${OUTPUT_HEADER_DIR} ]]; then
255 rm -rf ${OUTPUT_HEADER_DIR}
256 fi
257 if [[ ${BUILD_TYPE} = "legacy" ]]; then
258 INPUT_HEADER_DIR="${WEBRTC_BASE_DIR}/talk/app/webrtc/objc/public"
259 ln -sf ${INPUT_HEADER_DIR} ${OUTPUT_HEADER_DIR}
260 else
261 mkdir -p ${OUTPUT_HEADER_DIR}
262 ln -sf ${INPUT_HEADER_DIR} ${OUTPUT_HEADER_DIR}/WebRTC
263 fi
264fi
265
tkchin0090b682016-04-28 18:02:27 -0700266echo "Generating LICENSE.html."
267${LICENSE_SCRIPT} ${OUTPUT_DIR}/arm64_libs ${OUTPUT_DIR}
268
tkchin9eeb6242016-04-27 01:54:20 -0700269echo "Done!"