#!/bin/sh
set -e

BUILD="$(pwd)"
newline="
"

if test -f "$BUILD"/mpv_options ; then
    IFS=$newline
    set -- $(cat "$BUILD"/mpv_options) "$@"
    unset -v IFS
fi

case "$PKG_CONFIG_PATH" in
  '')
    export PKG_CONFIG_PATH="$BUILD/build_libs/lib/pkgconfig"
    ;;
  *)
    export PKG_CONFIG_PATH="$BUILD/build_libs/lib/pkgconfig:$PKG_CONFIG_PATH"
    ;;
esac

echo Using mpv options: "$@"

cd "$BUILD"/mpv

if [ "$BUILDSYSTEM" = "meson" ]; then
    meson setup build -Dprefer_static=true -Dbuildtype=release "$@"
else
    # add missing private dependencies from libass.pc
    # this is necessary due to the hybrid static / dynamic nature of the build
    # need to link against stdc++ in case libplacebo was built with glslang,
    # which requires that
    export LDFLAGS="$LDFLAGS $(pkg-config --libs fontconfig harfbuzz fribidi) -lstdc++"
    python3 ./waf configure "$@"
fi
