#!/bin/bash -ex
# Builder M13, 2026-10-05: LGPL FFmpeg n7.1 for the FACE CHECK's cv2 (opencv-python 4.14.0.94 links avcodec, avformat,
# avutil, swscale AND avdevice; Homebrew's GPL 7.1.1 avfilter also comes along). Same source and line as Builder PB's
# mac-build/pb_build_mac.sh (PB's local n7.1 tarball b08d7969, sha256 1ae1e22a...; nothing downloaded), with ONE change:
# avdevice and avfilter are built (cv2.abi3.so links avdevice, which links avfilter). Still no --enable-gpl, no
# --enable-version3, no external libraries, no postproc (GPL only). macOS 13.0 deployment target, clean PATH.
# usage: m13_build_ffmpeg.sh <ffmpeg-n7.1 tarball> <build dir> <install dir, NO spaces> [jobs]
SRC_TAR="$1"; BLD="$2"; INST="$3"; JOBS="${4:-6}"
case "$INST$BLD" in *" "*) echo "build and install paths must not contain spaces"; exit 2;; esac
test "$(shasum -a 256 "$SRC_TAR" | awk '{print $1}')" = 1ae1e22a5b7ef961570e187bdd1875a6b0fa42289a9c54c301a4a99cc2c3863d
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
export MACOSX_DEPLOYMENT_TARGET=13.0
rm -rf "$BLD" "$INST"; mkdir -p "$BLD/src" "$INST"
tar -xJf "$SRC_TAR" -C "$BLD/src" --strip-components=1
cd "$BLD/src"
./configure --prefix="$INST" --enable-shared --disable-static --enable-pthreads --cc=clang \
  --enable-videotoolbox --enable-audiotoolbox --enable-neon \
  --disable-programs --disable-doc --disable-postproc \
  --disable-sdl2 --disable-xlib --disable-libxcb --disable-lzma \
  --extra-cflags="-mmacosx-version-min=13.0" --extra-ldflags="-mmacosx-version-min=13.0"
grep -E "#define (CONFIG_GPL|CONFIG_VERSION3|CONFIG_NONFREE|HAVE_NEON|CONFIG_VIDEOTOOLBOX|CONFIG_AVDEVICE|CONFIG_AVFILTER|CONFIG_POSTPROC) " config.h
make -j"$JOBS"
make install
ls -la "$INST/lib"
