blob: a01d128373eb216f499d0a800700e26b690b8b61 [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
11# Generates static FAT libraries for ios in out_ios_libs.
12
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}/../../..
19GYP_WEBRTC_SCRIPT=${WEBRTC_BASE_DIR}/webrtc/build/gyp_webrtc
tkchin5209d672016-04-16 12:06:33 -070020EXPORT_HEADERS_SCRIPT=${SCRIPT_DIR}/export_headers.py
21MERGE_SCRIPT=${SCRIPT_DIR}/merge_ios_libs.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
42 # Check for export headers script.
43 if [[ ! -x ${EXPORT_HEADERS_SCRIPT} ]]; then
44 echo "Failed to find export headers script." >&2
45 exit 1
46 fi
47
48 # Check for merge script.
49 if [[ ! -x ${MERGE_SCRIPT} ]]; then
50 echo "Failed to find library merging script." >&2
51 exit 1
52 fi
hjonbc73fe12016-03-21 11:38:26 -070053}
54
tkchin5209d672016-04-16 12:06:33 -070055function build_webrtc {
56 local base_output_dir=$1
57 local flavor=$2
58 local target_arch=$3
59 local ninja_output_dir=${base_output_dir}/${target_arch}_ninja
60 local library_output_dir=${base_output_dir}/${target_arch}_libs
61 if [[ ${target_arch} = 'arm' || ${target_arch} = 'arm64' ]]; then
62 flavor="${flavor}-iphoneos"
63 else
64 flavor="${flavor}-iphonesimulator"
65 fi
66 export GYP_DEFINES="OS=ios target_arch=${target_arch} use_objc_h264=1 \
67clang_xcode=1 ios_override_visibility=1"
68 export GYP_GENERATORS="ninja"
69 export GYP_GENERATOR_FLAGS="output_dir=${ninja_output_dir}"
hjonbc73fe12016-03-21 11:38:26 -070070
tkchin5209d672016-04-16 12:06:33 -070071 # GYP generation requires relative path for some reason.
72 pushd ${WEBRTC_BASE_DIR}
73 webrtc/build/gyp_webrtc webrtc/build/ios/merge_ios_libs.gyp
74 popd
75 if [[ ${USE_LEGACY_API} -eq 1 ]]; then
76 ninja -C ${ninja_output_dir}/${flavor} libjingle_peerconnection_objc_no_op
77 else
78 ninja -C ${ninja_output_dir}/${flavor} webrtc_api_objc_no_op
79 fi
80 mkdir -p ${library_output_dir}
81
82 for f in ${ninja_output_dir}/${flavor}/*.a
83 do
84 ln -sf "${f}" "${library_output_dir}/$(basename ${f})"
85 done
86}
87
88function clean_artifacts {
89 local output_dir=$1
90 if [[ -d ${output_dir} ]]; then
91 rm -r ${output_dir}
92 fi
93}
94
95function usage {
96 echo "WebRTC iOS FAT libraries build script."
97 echo "Each architecture is compiled separately before being merged together."
98 echo "By default, the fat libraries will be created in out_ios_libs/fat_libs."
99 echo "The headers will be copied to out_ios_libs/include."
100 echo "Usage: $0 [-h] [-c] [-o]"
101 echo " -h Print this help."
102 echo " -c Removes generated build output."
103 echo " -o Specifies a directory to output build artifacts to."
104 echo " If specified together with -c, deletes the dir."
105 exit 0
106}
107
108check_preconditions
109
110# Set default arguments.
111# Output directory for build artifacts.
112OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs
113# Flag to build the new or legacy version of the API.
114USE_LEGACY_API=0
115PERFORM_CLEAN=0
116
117# Parse arguments.
118while getopts "hco:" opt; do
119 case "${opt}" in
120 h) usage;;
121 c) PERFORM_CLEAN=1;;
122 o) OUTPUT_DIR="${OPTARG}";;
123 *)
124 usage
125 exit 1
126 ;;
127 esac
128done
129
130if [[ ${PERFORM_CLEAN} -ne 0 ]]; then
131 clean_artifacts ${OUTPUT_DIR}
132 exit 0
133fi
134
135# Build all the common architectures.
136archs=( "arm" "arm64" "ia32" "x64" )
137for arch in "${archs[@]}"
138do
139 echo "Building WebRTC arch: ${arch}"
140 build_webrtc ${OUTPUT_DIR} "Profile" $arch
141done
hjonbc73fe12016-03-21 11:38:26 -0700142
143# Export header files.
tkchin5209d672016-04-16 12:06:33 -0700144${EXPORT_HEADERS_SCRIPT} ${OUTPUT_DIR} ${USE_LEGACY_API}
hjonbc73fe12016-03-21 11:38:26 -0700145
146# Merge the libraries together.
tkchin5209d672016-04-16 12:06:33 -0700147${MERGE_SCRIPT} ${OUTPUT_DIR}