blob: 144152750abbde2a130e0e590594cbd509693b9f [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
tkchin5fa51e22016-10-05 13:16:03 -070011# Generates static 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
VladimirTechMan18b87742016-10-30 23:09:44 -070016# Environment
17export PATH=/usr/libexec:$PATH
18
tkchin5209d672016-04-16 12:06:33 -070019SCRIPT_DIR=$(cd $(dirname $0) && pwd)
Mirko Bonadeib0dd7842017-01-26 14:52:27 +010020WEBRTC_BASE_DIR=${SCRIPT_DIR}/../..
hjonbc73fe12016-03-21 11:38:26 -070021
Zeke Chindd0e1e02016-10-11 13:27:26 -070022function clean_artifacts {
23 local output_dir=$1
24 if [[ -d ${output_dir} ]]; then
25 echo "Deleting ${output_dir}"
26 rm -r ${output_dir}
27 fi
hjonbc73fe12016-03-21 11:38:26 -070028}
29
Zeke Chindd0e1e02016-10-11 13:27:26 -070030function build_webrtc {
31 local target_arch=$1
32 local flavor=$2
33 local build_type=$3
34 local ios_deployment_target=$4
35 local libvpx_build_vp9=$5
tkchinfb94cd62016-11-21 23:30:56 -080036 local use_bitcode=$6
37 local custom_gn_options=$7
hjonbc73fe12016-03-21 11:38:26 -070038
Zeke Chindd0e1e02016-10-11 13:27:26 -070039 OUTPUT_DIR=${SDK_OUTPUT_DIR}/${target_arch}_libs
40 GN_ARGS="target_os=\"ios\" ios_enable_code_signing=false \
tkchinfb94cd62016-11-21 23:30:56 -080041use_xcode_clang=true is_component_build=false"
Zeke Chindd0e1e02016-10-11 13:27:26 -070042
43 # Add flavor option.
44 if [[ ${flavor} = "debug" ]]; then
45 GN_ARGS="${GN_ARGS} is_debug=true"
46 elif [[ ${flavor} = "release" ]]; then
47 GN_ARGS="${GN_ARGS} is_debug=false"
48 else
49 echo "Unexpected flavor type: ${flavor}"
50 exit 1
51 fi
52
53 # Add the specified architecture.
Zeke Chindd0e1e02016-10-11 13:27:26 -070054 GN_ARGS="${GN_ARGS} target_cpu=\"${target_arch}\""
55
56 # Add deployment target.
57 GN_ARGS="${GN_ARGS} ios_deployment_target=\"${ios_deployment_target}\""
58
59 # Add vp9 option.
60 GN_ARGS="${GN_ARGS} rtc_libvpx_build_vp9=${libvpx_build_vp9}"
61
tkchinfb94cd62016-11-21 23:30:56 -080062 # Add bitcode option.
VladimirTechMan0fc04b72017-01-20 08:01:36 -080063 GN_ARGS="${GN_ARGS} enable_ios_bitcode=${use_bitcode}"
tkchinfb94cd62016-11-21 23:30:56 -080064
Zeke Chindd0e1e02016-10-11 13:27:26 -070065 # Add custom options.
66 if [[ -n "${custom_gn_options}" ]]; then
67 GN_ARGS="${GN_ARGS} ${custom_gn_options}"
68 fi
69
70 # Generate static or dynamic.
71 if [[ ${build_type} = "static_only" ]]; then
72 GN_TARGET_NAME="rtc_sdk_objc"
73 elif [[ ${build_type} == "framework" ]]; then
74 GN_TARGET_NAME="rtc_sdk_framework_objc"
75 GN_ARGS="${GN_ARGS} enable_dsyms=true enable_stripping=true"
VladimirTechMan1a7f01c2017-01-25 14:30:15 -080076 else
77 echo "Build type \"${build_type}\" is not supported."
78 exit 1
Zeke Chindd0e1e02016-10-11 13:27:26 -070079 fi
80
81 echo "Building WebRTC with args: ${GN_ARGS}"
82 gn gen ${OUTPUT_DIR} --args="${GN_ARGS}"
83 echo "Building target: ${GN_TARGET_NAME}"
84 ninja -C ${OUTPUT_DIR} ${GN_TARGET_NAME}
85
86 # Strip debug symbols to reduce size.
87 if [[ ${build_type} = "static_only" ]]; then
88 strip -S ${OUTPUT_DIR}/obj/webrtc/sdk/lib${GN_TARGET_NAME}.a -o \
89 ${OUTPUT_DIR}/lib${GN_TARGET_NAME}.a
90 fi
91}
92
93function usage {
94 echo "WebRTC iOS FAT libraries build script."
95 echo "Each architecture is compiled separately before being merged together."
VladimirTechMan2d8cd582017-01-25 12:33:40 -080096 echo "By default, the library is created in out_ios_libs/. (Change with -o.)"
Zeke Chindd0e1e02016-10-11 13:27:26 -070097 echo "The headers will be copied to out_ios_libs/include."
VladimirTechMan2d8cd582017-01-25 12:33:40 -080098 echo "Usage: $0 [-h] [-b build_type] [-c] [-o output_dir] [-r rev_num] [-e]"
Zeke Chindd0e1e02016-10-11 13:27:26 -070099 echo " -h Print this help."
VladimirTechMan2d8cd582017-01-25 12:33:40 -0800100 echo " -b The build type. Can be \"framework\" or \"static_only\"."
101 echo " Defaults to \"framework\"."
102 echo " -c Removes the previously generated build output, if any."
103 echo " -o Specifies a directory to output the build artifacts to."
Zeke Chindd0e1e02016-10-11 13:27:26 -0700104 echo " If specified together with -c, deletes the dir."
105 echo " -r Specifies a revision number to embed if building the framework."
tkchinfb94cd62016-11-21 23:30:56 -0800106 echo " -e Compile with bitcode."
Zeke Chindd0e1e02016-10-11 13:27:26 -0700107 exit 0
108}
109
110SDK_OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs
111SDK_LIB_NAME="librtc_sdk_objc.a"
112SDK_FRAMEWORK_NAME="WebRTC.framework"
113
114BUILD_FLAVOR="release"
115BUILD_TYPE="framework"
kthelgason5ec208f2016-11-10 01:13:43 -0800116ENABLED_ARCHITECTURES=("arm" "arm64" "x64")
Zeke Chindd0e1e02016-10-11 13:27:26 -0700117IOS_DEPLOYMENT_TARGET="8.0"
118LIBVPX_BUILD_VP9="false"
tkchinfb94cd62016-11-21 23:30:56 -0800119USE_BITCODE="false"
Zeke Chindd0e1e02016-10-11 13:27:26 -0700120CUSTOM_GN_OPTS=""
121WEBRTC_REVISION="0"
122
123# Parse arguments.
VladimirTechMan0fc04b72017-01-20 08:01:36 -0800124while getopts "hb:co:r:e" opt; do
Zeke Chindd0e1e02016-10-11 13:27:26 -0700125 case "${opt}" in
126 h) usage;;
127 b) BUILD_TYPE="${OPTARG}";;
128 c) PERFORM_CLEAN=1;;
tkchinfb94cd62016-11-21 23:30:56 -0800129 e) USE_BITCODE="true";;
Zeke Chindd0e1e02016-10-11 13:27:26 -0700130 o) SDK_OUTPUT_DIR="${OPTARG}";;
131 r) WEBRTC_REVISION="${OPTARG}";;
132 *)
133 usage
134 exit 1
135 ;;
136 esac
137done
138
139if [[ ${PERFORM_CLEAN} -ne 0 ]]; then
140 clean_artifacts ${SDK_OUTPUT_DIR}
141 exit 0
142fi
143
144# Build all architectures.
kthelgason5ec208f2016-11-10 01:13:43 -0800145for arch in ${ENABLED_ARCHITECTURES[*]}; do
146 build_webrtc $arch ${BUILD_FLAVOR} ${BUILD_TYPE} \
tkchinfb94cd62016-11-21 23:30:56 -0800147 ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${USE_BITCODE} \
148 ${CUSTOM_GN_OPTS}
kthelgason5ec208f2016-11-10 01:13:43 -0800149done
Zeke Chindd0e1e02016-10-11 13:27:26 -0700150
151# Ignoring x86 except for static libraries for now because of a GN build issue
152# where the generated dynamic framework has the wrong architectures.
153
154# Create FAT archive.
155if [[ ${BUILD_TYPE} = "static_only" ]]; then
156 build_webrtc "x86" ${BUILD_FLAVOR} ${BUILD_TYPE} \
tkchinfb94cd62016-11-21 23:30:56 -0800157 ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${USE_BITCODE} \
158 ${CUSTOM_GN_OPTS}
Zeke Chindd0e1e02016-10-11 13:27:26 -0700159
160 ARM_LIB_PATH=${SDK_OUTPUT_DIR}/arm_libs/${SDK_LIB_NAME}
161 ARM64_LIB_PATH=${SDK_OUTPUT_DIR}/arm64_libs/${SDK_LIB_NAME}
162 X64_LIB_PATH=${SDK_OUTPUT_DIR}/x64_libs/${SDK_LIB_NAME}
163 X86_LIB_PATH=${SDK_OUTPUT_DIR}/x86_libs/${SDK_LIB_NAME}
164
165 # Combine the slices.
166 lipo ${ARM_LIB_PATH} ${ARM64_LIB_PATH} ${X64_LIB_PATH} ${X86_LIB_PATH} \
167 -create -output ${SDK_OUTPUT_DIR}/${SDK_LIB_NAME}
168elif [[ ${BUILD_TYPE} = "framework" ]]; then
169 ARM_LIB_PATH=${SDK_OUTPUT_DIR}/arm_libs
170 ARM64_LIB_PATH=${SDK_OUTPUT_DIR}/arm64_libs
171 X64_LIB_PATH=${SDK_OUTPUT_DIR}/x64_libs
172 X86_LIB_PATH=${SDK_OUTPUT_DIR}/x86_libs
173
174 # Combine the slices.
175 DYLIB_PATH="WebRTC.framework/WebRTC"
176 cp -R ${ARM64_LIB_PATH}/WebRTC.framework ${SDK_OUTPUT_DIR}
177 rm ${SDK_OUTPUT_DIR}/${DYLIB_PATH}
178 echo "Merging framework slices."
179 lipo ${ARM_LIB_PATH}/${DYLIB_PATH} \
180 ${ARM64_LIB_PATH}/${DYLIB_PATH} \
181 ${X64_LIB_PATH}/${DYLIB_PATH} \
182 -create -output ${SDK_OUTPUT_DIR}/${DYLIB_PATH}
183
Zeke Chindd0e1e02016-10-11 13:27:26 -0700184 # Merge the dSYM slices.
185 DSYM_PATH="WebRTC.dSYM/Contents/Resources/DWARF/WebRTC"
186 cp -R ${ARM64_LIB_PATH}/WebRTC.dSYM ${SDK_OUTPUT_DIR}
187 rm ${SDK_OUTPUT_DIR}/${DSYM_PATH}
188 echo "Merging dSYM slices."
189 lipo ${ARM_LIB_PATH}/${DSYM_PATH} \
190 ${ARM64_LIB_PATH}/${DSYM_PATH} \
191 ${X64_LIB_PATH}/${DSYM_PATH} \
192 -create -output ${SDK_OUTPUT_DIR}/${DSYM_PATH}
193
194 # Modify the version number.
195 # Format should be <Branch cut MXX>.<Hotfix #>.<Rev #>.
196 # e.g. 55.0.14986 means branch cut 55, no hotfixes, and revision number 14986.
197 INFOPLIST_PATH=${SDK_OUTPUT_DIR}/WebRTC.framework/Info.plist
198 MAJOR_MINOR=$(PlistBuddy -c "Print :CFBundleShortVersionString" \
199 ${INFOPLIST_PATH})
200 VERSION_NUMBER="${MAJOR_MINOR}.${WEBRTC_REVISION}"
201 echo "Substituting revision number: ${VERSION_NUMBER}"
202 PlistBuddy -c "Set :CFBundleVersion ${VERSION_NUMBER}" ${INFOPLIST_PATH}
203 plutil -convert binary1 ${INFOPLIST_PATH}
204else
205 echo "BUILD_TYPE ${BUILD_TYPE} not supported."
206 exit 1
207fi
hjonbc73fe12016-03-21 11:38:26 -0700208
tkchin5fa51e22016-10-05 13:16:03 -0700209echo "Done."