# Edit on github: https://github.com/LizardByte/Sunshine/blob/nightly/packaging/linux/Arch/PKGBUILD
# Reference: https://wiki.archlinux.org/title/PKGBUILD

pkgname='sunshine'
pkgver=@PROJECT_VERSION@@SUNSHINE_SUB_VERSION@
pkgrel=1
pkgdesc="@PROJECT_DESCRIPTION@"
arch=('x86_64' 'aarch64')
url=@PROJECT_HOMEPAGE_URL@
license=('GPL-3.0-only')
install=sunshine.install

depends=('avahi'
         'boost-libs'
         'curl'
         'libayatana-appindicator'
         'libcap'
         'libdrm'
         'libevdev'
         'libmfx'
         'libnotify'
         'libpulse'
         'libva'
         'libvdpau'
         'libx11'
         'libxcb'
         'libxfixes'
         'libxrandr'
         'libxtst'
         'miniupnpc'
         'numactl'
         'openssl'
         'opus'
         'python'
         'udev')
checkdepends=('doxygen'
              'graphviz')
makedepends=('boost'
             'cmake'
             'gcc12'
             'git'
             'make'
             'nodejs'
             'npm')
optdepends=('cuda: Nvidia GPU encoding support'
            'libva-mesa-driver: AMD GPU encoding support'
            'intel-media-driver: Intel GPU encoding support'
            'xorg-server-xvfb: Virtual X server for headless testing')

provides=('sunshine')

source=("$pkgname::git+@GITHUB_CLONE_URL@#commit=@GITHUB_COMMIT@")
sha256sums=('SKIP')

prepare() {
    cd "$pkgname"
    git submodule update --recursive --init
}

build() {
    export BRANCH="@GITHUB_BRANCH@"
    export BUILD_VERSION="@GITHUB_BUILD_VERSION@"
    export COMMIT="@GITHUB_COMMIT@"

    export CC=gcc-12
    export CXX=g++-12

    export CFLAGS="${CFLAGS/-Werror=format-security/}"
    export CXXFLAGS="${CXXFLAGS/-Werror=format-security/}"

    cmake \
        -S "$pkgname" \
        -B build \
        -Wno-dev \
        -D BUILD_WERROR=ON \
        -D CMAKE_INSTALL_PREFIX=/usr \
        -D SUNSHINE_EXECUTABLE_PATH=/usr/bin/sunshine \
        -D SUNSHINE_ASSETS_DIR="share/sunshine"

    make -C build
}

check() {
   export CC=gcc-12
   export CXX=g++-12

   cd "${srcdir}/build/tests"
   ./test_sunshine --gtest_color=yes
}

package() {
    make -C build install DESTDIR="$pkgdir"
}
