[
  {
    "path": ".gitignore",
    "content": "*.local\nout\ndepot_tools\n.DS_Store\n"
  },
  {
    "path": ".gitlab-ci.yml",
    "content": "before_script:\n- sed -i \"s#universe#universe multiverse#\" /etc/apt/sources.list\n- apt-get update\n- apt-get install -qq --no-install-recommends ca-certificates\n\nstages:\n- build\n- test\n\nbuild-webrtc:\n  stage: build\n  script:\n  - ./build.sh $REVISION\n  cache:\n    paths:\n    - out\n  artifacts:\n    expire_in: 6 months\n    paths:\n    - out/*.zip\n\ntest-webrtc:\n  stage: test\n  before_script:\n  - apt-get update\n  - apt-get install -qq --no-install-recommends unzip pkg-config g++ libssl-dev\n    libnss3-dev libx11-dev libexpat1-dev libasound2\n  script:\n  - cd out; unzip *.zip; cd -\n  - test/run_tests.sh $(ls -d -1 out/webrtc*/)\n  dependencies:\n  - build-webrtc\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: cpp\nsudo: required\nos:\n- linux\n- osx\nosx_image: xcode9.3\naddons:\n  apt:\n    sources:\n      - ubuntu-toolchain-r-test\n    packages:\n      # Update the default 'trusty' linker and gcc version for tests to link and pass.\n      - g++-5\n      - binutils-2.26\nenv:\n  global:\n  - LINUX_PICKLE_URL=https://www.dropbox.com/s/yclmzq1n63cminb/linux-pickle.tar.gz?dl=0\n  - OSX_PICKLE_URL=https://www.dropbox.com/s/m23s3l9g1s9yw87/osx-pickle.tar.gz?dl=0\nbefore_script:\n# Update the default 'trusty' linker and gcc version for tests to link and pass.\n- if [[ \"$TRAVIS_OS_NAME\" == \"linux\" ]]; then\n  sudo update-alternatives --install /usr/bin/ld ld /usr/lib/binutils-2.26/bin/ld 90;\n  fi\n# To help prevent timeouts, download a 'pickled' .tar.gz archive of the linux\n# webrtc checkout. LINUX_PICKLE_URL was created with:\n# `GZIP=-9 tar zcvf linux-pickle.tar.gz .`\n- mkdir -p out\n- if [[ \"$TRAVIS_OS_NAME\" == \"linux\" ]]; then travis_retry curl -L $LINUX_PICKLE_URL -o pickle.tar.gz; fi\n- if [[ \"$TRAVIS_OS_NAME\" == \"osx\" ]]; then travis_retry curl -L $OSX_PICKLE_URL -o pickle.tar.gz; fi\n- tar xzf pickle.tar.gz -C out && rm pickle.tar.gz\nscript:\n- ./build.sh -n Release -d\n# Run again since build.sh installation of dependencies sets back defaults\n- if [[ \"$TRAVIS_OS_NAME\" == \"linux\" ]]; then\n  sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 90 --slave /usr/bin/g++ g++ /usr/bin/g++-5;\n  fi\n- test/run_tests.sh $(ls -d -1 out/webrtc*/) Release\n"
  },
  {
    "path": "LICENSE",
    "content": "Copyright (c) 2015, Vicken Simonian\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\n3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
  },
  {
    "path": "README.md",
    "content": "# webrtcbuilds [![Build Status](https://travis-ci.org/vsimon/webrtcbuilds.svg?branch=master)](https://travis-ci.org/vsimon/webrtcbuilds)\n\nThe goal of webrtcbuilds is to provide a single standalone static library and\npackage for WebRTC.\n\n## Current Platforms and Prerequisites\n\n* OSX (requires [Homebrew](http://brew.sh/) is installed)\n* Windows (requires [Visual Studio Community 2013](http://www.chromium.org/developers/how-tos/build-instructions-windows) at least\nand a [Bash shell such as Git for Windows](https://msysgit.github.io) is\ninstalled)\n* Linux (tested on Ubuntu 16.04 64-bit)\n\n## How to run\n\n`./build.sh` to build the latest version of WebRTC.\n\nOr with options.\n\n```\nUsage:\n   ./build.sh [OPTIONS]\n\nOPTIONS:\n   -h             Show this message\n   -d             Debug mode. Print all executed commands.\n   -o OUTDIR      Output directory. Default is 'out'\n   -b BRANCH      Latest revision on git branch. Overrides -r. Common branch names are 'branch-heads/nn', where 'n' is the release number.\n   -r REVISION    Git SHA revision. Default is latest revision.\n   -t TARGET OS   The target os for cross-compilation. Default is the host OS such as 'linux', 'mac', 'win'. Other values can be 'android', 'ios'.\n   -c TARGET CPU  The target cpu for cross-compilation. Default is 'x64'. Other values can be 'x86', 'arm64', 'arm'.\n   -n CONFIGS     Build configurations, space-separated. Default is 'Debug Release'. Other values can be 'Debug', 'Release'.\n   -e             Compile WebRTC with RTTI enabled. Default is with RTTI not enabled.\n   -g             [Linux] Compile 'Debug' WebRTC with iterator debugging disabled. Default is enabled but it might add significant overhead.\n   -D             [Linux] Generate a debian package\n   -F PATTERN     Allow customize package filename through a pattern\n   -P PATTERN     Allow customize package name through a pattern\n   -V PATTERN     Allow customize package version through a pattern\n\nThe PATTERN is a string that can use the following tokens:\n   %p%            The system platform.\n   %to%           Target os.\n   %tc%           Target cpu.\n   %b%            The branch if it was specified.\n   %r%            Revision.\n   %sr%           Short revision.\n   %rn%           The associated revision number.\n   %da%           Debian architecture.\n```\n\n## Where is the package\n\n`out/webrtcbuilds-<rev>-<sha>-<target-os>-<target-cpu>.zip`\nwhere `<rev>` is the revision number of the commit, `<sha>` is the short git SHA\nof the commit, and `<target-os>-<target-cpu>` is the OS (linux, mac, win) and\nCPU (x64, x86) of the target environment.\n\n## Documentation\n\nWiki: https://github.com/vsimon/webrtcbuilds/wiki\n\nMailing List: http://groups.google.com/group/webrtcbuilds\n"
  },
  {
    "path": "build.sh",
    "content": "#!/bin/bash\n\nset -o errexit\nset -o nounset\nset -o pipefail\n\nDIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"\nsource $DIR/util.sh\n\nusage ()\n{\ncat << EOF\n\nUsage:\n   $0 [OPTIONS]\n\nWebRTC build script.\n\nOPTIONS:\n   -h             Show this message\n   -d             Debug mode. Print all executed commands.\n   -o OUTDIR      Output directory. Default is 'out'\n   -b BRANCH      Latest revision on git branch. Overrides -r. Common branch names are 'branch-heads/nn', where 'nn' is the release number.\n   -r REVISION    Git SHA revision. Default is latest revision.\n   -t TARGET OS   The target os for cross-compilation. Default is the host OS such as 'linux', 'mac', 'win'. Other values can be 'android', 'ios'.\n   -c TARGET CPU  The target cpu for cross-compilation. Default is 'x64'. Other values can be 'x86', 'arm64', 'arm'.\n   -n CONFIGS     Build configurations, space-separated. Default is 'Debug Release'. Other values can be 'Debug', 'Release'.\n   -e             Compile WebRTC with RTTI enabled. Default is with RTTI not enabled.\n   -g             [Linux] Compile 'Debug' WebRTC with iterator debugging disabled. Default is enabled but it might add significant overhead.\n   -D             [Linux] Generate a debian package\n   -F PATTERN     Allow customize package filename through a pattern\n   -P PATTERN     Allow customize package name through a pattern\n   -V PATTERN     Allow customize package version through a pattern\n\nThe PATTERN is a string that can use the following tokens:\n   %p%            The system platform.\n   %to%           Target os.\n   %tc%           Target cpu.\n   %b%            The branch if it was specified.\n   %r%            Revision.\n   %sr%           Short revision.\n   %rn%           The associated revision number.\n   %da%           Debian architecture.\nEOF\n}\n\nwhile getopts :b:o:r:t:c:n:degDF:P:V: OPTION; do\n  case $OPTION in\n  o) OUTDIR=$OPTARG ;;\n  b) BRANCH=$OPTARG ;;\n  r) REVISION=$OPTARG ;;\n  t) TARGET_OS=$OPTARG ;;\n  c) TARGET_CPU=$OPTARG ;;\n  n) CONFIGS=$OPTARG ;;\n  d) DEBUG=1 ;;\n  e) ENABLE_RTTI=1 ;;\n  g) DISABLE_ITERATOR_DEBUG=1 ;;\n  D) PACKAGE_AS_DEBIAN=1 ;;\n  F) PACKAGE_FILENAME_PATTERN=$OPTARG ;;\n  P) PACKAGE_NAME_PATTERN=$OPTARG ;;\n  V) PACKAGE_VERSION_PATTERN=$OPTARG ;;\n  ?) usage; exit 1 ;;\n  esac\ndone\n\nOUTDIR=${OUTDIR:-out}\nBRANCH=${BRANCH:-}\nDEBUG=${DEBUG:-0}\nENABLE_RTTI=${ENABLE_RTTI:-0}\nDISABLE_ITERATOR_DEBUG=${DISABLE_ITERATOR_DEBUG:-0}\nPACKAGE_AS_DEBIAN=${PACKAGE_AS_DEBIAN:-0}\nPACKAGE_FILENAME_PATTERN=${PACKAGE_FILENAME_PATTERN:-\"webrtcbuilds-%rn%-%sr%-%to%-%tc%\"}\nPACKAGE_NAME_PATTERN=${PACKAGE_NAME_PATTERN:-\"webrtcbuilds\"}\nPACKAGE_VERSION_PATTERN=${PACKAGE_VERSION_PATTERN:-\"%rn%\"}\nCONFIGS=${CONFIGS:-Debug Release}\nREPO_URL=\"https://webrtc.googlesource.com/src\"\nDEPOT_TOOLS_URL=\"https://chromium.googlesource.com/chromium/tools/depot_tools.git\"\nDEPOT_TOOLS_DIR=$DIR/depot_tools\nDEPOT_TOOLS_WIN_TOOLCHAIN=0\nPATH=$DEPOT_TOOLS_DIR:$DEPOT_TOOLS_DIR/python276_bin:$PATH\n\n[ \"$DEBUG\" = 1 ] && set -x\n\nmkdir -p $OUTDIR\nOUTDIR=$(cd $OUTDIR && pwd -P)\n\ndetect-platform\nTARGET_OS=${TARGET_OS:-$PLATFORM}\nTARGET_CPU=${TARGET_CPU:-x64}\necho \"Host OS: $PLATFORM\"\necho \"Target OS: $TARGET_OS\"\necho \"Target CPU: $TARGET_CPU\"\n\ncheck::platform $PLATFORM $TARGET_OS\n\necho Checking webrtcbuilds dependencies\ncheck::webrtcbuilds::deps $PLATFORM\n\necho Checking depot-tools\ncheck::depot-tools $PLATFORM $DEPOT_TOOLS_URL $DEPOT_TOOLS_DIR\n\nif [ ! -z $BRANCH ]; then\n  REVISION=$(git ls-remote $REPO_URL --heads $BRANCH | head -n1 | cut -f1) || \\\n    { echo \"Cound not get branch revision for $BRANCH\" && exit 1; }\n  [ -z $REVISION ] && echo \"Cound not get branch revision for $BRANCH\" && exit 1\n   echo \"Building branch: $BRANCH\"\nelse\n  REVISION=${REVISION:-$(latest-rev $REPO_URL)} || \\\n    { echo \"Could not get latest revision\" && exit 1; }\nfi\necho \"Building revision: $REVISION\"\nREVISION_NUMBER=$(revision-number $REPO_URL $REVISION) || \\\n  { echo \"Could not get revision number\" && exit 1; }\necho \"Associated revision number: $REVISION_NUMBER\"\n\necho \"Checking out WebRTC revision (this will take awhile): $REVISION\"\ncheckout \"$TARGET_OS\" $OUTDIR $REVISION\n\necho Checking WebRTC dependencies\ncheck::webrtc::deps $PLATFORM $OUTDIR \"$TARGET_OS\"\n\necho Patching WebRTC source\npatch $PLATFORM $OUTDIR $ENABLE_RTTI\n\necho Compiling WebRTC\ncompile $PLATFORM $OUTDIR \"$TARGET_OS\" \"$TARGET_CPU\" \"$CONFIGS\" \"$DISABLE_ITERATOR_DEBUG\"\n\necho Packaging WebRTC\nPACKAGE_FILENAME=$(interpret-pattern \"$PACKAGE_FILENAME_PATTERN\" \"$PLATFORM\" \"$OUTDIR\" \"$TARGET_OS\" \"$TARGET_CPU\" \"$BRANCH\" \"$REVISION\" \"$REVISION_NUMBER\")\nPACKAGE_NAME=$(interpret-pattern \"$PACKAGE_NAME_PATTERN\" \"$PLATFORM\" \"$OUTDIR\" \"$TARGET_OS\" \"$TARGET_CPU\" \"$BRANCH\" \"$REVISION\" \"$REVISION_NUMBER\")\nPACKAGE_VERSION=$(interpret-pattern \"$PACKAGE_VERSION_PATTERN\" \"$PLATFORM\" \"$OUTDIR\" \"$TARGET_OS\" \"$TARGET_CPU\" \"$BRANCH\" \"$REVISION\" \"$REVISION_NUMBER\")\npackage::prepare $PLATFORM $OUTDIR $PACKAGE_FILENAME $DIR/resource \"$CONFIGS\" $REVISION_NUMBER\nif [ \"$PACKAGE_AS_DEBIAN\" = 1 ]; then\n  package::debian $OUTDIR $PACKAGE_FILENAME $PACKAGE_NAME $PACKAGE_VERSION \"$(debian-arch $TARGET_CPU)\"\nelse\n  package::zip $PLATFORM $OUTDIR $PACKAGE_FILENAME\nfi\n\necho Build successful\n"
  },
  {
    "path": "resource/pkgconfig/libwebrtc_full.pc.in",
    "content": "prefix=${WEBRTC_LOCAL}\nlibdir=${prefix}/lib\nincludedir=${prefix}/include\n\nName: libwebrtc_full\nDescription: The WebRTC library\nVersion: 0.0.1\nRequires: libcrypto, nss\nCflags: -DWEBRTC_POSIX -I${includedir} -std=gnu++11\nLibs: ${libdir}/$CONFIG/libwebrtc_full.a -ldl -lX11 -lexpat\n"
  },
  {
    "path": "test/run_tests.sh",
    "content": "#!/bin/bash\n\nset -o errexit\nset -o nounset\nset -o pipefail\n\nDIR=$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\nWEBRTCBUILDS_FOLDER=\"$1\"\nWEBRTCBUILDS_FOLDER=$(cd $WEBRTCBUILDS_FOLDER && pwd -P)\nCONFIGS=${2:-Debug Release}\n\n# This is for handling breaking changes between WebRTC versions in our test\nWEBRTC_REVISION_NUMBER=$(echo $WEBRTCBUILDS_FOLDER | cut -d- -f2)\n\ntmpdir=$(mktemp -d)\ntrap 'rm -rf \"$tmpdir\"' EXIT INT TERM HUP\npushd $tmpdir >/dev/null\n  for CONFIG in $CONFIGS; do\n    if [[ $(uname) = Linux ]]; then\n      export PKG_CONFIG_PATH=$WEBRTCBUILDS_FOLDER/lib/$CONFIG/pkgconfig\n      c++ -o simple_app $DIR/simple_app.cc \\\n      -DWEBRTC_REVISION_NUMBER=$WEBRTC_REVISION_NUMBER \\\n      $(pkg-config --cflags --libs --define-variable=WEBRTC_LOCAL=$WEBRTCBUILDS_FOLDER libwebrtc_full) \\\n      -lpthread\n    elif [[ $(uname) = Darwin ]]; then\n      clang++ -o simple_app $DIR/simple_app.cc -DWEBRTC_POSIX -DWEBRTC_MAC \\\n        -DWEBRTC_REVISION_NUMBER=$WEBRTC_REVISION_NUMBER \\\n        -I$WEBRTCBUILDS_FOLDER/include -std=c++11 -stdlib=libc++ \\\n        $WEBRTCBUILDS_FOLDER/lib/$CONFIG/libwebrtc_full.a \\\n        -framework Cocoa -framework Foundation -framework IOKit \\\n        -framework Security -framework SystemConfiguration \\\n        -framework ApplicationServices -framework CoreServices \\\n        -framework CoreVideo -framework CoreAudio -framework AudioToolbox \\\n        -framework QTKit -framework AVFoundation -framework CoreMedia\n    else\n      echo No test currently exists for this platform\n      exit 1\n    fi\n    ./simple_app\n  done\npopd >/dev/null\n"
  },
  {
    "path": "test/simple_app.cc",
    "content": "// Revision 19846 is the following, where upstream moved src/webrtc to src/\n// https://webrtc.googlesource.com/src/+/92ea95e34af5966555903026f45164afbd7e2088\n#if WEBRTC_REVISION_NUMBER >= 19846\n  #include \"rtc_base/thread.h\"\n  #include \"p2p/base/basicpacketsocketfactory.h\"\n  #include \"api/peerconnectioninterface.h\"\n  #include \"api/test/fakeconstraints.h\"\n  #include \"media/engine/webrtcvideocapturerfactory.h\"\n  #include \"api/audio_codecs/builtin_audio_decoder_factory.h\"\n  #include \"api/audio_codecs/builtin_audio_encoder_factory.h\"\n  #include \"modules/audio_device/include/audio_device.h\"\n#else\n  #include \"webrtc/rtc_base/thread.h\"\n  #include \"webrtc/p2p/base/basicpacketsocketfactory.h\"\n  #include \"webrtc/api/peerconnectioninterface.h\"\n  #include \"webrtc/api/test/fakeconstraints.h\"\n  #include \"webrtc/media/engine/webrtcvideocapturerfactory.h\"\n#endif\n\nint main(int argc, char* argv[]) {\n  // something from base\n  rtc::Thread* thread = rtc::Thread::Current();\n\n  // something from p2p\n  std::unique_ptr<rtc::BasicPacketSocketFactory> socket_factory(\n    new rtc::BasicPacketSocketFactory());\n\n  // something from api\n  rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_connection_factory =\n    webrtc::CreatePeerConnectionFactory(\n      NULL,\n      rtc::Thread::Current(),\n      NULL,\n      webrtc::AudioDeviceModule::Create(0, webrtc::AudioDeviceModule::kDummyAudio),\n      webrtc::CreateBuiltinAudioEncoderFactory(),\n      webrtc::CreateBuiltinAudioDecoderFactory(),\n      NULL,\n      NULL);\n\n  // something from api/test\n  webrtc::FakeConstraints constraints;\n\n  // something from media/engine\n  cricket::WebRtcVideoDeviceCapturerFactory factory;\n  std::unique_ptr<cricket::VideoCapturer> capturer = factory.Create(cricket::Device(\"\", 0));\n\n  return 0;\n}\n"
  },
  {
    "path": "util.sh",
    "content": "# Detect host platform.\n# Set PLATFORM environment variable to override default behavior.\n# Supported platform types - 'linux', 'win', 'mac'\n# 'msys' is the git bash shell, built using mingw-w64, running under Microsoft\n# Windows.\nfunction detect-platform() {\n  # set PLATFORM to android on linux host to build android\n  case \"$OSTYPE\" in\n  darwin*)      PLATFORM=${PLATFORM:-mac} ;;\n  linux*)       PLATFORM=${PLATFORM:-linux} ;;\n  win32*|msys*) PLATFORM=${PLATFORM:-win} ;;\n  *)            echo \"Building on unsupported OS: $OSTYPE\"; exit 1; ;;\n  esac\n}\n\n# Sanity check for the host os/platform supporting cross-compilation with the\n# target os.\n# $1: The platform type.\n# $2: The target os.\nfunction check::platform() {\n  local platform=\"$1\"\n  local target_os=\"$2\"\n    if [[ $target_os = 'android' && $platform != 'linux' ]]; then\n      # Codifying the webrtc documentation for android compilation support for non-linux platforms\n      echo \"Android compilation is only supported on Linux (https://webrtc.org/native-code/android/#getting-the-code)\"\n      exit 1\n    fi\n}\n\n# This cleans the output directory.\n# $1: The output directory.\nfunction clean() {\n  local outdir=\"$1\"\n  rm -rf $outdir/* $outdir/.gclient*\n}\n\n# Makes sure depot tools are present.\n# $1: The platform type.\n# $2: The depot tools url.\n# $3: The depot tools directory.\nfunction check::depot-tools() {\n  local platform=\"$1\"\n  local depot_tools_url=\"$2\"\n  local depot_tools_dir=\"$3\"\n\n  if [ ! -d $depot_tools_dir ]; then\n    git clone -q $depot_tools_url $depot_tools_dir\n    if [ $platform = 'win' ]; then\n      # run gclient.bat to get python\n      pushd $depot_tools_dir >/dev/null\n      ./gclient.bat\n      popd >/dev/null\n    fi\n  else\n    pushd $depot_tools_dir >/dev/null\n      git reset --hard -q\n    popd >/dev/null\n  fi\n}\n\n# Makes sure package is installed. Depends on sudo to be installed first.\n# $1: The name of the package\n# $2: Existence check binary. Defaults to name of the package.\nfunction ensure-package() {\n  local name=\"$1\"\n  local binary=\"${2:-$1}\"\n  if ! which $binary > /dev/null ; then\n    sudo apt-get update -qq\n    sudo apt-get install -y $name\n  fi\n}\n\n# Makes sure all webrtcbuilds dependencies are present.\n# $1: The platform type.\nfunction check::webrtcbuilds::deps() {\n  local platform=\"$1\"\n\n  case $platform in\n  mac)\n    which brew > /dev/null || (echo \"Building with 'mac' requires Homebrew. Visit https://brew.sh\"; exit 1)\n    # for GNU version of cp: gcp\n    which gcp > /dev/null || brew install coreutils\n    ;;\n  linux)\n    if ! grep -v \\# /etc/apt/sources.list | grep -q multiverse ; then\n      echo \"*** Warning: The Multiverse repository is probably not enabled ***\"\n      echo \"*** which is required for things like msttcorefonts.           ***\"\n    fi\n    if ! which sudo > /dev/null ; then\n      apt-get update -qq\n      apt-get install -y sudo\n    fi\n    ensure-package curl\n    ensure-package git\n    ensure-package python\n    ensure-package lbzip2\n    ensure-package lsb-release lsb_release\n    ;;\n  win)\n    VISUAL_STUDIO_TOOLS=${VS140COMNTOOLS:-}\n    if [ -z VISUAL_STUDIO_TOOLS ]; then\n      echo \"Building with 'win' requires Microsoft Visual Studio 2015\"\n      exit 1\n    fi\n;;\n  esac\n}\n\n# Makes sure all WebRTC build dependencies are present.\n# $1: The platform type.\nfunction check::webrtc::deps() {\n  local platform=\"$1\"\n  local outdir=\"$2\"\n  local target_os=\"$3\"\n\n  case $platform in\n  linux)\n    # Automatically accepts ttf-mscorefonts EULA\n    echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections\n    sudo $outdir/src/build/install-build-deps.sh --no-syms --no-arm --no-chromeos-fonts --no-nacl --no-prompt\n    ;;\n  esac\n\n  if [ $target_os = 'android' ]; then\n    sudo $outdir/src/build/install-build-deps-android.sh\n  fi\n}\n\n# Checks out a specific revision\n# $1: The target OS type.\n# $2: The output directory.\n# $3: Revision represented as a git SHA.\nfunction checkout() {\n  local target_os=\"$1\"\n  local outdir=\"$2\"\n  local revision=\"$3\"\n\n  pushd $outdir >/dev/null\n  local prev_target_os=$(cat $outdir/.webrtcbuilds_target_os 2>/dev/null)\n  if [[ -n \"$prev_target_os\" && \"$target_os\" != \"$prev_target_os\" ]]; then\n    echo The target OS has changed. Refetching sources for the new target OS\n    rm -rf src .gclient*\n  fi\n  # Fetch only the first-time, otherwise sync.\n  if [ ! -d src ]; then\n    case $target_os in\n    android)\n      yes | fetch --nohooks webrtc_android\n      ;;\n    ios)\n      fetch --nohooks webrtc_ios\n      ;;\n    *)\n      fetch --nohooks webrtc\n      ;;\n    esac\n  fi\n  # Checkout the specific revision after fetch or for older branches, run\n  # setup_links.py to replace all directories which now must be symlinks then\n  # try again.\n  gclient sync --force --revision $revision ||\n    (test -f src/setup_links.py && src/setup_links.py --force --no-prompt && gclient sync --force --revision $revision)\n  # Cache the target OS\n  echo $target_os > $outdir/.webrtcbuilds_target_os\n  popd >/dev/null\n}\n\n# Patches a checkout for building static standalone libs\n# $1: The platform type.\n# $2: The output directory.\n# $3: Enable RTTI or not. '0' or '1'.\nfunction patch() {\n  local platform=\"$1\"\n  local outdir=\"$2\"\n  local rtti_enabled=\"$3\"\n\n  pushd $outdir/src >/dev/null\n  # This removes the examples from being built.\n  sed -i.bak 's|\"//webrtc/examples\",|#\"//webrtc/examples\",|' BUILD.gn\n  # This configures whether to build with RTTI enabled or not.\n  [ \"$rtti_enabled\" = 1 ] && sed -i.bak \\\n    's|\"//build/config/compiler:no_rtti\",|\"//build/config/compiler:rtti\",|' \\\n    build/config/BUILDCONFIG.gn\n  popd >/dev/null\n}\n\n# This function compiles a single library using Microsoft Visual C++ for a\n# Microsoft Windows (32/64-bit) target. This function is separate from the\n# other compile functions because of differences using the Microsoft tools:\n#\n# The Microsoft Windows tools use different file extensions than the other tools:\n#  '.obj' as the object file extension, instead of '.o'\n# '.lib' as the static library file extension, instead of '.a'\n# '.dll' as the shared library file extension, instead of '.so'\n#\n# The Microsoft Windows tools have different names than the other tools:\n# 'lib' as the librarian, instead of 'ar'. 'lib' must be found through the path\n# variable $VS140COMNTOOLS.\n#\n# The Microsoft tools that target Microsoft Windows run only under\n# Microsoft Windows, so the build and target systems are the same.\n#\n# $1 the output directory, 'Debug', 'Debug_x64', 'Release', or 'Release_x64'\n# $2 additional gn arguments\nfunction compile-win() {\n  local outputdir=\"$1\"\n  local gn_args=\"$2\"\n\n  gn gen $outputdir --args=\"$gn_args\"\n  pushd $outputdir >/dev/null\n  ninja -C .\n\n  rm -f libwebrtc_full.lib\n  local objlist=$(strings .ninja_deps | grep -o '.*\\.obj')\n  local blacklist=\"unittest_main.obj|video_capture_external.obj|\\\ndevice_info_external.obj\"\n  echo \"$objlist\" | tr ' ' '\\n' | grep -v -E $blacklist >libwebrtc_full.list\n  # On Windows, asm files are compiled to object files that have .obj and .o\n  # extensions.\n  local extras=$(find \\\n    ./obj/third_party/libvpx/libvpx_* \\\n    ./obj/third_party/libjpeg_turbo/simd_asm \\\n    ./obj/third_party/boringssl/boringssl_asm -name '*.o' -o -name '*.obj')\n  echo \"$extras\" | tr ' ' '\\n' >>libwebrtc_full.list\n  \"$VS140COMNTOOLS../../VC/bin/lib\" /OUT:webrtc_full.lib @libwebrtc_full.list\n  popd >/dev/null\n}\n\n# This function compile and combine build artifact objects into one library.\n# $1 the output directory, 'Debug', 'Release'\n# $2 additional gn arguments\nfunction compile-unix() {\n  local outputdir=\"$1\"\n  local gn_args=\"$2\"\n  local blacklist=\"unittest|examples|/yasm|protobuf_lite|main.o|\\\nvideo_capture_external.o|device_info_external.o\"\n\n  gn gen $outputdir --args=\"$gn_args\"\n  pushd $outputdir >/dev/null\n  ninja -C .\n\n  rm -f libwebrtc_full.a\n  # Produce an ordered objects list by parsing .ninja_deps for strings\n  # matching .o files.\n  local objlist=$(strings .ninja_deps | grep -o '.*\\.o')\n  echo \"$objlist\" | tr ' ' '\\n' | grep -v -E $blacklist >libwebrtc_full.list\n  # various intrinsics aren't included by default in .ninja_deps\n  local extras=$(find \\\n    ./obj/third_party/libvpx/libvpx_* \\\n    ./obj/third_party/libjpeg_turbo/simd_asm \\\n    ./obj/third_party/boringssl/boringssl_asm -name '*.o')\n  echo \"$extras\" | tr ' ' '\\n' >>libwebrtc_full.list\n  # generate the archive\n  cat libwebrtc_full.list | xargs ar -crs libwebrtc_full.a\n  # generate an index list\n  ranlib libwebrtc_full.a\n  popd >/dev/null\n}\n\n# This compiles the library.\n# $1: The platform type.\n# $2: The output directory.\n# $3: The target os for cross-compilation.\n# $4: The target cpu for cross-compilation.\n# $5: The build configurations.\n# $6: Enable iterator debug or not. '0' or '1'.\nfunction compile() {\n  local platform=\"$1\"\n  local outdir=\"$2\"\n  local target_os=\"$3\"\n  local target_cpu=\"$4\"\n  local configs=\"$5\"\n  local disable_iterator_debug=\"$6\"\n  local common_args=\"is_component_build=false rtc_include_tests=false treat_warnings_as_errors=false\"\n  local target_args=\"target_os=\\\"$target_os\\\" target_cpu=\\\"$target_cpu\\\"\"\n\n  [ \"$disable_iterator_debug\" = 1 ] && common_args+=' enable_iterator_debugging=false'\n  pushd $outdir/src >/dev/null\n  for cfg in $configs; do\n    [ \"$cfg\" = 'Release' ] && common_args+=' is_debug=false'\n    case $platform in\n    win)\n      # 32-bit build\n      compile-win \"out/$cfg\" \"$common_args $target_args\"\n\n      # 64-bit build\n      GYP_DEFINES=\"target_arch=x64 $GYP_DEFINES\"\n      compile-win \"out/${cfg}_x64\" \"$common_args $target_args\"\n      ;;\n    *)\n      # On Linux when not cross-compiling, use clang = false and sysroot = false\n      # to build using gcc. Comment this out to use clang.\n      if [[ $platform = 'linux' && $target_os != 'android' && $target_cpu != amd* ]]; then\n        target_args+=\" is_clang=false use_sysroot=false\"\n      fi\n\n      # Debug builds are component builds (shared libraries) by default unless\n      # is_component_build=false is passed to gn gen --args. Release builds are\n      # static by default.\n      compile-unix \"out/$cfg\" \"$common_args $target_args\"\n      ;;\n    esac\n  done\n  popd >/dev/null\n}\n\n# This prepares artifacts to be packaged.\n# $1: The platform type.\n# $2: The output directory.\n# $3: The package filename.\n# $4: The project's resource dirctory.\n# $5: The build configurations.\n# $6: : The revision number.\nfunction package::prepare() {\n  local platform=\"$1\"\n  local outdir=\"$2\"\n  local package_filename=\"$3\"\n  local resourcedir=\"$4\"\n  local configs=\"$5\"\n  local revision_number=\"$6\"\n\n  if [ $platform = 'mac' ]; then\n    CP='gcp'\n  else\n    CP='cp'\n  fi\n  pushd $outdir >/dev/null\n  # create directory structure\n  mkdir -p $package_filename/include $package_filename/lib\n  for cfg in $configs; do\n    mkdir -p $package_filename/lib/$cfg\n  done\n\n  # find and copy header files\n  # copy all non third-party header files first then copy only the third-party\n  # header files that are required such as abseil-cpp for optional.h\n  pushd src >/dev/null\n  local headersSourceDir=webrtc\n  local headersDestDir=$outdir/$package_filename/include\n  # Revision 19846 is the following, where upstream moved src/webrtc to src/\n  # https://webrtc.googlesource.com/src/+/92ea95e34af5966555903026f45164afbd7e2088\n  if [[ $revision_number -ge 19846 ]]; then\n    headersSourceDir=.\n  fi\n  find $headersSourceDir -path './third_party*' -prune -o -name '*.h' -exec $CP --parents '{}' $headersDestDir ';'\n  # Revision 23941 introduced absl::optional from abseil-cpp\n  if [[ $revision_number -ge 23941 ]]; then\n    pushd $headersSourceDir/third_party/abseil-cpp >/dev/null\n    find . -name '*.h' -exec $CP --parents '{}' $headersDestDir ';'\n    popd >/dev/null\n  fi\n  popd >/dev/null\n  # find and copy libraries\n  pushd src/out >/dev/null\n  find . -maxdepth 3 \\( -name '*.so' -o -name '*.dll' -o -name '*webrtc_full*' -o -name *.jar \\) \\\n    -exec $CP --parents '{}' $outdir/$package_filename/lib ';'\n  popd >/dev/null\n\n  # for linux, add pkgconfig files\n  if [ $platform = 'linux' ]; then\n    for cfg in $configs; do\n      mkdir -p $package_filename/lib/$cfg/pkgconfig\n      CONFIG=$cfg envsubst '$CONFIG' < $resourcedir/pkgconfig/libwebrtc_full.pc.in > \\\n        $package_filename/lib/$cfg/pkgconfig/libwebrtc_full.pc\n    done\n  fi\n  popd >/dev/null\n}\n\n# This packages a compiled build into a zip file in the output directory.\n# $1: The platform type.\n# $2: The output directory.\n# $3: The package filename.\nfunction package::zip() {\n  local platform=\"$1\"\n  local outdir=\"$2\"\n  local package_filename=\"$3\"\n\n  pushd $outdir >/dev/null\n  # remove first for cleaner builds\n  rm -f $package_filename.zip\n\n  # zip up the package\n  if [ $platform = 'win' ]; then\n    $DEPOT_TOOLS/win_toolchain/7z/7z.exe a -tzip $package_filename.zip $package_filename\n  else\n    zip -r $package_filename.zip $package_filename >/dev/null\n  fi\n  popd >/dev/null\n}\n\n# This packages into a debian package in the output directory.\n# $1: The output directory.\n# $2: The package filename.\n# $3: The package name.\n# $4: The package version.\n# $5: The architecture.\nfunction package::debian() {\n  local outdir=\"$1\"\n  local package_filename=\"$2\"\n  local package_name=\"$3\"\n  local package_version=\"$4\"\n  local arch=\"$5\"\n  local debianize=\"debianize/$package_filename\"\n\n  echo \"Debianize WebRTC\"\n  pushd $outdir >/dev/null\n  mkdir -p $debianize/DEBIAN\n  mkdir -p $debianize/opt\n  mv $package_filename $debianize/opt/webrtc\n  cat << EOF > $debianize/DEBIAN/control\nPackage: $package_name\nArchitecture: $arch\nMaintainer: webrtcbuilds manintainers\nDepends: debconf (>= 0.5.00)\nPriority: optional\nVersion: $package_version\nDescription: webrtc static library\n This package provides webrtc library generated with webrtcbuilds\nEOF\n  fakeroot dpkg-deb --build $debianize\n  mv debianize/*.deb .\n  rm -rf debianize\n  popd >/dev/null\n}\n\n# This returns the latest revision from the git repo.\n# $1: The git repo URL\nfunction latest-rev() {\n  local repo_url=\"$1\"\n  git ls-remote $repo_url HEAD | cut -f1\n}\n\n# This returns the associated revision number for a given git sha revision\n# $1: The git repo URL\n# $2: The revision git sha string\nfunction revision-number() {\n  local repo_url=\"$1\"\n  local revision=\"$2\"\n  # This says curl the revision log with text format, base64 decode it using\n  # openssl since its more portable than just 'base64', take the last line which\n  # contains the commit revision number and output only the matching {#nnn} part\n  openssl base64 -d -A <<< $(curl --silent $repo_url/+/$revision?format=TEXT) \\\n    | tail -1 | egrep -o '{#([0-9]+)}' | tr -d '{}#'\n}\n\n# This returns a short revision sha.\n# $1: The revision string\nfunction short-rev() {\n  local revision=\"$1\"\n  echo $revision | cut -c -7\n}\n\n# This returns a short revision sha.\n# $1: The target cpu for cross-compilation.\nfunction debian-arch() {\n  local target_cpu=\"$1\"\n  # set PLATFORM to android on linux host to build android\n  case \"$target_cpu\" in\n  x86*)         echo \"i386\" ;;\n  x64*)         echo \"amd64\" ;;\n  *)            echo \"$target_cpu\" ;;\n  esac\n}\n\n# This interprets a pattern and returns the interpreted one.\n# $1: The pattern.\n# $2: The output directory.\n# $3: The platform type.\n# $4: The target os for cross-compilation.\n# $5: The target cpu for cross-compilation.\n# $6: The branch.\n# $7: The revision.\n# $8: The revision number.\nfunction interpret-pattern() {\n  local pattern=\"$1\"\n  local platform=\"$2\"\n  local outdir=\"$3\"\n  local target_os=\"$4\"\n  local target_cpu=\"$5\"\n  local branch=\"$6\"\n  local revision=\"$7\"\n  local revision_number=\"$8\"\n  local debian_arch=\"$(debian-arch $target_cpu)\"\n  local short_revision=\"$(short-rev $revision)\"\n\n  pattern=${pattern//%p%/$platform}\n  pattern=${pattern//%to%/$target_os}\n  pattern=${pattern//%tc%/$target_cpu}\n  pattern=${pattern//%b%/$branch}\n  pattern=${pattern//%r%/$revision}\n  pattern=${pattern//%rn%/$revision_number}\n  pattern=${pattern//%da%/$debian_arch}\n  pattern=${pattern//%sr%/$short_revision}\n\n  echo \"$pattern\"\n}\n"
  }
]