Index: webrtc/build/ios/build_ios_libs.sh |
diff --git a/webrtc/build/ios/build_ios_libs.sh b/webrtc/build/ios/build_ios_libs.sh |
index 5d6157aab2f5e21e0de5bbfd794326876174a2a7..9a9f613e310c7bf4c3d98824dfc1a6641e9572c1 100755 |
--- a/webrtc/build/ios/build_ios_libs.sh |
+++ b/webrtc/build/ios/build_ios_libs.sh |
@@ -10,77 +10,130 @@ |
# Generates static FAT libraries for ios in out_ios_libs. |
-# Flag to build the new or legacy version of the API. |
-USE_LEGACY_API=0 |
+# Exit on errors. |
+set -e |
-# Check for Darwin. |
-if [[ ! $(uname) = "Darwin" ]]; then |
- echo "OS/X required." >&2 |
-fi |
- |
-# Check for libtool. |
-if [[ -z $(which libtool) ]]; then |
- echo "Missing libtool binary." >&2 |
-fi |
- |
-# Check for GYP generator. |
-SCRIPT_DIR=$(dirname $0) |
+# Globals. |
+SCRIPT_DIR=$(cd $(dirname $0) && pwd) |
WEBRTC_BASE_DIR=${SCRIPT_DIR}/../../.. |
GYP_WEBRTC_SCRIPT=${WEBRTC_BASE_DIR}/webrtc/build/gyp_webrtc |
-if [[ ! -x ${GYP_WEBRTC_SCRIPT} ]]; then |
- echo "Failed to find gyp generator." >&2 |
- exit 1 |
-fi |
-# Check for export headers script. |
-EXPORT_HEADERS_SCRIPT=${SCRIPT_DIR}/export_headers |
-if [[ ! -x ${EXPORT_HEADERS_SCRIPT} ]]; then |
- echo "Failed to find export headers script." >&2 |
- exit 1 |
-fi |
-# Check for merge script. |
-MERGE_SCRIPT=${SCRIPT_DIR}/merge_ios_libs |
-if [[ ! -x ${MERGE_SCRIPT} ]]; then |
- echo "Failed to find library merging script." >&2 |
- exit 1 |
-fi |
+EXPORT_HEADERS_SCRIPT=${SCRIPT_DIR}/export_headers.py |
+MERGE_SCRIPT=${SCRIPT_DIR}/merge_ios_libs.py |
-pushd ${WEBRTC_BASE_DIR} |
-LIBRARY_BASE_DIR="out_ios_libs" |
+function check_preconditions { |
+ # Check for Darwin. |
+ if [[ ! $(uname) = "Darwin" ]]; then |
+ echo "OS/X required." >&2 |
+ exit 1 |
+ fi |
+ |
+ # Check for libtool. |
+ if [[ -z $(which libtool) ]]; then |
+ echo "Missing libtool binary." >&2 |
+ exit 1 |
+ fi |
+ |
+ # Check for GYP generator. |
+ if [[ ! -x ${GYP_WEBRTC_SCRIPT} ]]; then |
+ echo "Failed to find gyp generator." >&2 |
+ exit 1 |
+ fi |
+ |
+ # Check for export headers script. |
+ if [[ ! -x ${EXPORT_HEADERS_SCRIPT} ]]; then |
+ echo "Failed to find export headers script." >&2 |
+ exit 1 |
+ fi |
+ |
+ # Check for merge script. |
+ if [[ ! -x ${MERGE_SCRIPT} ]]; then |
+ echo "Failed to find library merging script." >&2 |
+ exit 1 |
+ fi |
+} |
function build_webrtc { |
- OUTPUT_DIR=$1 |
- FLAVOR=$2 |
- TARGET_ARCH=$3 |
- if [[ ${TARGET_ARCH} = 'arm' || ${TARGET_ARCH} = 'arm64' ]]; then |
- FLAVOR="${FLAVOR}-iphoneos" |
+ local base_output_dir=$1 |
+ local flavor=$2 |
+ local target_arch=$3 |
+ local ninja_output_dir=${base_output_dir}/${target_arch}_ninja |
+ local library_output_dir=${base_output_dir}/${target_arch}_libs |
+ if [[ ${target_arch} = 'arm' || ${target_arch} = 'arm64' ]]; then |
+ flavor="${flavor}-iphoneos" |
else |
- FLAVOR="${FLAVOR}-iphonesimulator" |
+ flavor="${flavor}-iphonesimulator" |
fi |
- export GYP_DEFINES="OS=ios target_arch=${TARGET_ARCH} use_objc_h264=1 \ |
+ export GYP_DEFINES="OS=ios target_arch=${target_arch} use_objc_h264=1 \ |
clang_xcode=1 ios_override_visibility=1" |
export GYP_GENERATORS="ninja" |
- export GYP_GENERATOR_FLAGS="output_dir=${OUTPUT_DIR}" |
+ export GYP_GENERATOR_FLAGS="output_dir=${ninja_output_dir}" |
webrtc/build/gyp_webrtc webrtc/build/ios/merge_ios_libs.gyp |
if [[ ${USE_LEGACY_API} -eq 1 ]]; then |
- ninja -C ${OUTPUT_DIR}/${FLAVOR} libjingle_peerconnection_objc_no_op |
+ ninja -C ${ninja_output_dir}/${flavor} libjingle_peerconnection_objc_no_op |
else |
- ninja -C ${OUTPUT_DIR}/${FLAVOR} webrtc_api_objc_no_op |
+ ninja -C ${ninja_output_dir}/${flavor} webrtc_api_objc_no_op |
fi |
- mkdir -p ${LIBRARY_BASE_DIR}/${TARGET_ARCH} |
- mv ${OUTPUT_DIR}/${FLAVOR}/*.a ${LIBRARY_BASE_DIR}/${TARGET_ARCH} |
+ mkdir -p ${library_output_dir} |
+ |
+ for f in ${ninja_output_dir}/${flavor}/*.a |
+ do |
+ ln -sf "${f}" "${library_output_dir}/$(basename ${f})" |
+ done |
} |
-# Build all the common architectures. |
-build_webrtc "out_ios_arm" "Release" "arm" |
-build_webrtc "out_ios_arm64" "Release" "arm64" |
-build_webrtc "out_ios_ia32" "Release" "ia32" |
-build_webrtc "out_ios_x86_64" "Release" "x64" |
+function clean_artifacts { |
+ local output_dir=$1 |
+ if [ -d ${output_dir} ]; then |
kjellander_webrtc
2016/04/15 04:59:41
Use double-brackets https://engdoc.corp.google.com
tkchin_webrtc
2016/04/16 00:34:18
Done.
|
+ rm -r ${output_dir} |
+ fi |
+} |
+ |
+function usage { |
+ echo "WebRTC iOS FAT libraries build script." |
+ echo "Each architecture is compiled separately before being merged together." |
+ echo "By default, the fat libraries will be created in out_ios_libs/fat_libs." |
+ echo "The headers will be copied to out_ios_libs/include." |
+ echo "Usage: $0 [-h] [-c] [-o]" |
+ echo " -h Print this help." |
+ echo " -c Removes generated build output." |
+ echo " -o Specifies a directory to output build artifacts to." |
+ echo " If specified together with -c, deletes the dir." |
+ exit 0 |
+} |
-popd |
+check_preconditions |
+ |
+# Set default arguments. |
+# Output directory for build artifacts. |
+OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs |
+# Flag to build the new or legacy version of the API. |
+USE_LEGACY_API=0 |
+PERFORM_CLEAN=0 |
+ |
+# Parse arguments. |
+while getopts "hco:" opt; do |
+ case "${opt}" in |
+ h) usage;; |
kjellander_webrtc
2016/04/15 04:59:41
-2 spaces indent https://engdoc.corp.google.com/en
tkchin_webrtc
2016/04/16 00:34:18
Done.
|
+ c) PERFORM_CLEAN=1;; |
+ o) OUTPUT_DIR="${OPTARG}";; |
+ esac |
+done |
+ |
+if [ ${PERFORM_CLEAN} -ne 0 ]; then |
kjellander_webrtc
2016/04/15 04:59:41
Use double-brackets https://engdoc.corp.google.com
tkchin_webrtc
2016/04/16 00:34:18
Done.
|
+ clean_artifacts ${OUTPUT_DIR} |
+ exit 0 |
+fi |
+ |
+# Build all the common architectures. |
+archs=( "arm" "arm64" "ia32" "x64" ) |
+for arch in "${archs[@]}" |
+do |
+ echo "Building WebRTC arch: ${arch}" |
+ build_webrtc ${OUTPUT_DIR} "Release" $arch |
+done |
# Export header files. |
-${EXPORT_HEADERS_SCRIPT} ${WEBRTC_BASE_DIR}/${LIBRARY_BASE_DIR} \ |
- ${USE_LEGACY_API} |
+${EXPORT_HEADERS_SCRIPT} ${OUTPUT_DIR} ${USE_LEGACY_API} |
# Merge the libraries together. |
-${MERGE_SCRIPT} ${WEBRTC_BASE_DIR}/${LIBRARY_BASE_DIR} |
+${MERGE_SCRIPT} ${OUTPUT_DIR} |