|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright (c) Microsoft Corporation. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the 'License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -e |
| 18 | + |
| 19 | +function die() { echo "$@"; exit 1; } |
| 20 | + |
| 21 | +if [[ "$(uname)" != "Darwin" ]]; then |
| 22 | + die "ERROR: this script is designed to be run on OSX. Can't run on $(uname)" |
| 23 | +fi |
| 24 | + |
| 25 | +trap "cd $(pwd -P)" EXIT |
| 26 | +cd "$(dirname $0)" |
| 27 | + |
| 28 | +source ./CONFIG.sh |
| 29 | + |
| 30 | +BUILDDIR="${PWD}/build" |
| 31 | +PREFIX="${BUILDDIR}/osx_prefix" |
| 32 | +OUTPUT_PATH="${PWD}/output/ffmpeg-mac" |
| 33 | + |
| 34 | +function build_libvpx { |
| 35 | + cd "${BUILDDIR}" |
| 36 | + git clone https://chromium.googlesource.com/webm/libvpx |
| 37 | + cd libvpx |
| 38 | + git checkout "${LIBVPX_VERSION}" |
| 39 | + # Compile libvpx according to the docs: |
| 40 | + # - https://chromium.googlesource.com/webm/libvpx/+/master/README |
| 41 | + ./configure --prefix="${PREFIX}" ${LIBVPX_CONFIG} |
| 42 | + make && make install |
| 43 | +} |
| 44 | + |
| 45 | +function build_ffmpeg { |
| 46 | + cd "${BUILDDIR}" |
| 47 | + git clone git://source.ffmpeg.org/ffmpeg.git |
| 48 | + cd ffmpeg |
| 49 | + git checkout "${FFMPEG_VERSION}" |
| 50 | + export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig" |
| 51 | + # Prohibit pkg-config from using system installed libs. |
| 52 | + export PKG_CONFIG_LIBDIR= |
| 53 | + |
| 54 | + ./configure --pkg-config=pkg-config \ |
| 55 | + --pkg-config-flags="--static" \ |
| 56 | + --extra-cflags="-I/${PREFIX}/include" \ |
| 57 | + --extra-ldflags="-L/${PREFIX}/lib" \ |
| 58 | + --prefix="${PREFIX}" \ |
| 59 | + --bindir="${PWD}/bin" \ |
| 60 | + ${FFMPEG_CONFIG} |
| 61 | + make && make install |
| 62 | +} |
| 63 | + |
| 64 | +REQUIERED_BUILD_TOOLS=("git" "make" "yasm" "pkg-config") |
| 65 | +missing_build_tools=() |
| 66 | + |
| 67 | +for dependency in ${REQUIERED_BUILD_TOOLS[@]}; do |
| 68 | + if ! command -v "${dependency}" >/dev/null; then |
| 69 | + missing_build_tools+=("${dependency}") |
| 70 | + fi |
| 71 | +done |
| 72 | + |
| 73 | +if [[ ${#missing_build_tools[@]} != 0 ]]; then |
| 74 | + die "ERROR: missing dependencies! Please run: brew install ${missing_build_tools[@]}" |
| 75 | +fi |
| 76 | + |
| 77 | +# Cleanup |
| 78 | +set -x |
| 79 | +rm -rf "${BUILDDIR}" |
| 80 | +mkdir -p "${BUILDDIR}" |
| 81 | + |
| 82 | +build_libvpx |
| 83 | +build_ffmpeg |
| 84 | + |
| 85 | +# put resulting executable where we were asked to |
| 86 | +mkdir -p $(dirname "${OUTPUT_PATH}") |
| 87 | +cp "${BUILDDIR}/ffmpeg/bin/ffmpeg" "${OUTPUT_PATH}" |
| 88 | +strip "${OUTPUT_PATH}" |
0 commit comments