hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 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 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 11 | # Generates static or dynamic FAT libraries for ios in out_ios_libs. |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 12 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 13 | # Exit on errors. |
| 14 | set -e |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 15 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 16 | # Globals. |
| 17 | SCRIPT_DIR=$(cd $(dirname $0) && pwd) |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 18 | WEBRTC_BASE_DIR=${SCRIPT_DIR}/../../.. |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 19 | GYP_WEBRTC_SCRIPT=${WEBRTC_BASE_DIR}/webrtc/build/gyp_webrtc.py |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 20 | MERGE_SCRIPT=${SCRIPT_DIR}/merge_ios_libs.py |
tkchin | 0090b68 | 2016-04-28 18:02:27 -0700 | [diff] [blame] | 21 | LICENSE_SCRIPT=${SCRIPT_DIR}/generate_licenses.py |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 22 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 23 | function check_preconditions { |
| 24 | # Check for Darwin. |
| 25 | if [[ ! $(uname) = "Darwin" ]]; then |
| 26 | echo "OS/X required." >&2 |
| 27 | exit 1 |
| 28 | fi |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 29 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 30 | # Check for libtool. |
| 31 | if [[ -z $(which libtool) ]]; then |
| 32 | echo "Missing libtool binary." >&2 |
| 33 | exit 1 |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 34 | fi |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 35 | |
| 36 | # Check for GYP generator. |
| 37 | if [[ ! -x ${GYP_WEBRTC_SCRIPT} ]]; then |
| 38 | echo "Failed to find gyp generator." >&2 |
| 39 | exit 1 |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 40 | fi |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 41 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 42 | # Check for merge script. |
| 43 | if [[ ! -x ${MERGE_SCRIPT} ]]; then |
| 44 | echo "Failed to find library merging script." >&2 |
| 45 | exit 1 |
| 46 | fi |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 47 | } |
| 48 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 49 | function build_webrtc { |
| 50 | local base_output_dir=$1 |
| 51 | local flavor=$2 |
| 52 | local target_arch=$3 |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 53 | local build_type=$4 |
| 54 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 55 | 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 |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 62 | 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 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 87 | export GYP_DEFINES="OS=ios target_arch=${target_arch} use_objc_h264=1 \ |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 88 | clang_xcode=1 ios_deployment_target=8.0 \ |
| 89 | ios_override_visibility=${override_visibility}" |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 90 | export GYP_GENERATORS="ninja" |
| 91 | export GYP_GENERATOR_FLAGS="output_dir=${ninja_output_dir}" |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 92 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 93 | # GYP generation requires relative path for some reason. |
| 94 | pushd ${WEBRTC_BASE_DIR} |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 95 | webrtc/build/gyp_webrtc.py ${gyp_file} |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 96 | popd |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 97 | # Compile the target we're interested in. |
| 98 | ninja -C ${ninja_flavor_dir} ${gyp_target} |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 99 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 100 | 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 |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 110 | do |
| 111 | ln -sf "${f}" "${library_output_dir}/$(basename ${f})" |
| 112 | done |
| 113 | } |
| 114 | |
| 115 | function clean_artifacts { |
| 116 | local output_dir=$1 |
| 117 | if [[ -d ${output_dir} ]]; then |
| 118 | rm -r ${output_dir} |
| 119 | fi |
| 120 | } |
| 121 | |
| 122 | function 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." |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 127 | echo "Usage: $0 [-h] [-b build_type] [-c] [-o output_dir]" |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 128 | echo " -h Print this help." |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 129 | echo " -b The build type. Can be framework, static_only or legacy." |
| 130 | echo " Defaults to framework." |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 131 | 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." |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 134 | echo " -r Specifies a revision number to embed if building the framework." |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 135 | exit 0 |
| 136 | } |
| 137 | |
| 138 | check_preconditions |
| 139 | |
| 140 | # Set default arguments. |
| 141 | # Output directory for build artifacts. |
| 142 | OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 143 | # The type of build to perform. Valid arguments are framework, static_only and |
| 144 | # legacy. |
| 145 | BUILD_TYPE="framework" |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 146 | PERFORM_CLEAN=0 |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 147 | FLAVOR="Profile" |
| 148 | POINT_VERSION="0" |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 149 | |
| 150 | # Parse arguments. |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 151 | while getopts "hb:co:r:" opt; do |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 152 | case "${opt}" in |
| 153 | h) usage;; |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 154 | b) BUILD_TYPE="${OPTARG}";; |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 155 | c) PERFORM_CLEAN=1;; |
| 156 | o) OUTPUT_DIR="${OPTARG}";; |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 157 | r) POINT_VERSION="${OPTARG}";; |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 158 | *) |
| 159 | usage |
| 160 | exit 1 |
| 161 | ;; |
| 162 | esac |
| 163 | done |
| 164 | |
| 165 | if [[ ${PERFORM_CLEAN} -ne 0 ]]; then |
| 166 | clean_artifacts ${OUTPUT_DIR} |
| 167 | exit 0 |
| 168 | fi |
| 169 | |
| 170 | # Build all the common architectures. |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 171 | ARCHS=( "arm" "arm64" "ia32" "x64" ) |
| 172 | for ARCH in "${ARCHS[@]}" |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 173 | do |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 174 | echo "Building WebRTC arch: ${ARCH}" |
| 175 | build_webrtc ${OUTPUT_DIR} ${FLAVOR} $ARCH ${BUILD_TYPE} |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame] | 176 | done |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 177 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 178 | ARM_NINJA_DIR=${OUTPUT_DIR}/arm_ninja/${FLAVOR}-iphoneos |
| 179 | ARM64_NINJA_DIR=${OUTPUT_DIR}/arm64_ninja/${FLAVOR}-iphoneos |
| 180 | IA32_NINJA_DIR=${OUTPUT_DIR}/ia32_ninja/${FLAVOR}-iphonesimulator |
| 181 | X64_NINJA_DIR=${OUTPUT_DIR}/x64_ninja/${FLAVOR}-iphonesimulator |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 182 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 183 | if [[ ${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 |
| 225 | else |
| 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 |
| 264 | fi |
| 265 | |
tkchin | 0090b68 | 2016-04-28 18:02:27 -0700 | [diff] [blame] | 266 | echo "Generating LICENSE.html." |
| 267 | ${LICENSE_SCRIPT} ${OUTPUT_DIR}/arm64_libs ${OUTPUT_DIR} |
| 268 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 269 | echo "Done!" |