#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobextra/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname=obs-studio
pkgver=29.0.2
#pkgver=29.0.0124+ga0b5c1b3f
#pkgver=${_pkgver//-/_}
pkgrel=02
#epoch=3
pkgdesc="Free and open source software for video recording and live streaming. w/o systemd pipewire pulseaudio"
arch=("x86_64")
url="https://github.com/obsproject/obs-studio"
depends=("ffmpeg" "jansson" "libxinerama" "libxkbcommon-x11" "mbedtls" "rnnoise" "pciutils"
         "qt5-svg" "curl" "gtk-update-icon-cache" "libxcomposite")
# "speexdsp" "pciutils" "libajantv2" "librist")
makedepends=('cmake' 'libfdk-aac' 'x264' 'swig' 'python' 'luajit' 'sndio')

#makedepends=("cmake" "git" "libfdk-aac" "libxcomposite" "x264"
#             "vlc" "swig" "luajit" "python"
# "cef-minimal-obs-bin" #"wayland"
#             "qt5-wayland" "xdg-desktop-portal" 
#"pipewire"
#)
optdepends=("libfdk-aac: FDK AAC codec support"
            "libva-intel-driver: hardware encoding"
            "libva-mesa-driver: hardware encoding"
            "vlc: VLC Media Source"
            "luajit: Lua scripting"
            "python: Python scripting"
            'sndio: Sndio input client'
            "v4l2loopback-dkms: Virtual webcam"
			"jack2: The JACK low-latency audio server")
provides=("obs-studio=$pkgver")
conflicts=("obs-studio-git")
_commit=8d9fc74631bb8d0f7ca71d2c158f922b702e7750  # tags/29.0.2
source=("$pkgname::git+https://github.com/obsproject/obs-studio.git#commit=$_commit"
#source=("$pkgname::git+https://github.com/obsproject/obs-studio.git"
 #       "git+https://github.com/Mixer/ftl-sdk.git"
 #       "git+https://github.com/obsproject/obs-browser.git"
 #       "git+https://github.com/obsproject/obs-vst.git"
 #       "git+https://github.com/obsproject/obs-websocket.git"
 #       "git+https://github.com/chriskohlhoff/asio.git"
 #       "git+https://github.com/nlohmann/json.git"
 #       "git+https://github.com/nayuki/QR-Code-generator.git"
 #       "git+https://github.com/zaphoyd/websocketpp.git"
		fix_python_binary_loading.patch
        ignore_unused_submodules.patch)

##pkgver() {
##  cd $pkgname
##  git describe --long --tags | cut -d- -f1-2 | sed "s/-/\./"
##}
#pkgver() {
#  cd $pkgname
#  git describe --long | sed "s/$pkgname//" | sed 's/^Release.//;s/\([^-]*-g\)/\1/;s/-/+/g;' | sed 's/+//'
#}

prepare() {
#  gitconf="protocol.file.allow=always"

  cd $pkgname
  patch -Np1 < "$srcdir"/fix_python_binary_loading.patch
  patch -Np1 < "$srcdir"/ignore_unused_submodules.patch

#  git config submodule.plugins/obs-outputs/ftl-sdk.url $srcdir/ftl-sdk
#  git config submodule.plugins/obs-browser.url $srcdir/obs-browser
#  git config submodule.plugins/obs-vst.url $srcdir/obs-vst
#  git config submodule.plugins/obs-websocket.url $srcdir/obs-websocket
#  git -c $gitconf submodule update
#
#  cd plugins/obs-websocket
#  git config submodule.deps/asio.url $srcdir/asio
#  git config submodule.deps/json.url $srcdir/json
#  git config submodule.deps/qr.url $srcdir/QR-Code-generator
#  git config submodule.deps/websocketpp.url $srcdir/websocketpp
#  git -c $gitconf submodule update
}

build() {
  cmake -B build -S $pkgname \
    -DCMAKE_INSTALL_PREFIX="/usr" \
    -DENABLE_BROWSER=OFF \
    -DENABLE_VST=ON \
    -DENABLE_VLC=OFF \
    -DENABLE_NEW_MPEGTS_OUTPUT=OFF \
    -DENABLE_AJA=OFF \
    -DENABLE_JACK=ON \
    -DENABLE_ALSA=ON \
    -DENABLE_LIBFDK=ON \
    -DOBS_VERSION_OVERRIDE="$pkgver-$pkgrel" \
    -DENABLE_PIPEWIRE=FALSE \
    -DENABLE_PULSEAUDIO=FALSE \
    -Wno-dev
  cmake --build build


#  mkdir -p build; cd build
#
#  cmake \
#    -DCMAKE_INSTALL_PREFIX=/usr \
#    -DCMAKE_INSTALL_LIBDIR=lib \
#    -DBUILD_BROWSER=ON \
#    -DCEF_ROOT_DIR="/opt/cef-obs" \
#    ..
#  make
}

package() {
#  cd $pkgname/build
#
#  make install DESTDIR="$pkgdir"

  DESTDIR="$pkgdir" cmake --install build
}

#---- license gpg-key sha256sums ----

license=("GPL2")

sha256sums=(SKIP #SKIP SKIP SKIP SKIP SKIP SKIP SKIP SKIP 
	bdfbd062f080bc925588aec1989bb1df34bf779cc2fc08ac27236679cf612abd  #  fix_python_binary_loading.patch
	60b0ee1f78df632e1a8c13cb0a7a5772b2a4b092c4a2a78f23464a7d239557c3) # ignore_unused_submodules.patch

