Nacre/tools/gst-mse.sh

58 lines
2.7 KiB
Shell
Executable file

#!/usr/bin/env bash
# Builds Nacre's patched copy of GStreamer's MSE library and plugin (vendor/gst-mse, gst-plugins-bad 1.28.9, LGPL)
# into target/gst-mse/:
# lib/libgstmse-1.0.so.0 the library (same soname as the system one; Nacre's RUNPATH finds this first)
# gstreamer-1.0/libgstmse.so the `mse` plugin (msesrc), found through GST_PLUGIN_PATH (src/main.rs)
# and, with `test`, builds and runs the C tests in tests/gst-mse/ against that library.
#
# Usage: tools/gst-mse.sh [test]
# Needs: cc, pkg-config, gstreamer-1.0, gstreamer-base-1.0, gstreamer-app-1.0.
set -eu
root=$(cd "$(dirname "$0")/.." && pwd)
src=$root/vendor/gst-mse
out=$root/target/gst-mse
mkdir -p "$out/obj" "$out/lib" "$out/gstreamer-1.0"
cflags="-O2 -g -fPIC -fvisibility=hidden -std=gnu11 -Wall -Wno-unused-function
-DGST_USE_UNSTABLE_API -DHAVE_CONFIG_H
-I$src/gen -I$src/gen/gst/mse -I$src/gst-libs -I$src/gst-libs/gst/mse
$(pkg-config --cflags gstreamer-1.0 gstreamer-base-1.0 gstreamer-app-1.0)"
libs=$(pkg-config --libs gstreamer-1.0 gstreamer-base-1.0 gstreamer-app-1.0)
objs=()
for c in "$src"/gst-libs/gst/mse/*.c "$src"/gen/gst/mse/mse-enumtypes.c; do
o=$out/obj/$(basename "$c" .c).o
if [ ! -f "$o" ] || [ "$c" -nt "$o" ] || [ -n "$(find "$src/gst-libs" "$src/gen" -name '*.h' -newer "$o")" ]; then
# shellcheck disable=SC2086
cc $cflags -DBUILDING_GST_MSE -DG_LOG_DOMAIN='"GStreamer-MSE"' -c "$c" -o "$o"
fi
objs+=("$o")
done
# shellcheck disable=SC2086
cc -shared -Wl,-soname,libgstmse-1.0.so.0 -Wl,--no-undefined -o "$out/lib/libgstmse-1.0.so.0" "${objs[@]}" $libs
ln -sf libgstmse-1.0.so.0 "$out/lib/libgstmse-1.0.so"
# The plugin links our library; its RUNPATH points at ../lib so it never pulls in the system copy.
# shellcheck disable=SC2086
cc $cflags -shared -Wl,--no-undefined -Wl,-rpath,'$ORIGIN/../lib' -o "$out/gstreamer-1.0/libgstmse.so" \
"$src/gst/mse/gstmse.c" -L"$out/lib" -lgstmse-1.0 $libs
echo "gst-mse: built $out/lib/libgstmse-1.0.so.0 and $out/gstreamer-1.0/libgstmse.so"
[ "${1:-}" = test ] || exit 0
# C tests: each tests/gst-mse/*.c is a GLib test program run against our library and plugin only.
tcflags="-O0 -g -std=gnu11 -Wall -DGST_USE_UNSTABLE_API -I$src/gen -I$src/gst-libs
$(pkg-config --cflags gstreamer-1.0)"
tlibs="-L$out/lib -lgstmse-1.0 $(pkg-config --libs gstreamer-1.0)"
mkdir -p "$out/tests"
status=0
for t in "$root"/tests/gst-mse/*.c; do
bin=$out/tests/$(basename "$t" .c)
# shellcheck disable=SC2086
cc $tcflags -Wl,-rpath,"$out/lib" -o "$bin" "$t" $tlibs
echo "gst-mse: running $(basename "$bin")"
GST_PLUGIN_PATH=$out/gstreamer-1.0 GST_REGISTRY=$out/tests/registry.bin \
TESTS_DATA_DIR=$root/tests/gst-mse/data "$bin" || status=1
done
exit $status