# Description: Open Broadcaster Software Studio
# URL: https://obsproject.com/
# Maintainer: unmaintained
# Depends on: alsa-lib fdk-aac ffmpeg jansson libgmp libva mbedtls qt6-svg speexdsp swig x264
# Optional: ffnvcodec-headers jack-audio-connection-kit libva luajit pipewire pulseaudio speexdsp v4l-utils vlc wayland-protocols x265

name=obs-studio
version=29.1.3
release=1
source=(https://github.com/obsproject/$name/archive/$version/$name-$version.tar.gz
	disable-some-plugins.patch)

build() {
	prt-get isinst luajit || PKGMK_OBS+=' -D ENABLE_SCRIPTING_LUA=OFF'
	prt-get isinst pipewire || PKGMK_OBS+=' -D ENABLE_PIPEWIRE=OFF'
	prt-get isinst pulseaudio || PKGMK_OBS+=' -D ENABLE_PULSEAUDIO=OFF'
	prt-get isinst v4l-utils || PKGMK_OBS+=' -D ENABLE_V4L2=OFF'
	prt-get isinst vlc || PKGMK_OBS+=' -D ENABLE_VLC=OFF'
	prt-get isinst wayland-protocols && PKGMK_OBS+=' -D ENABLE_WAYLAND=ON' || PKGMK_OBS+=' -D ENABLE_WAYLAND=OFF'

	prt-get isinst ccache && PATH="$(echo ${PATH} | awk -v RS=: \
		-v ORS=: '/ccache/ {next} {print}' | sed 's/:*$//')"

	patch -Np1 -d $name-$version -i $SRC/disable-some-plugins.patch

	export QT_QPA_PLATFORMTHEME="qt6ct"
	cmake -S $name-$version -B build -G Ninja $PKGMK_OBS \
		-D CMAKE_INSTALL_PREFIX=/usr \
		-D CMAKE_INSTALL_LIBDIR=lib \
		-D CMAKE_BUILD_TYPE=Release \
		-D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS" \
		-D CMAKE_C_FLAGS_RELEASE="$CFLAGS" \
		-D QT_VERSION=6 \
		-D OBS_VERSION_OVERRIDE="$version" \
		-D UNIX_STRUCTURE=ON \
		-D BUILD_VST=OFF \
		-D BUILD_BROWSER=OFF \
		-D ENABLE_DECKLINK=OFF \
		-D ENABLE_NEW_MPEGTS_OUTPUT=OFF \
		-D LIBOBS_PREFER_IMAGEMAGICK=OFF \
		-Wno-dev

	cmake --build build
	DESTDIR=$PKG cmake --install build

	find $PKG -type d -exec chmod g-w '{}' \;

	rm $PKG/usr/share/obs/obs-studio/authors/AUTHORS

	find $PKG/usr/share/obs \
		-iname '*ini' \
		! -iname 'en-*.ini' \
		! -iname 'locale.ini' \
		-exec rm '{}' \+
}
