#!/usr/bin/env sh # macOS: copies Homebrew's libmpv and every library it links (ffmpeg, libplacebo, ...) # into vendor/mpv/macos, pointing them at each other with @loader_path so the folder is # self-contained; the bundle ships it as Contents/Frameworks. # Linux: libmpv comes from the system package (libmpv2); nothing to copy. set -eu root=$(cd "$(dirname "$0")/.." && pwd) case "$(uname -s)" in Darwin) out="$root/vendor/mpv/macos" if [ -f "$out/libmpv.2.dylib" ] && [ "${1:-}" != "--force" ]; then echo "libmpv already in vendor/mpv/macos (pass --force to refresh)" exit 0 fi brew list mpv >/dev/null 2>&1 || brew install mpv command -v dylibbundler >/dev/null 2>&1 || brew install dylibbundler rm -rf "$out" && mkdir -p "$out" cp "$(brew --prefix mpv)/lib/libmpv.2.dylib" "$out/" chmod u+w "$out/libmpv.2.dylib" install_name_tool -id @loader_path/libmpv.2.dylib "$out/libmpv.2.dylib" # -of: overwrite, -b: bundle dependencies, -x: fix this file, -d: where they go, # -p: how they're referenced, -s: also search Homebrew's lib folder for @rpath names. dylibbundler -of -b -x "$out/libmpv.2.dylib" -d "$out" -p @loader_path/ -s "$(brew --prefix)/lib" >/dev/null for f in "$out"/*.dylib; do # dylibbundler can repeat an rpath, which dyld refuses to load; keep one of each. for rpath in $(otool -l "$f" | awk '/cmd LC_RPATH/{getline; getline; print $2}' | sort | uniq -d); do while [ "$(otool -l "$f" | awk '/cmd LC_RPATH/{getline; getline; print $2}' | grep -cx "$rpath")" -gt 1 ]; do install_name_tool -delete_rpath "$rpath" "$f" 2>/dev/null done done # Rewriting load commands invalidates signatures; Apple silicon refuses unsigned code. codesign --force --sign - "$f" 2>/dev/null done # Homebrew builds for the macOS it runs on: the oldest macOS these libraries load on. minos=$(for f in "$out"/*.dylib; do otool -l "$f" | awk '/LC_BUILD_VERSION/{b=1} b&&/minos/{print $2; b=0}'; done | sort -V | tail -1) echo "libmpv and $(($(ls "$out" | wc -l) - 1)) libraries copied to vendor/mpv/macos (need macOS $minos or later)" ;; Linux) echo "Install libmpv from your distribution (e.g. apt install libmpv2 libmpv-dev)." ;; *) echo "Use scripts/fetch-libmpv.ps1 on Windows." ;; esac