# chiaki-ng with SmoovPlay's frame tap, for Arch Linux: PlayStation Remote Play in Summit, with Enhance.
# Copied from SmoovPlay's chiaki_tap/ (https://github.com/smoovplay/smoovplay, MIT), unchanged but for these lines.
#
#   cd packaging/chiaki-ng && makepkg -si      (install.sh --with-remote-play does this)
#
# Builds chiaki-ng v1.10.1 (the version apply_patch.py's edits are written against) with the tap compiled in. With
# CHIAKI_FRAMETAP unset it behaves exactly like chiaki-ng; Summit (and SmoovPlay) start it with CHIAKI_FRAMETAP=1. It replaces
# the chiaki-ng package (provides/conflicts), so the controller mapping and registered consoles carry over.
#
# chiaki-ng is AGPL-3.0; the tap files are MIT (SmoovPlay). The result is a build of chiaki-ng, under its licence.
pkgname=chiaki-ng-smoovplay
_tag=v1.10.1
pkgver=1.10.1
pkgrel=1
pkgdesc="chiaki-ng (PS5 Remote Play) with SmoovPlay's frame tap, for SmoovPlay's frame generation"
arch=('x86_64')
url="https://github.com/smoovplay/smoovplay"
license=('AGPL-3.0-only' 'MIT')
depends=('qt6-base' 'qt6-declarative' 'qt6-svg' 'qt6-wayland' 'qt6-webengine' 'qt6-positioning' 'ffmpeg'
         'sdl2-compat' 'opus' 'openssl' 'json-c' 'miniupnpc' 'libevent' 'hidapi' 'libplacebo' 'speexdsp' 'fftw'
         'lcms2' 'libdovi' 'shaderc' 'spirv-cross' 'protobuf' 'systemd-libs' 'libevdev' 'curl')
makedepends=('cmake' 'ninja' 'git' 'python' 'python-protobuf' 'python-setuptools' 'qt6-shadertools'
             'vulkan-headers' 'fast_float')
provides=('chiaki-ng')
conflicts=('chiaki-ng' 'chiaki-ng-bin' 'chiaki-ng-git')
source=("chiaki-ng::git+https://github.com/streetpea/chiaki-ng.git#tag=${_tag}"
        'apply_patch.py' 'frametap.c' 'frametap.h' 'frametap_session.cpp' 'frametap_session.h')
sha256sums=('SKIP' 'SKIP' 'SKIP' 'SKIP' 'SKIP' 'SKIP')  # the tap files come from this folder; the tag pins chiaki-ng

prepare() {
  cd chiaki-ng
  git submodule update --init --recursive --depth 1
  python "${srcdir}/apply_patch.py" .
}

build() {
  cmake -S chiaki-ng -B build -G Ninja \
    -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \
    -DCHIAKI_ENABLE_CLI=OFF -DCHIAKI_ENABLE_TESTS=OFF -DCHIAKI_USE_SYSTEM_CURL=ON  # the bundled curl fails on OpenSSL 3.6+
  cmake --build build --target chiaki
}

package() {
  DESTDIR="${pkgdir}" cmake --install build --component Unspecified 2>/dev/null || DESTDIR="${pkgdir}" cmake --install build
  install -Dm644 chiaki-ng/COPYING "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}
