# Maintainer: galister <galister-dev at pm dot me>

_pkgname=wayvr
pkgname=$_pkgname-git
pkgver=26.7.1.r46.6b22e4a
pkgrel=1
pkgdesc="Your way to enjoy VR on Linux! Access your Wayland/X11 desktop from SteamVR/Monado (OpenVR+OpenXR support)"
url="https://github.com/wayvr-org/wayvr"
arch=('x86_64')
license=('GPL-3.0-or-later')
depends=(glibc
  libxkbcommon
  libxkbcommon-x11
  hicolor-icon-theme
  libx11
  libstdc++
  libxcb
  libinput
  libxrandr
  libgcc
  dbus
  libpipewire
  alsa-lib
  openxr
  openvr
  dav1d
  systemd-libs
  libxext
  vulkan-icd-loader
  xwayland-satellite)
makedepends=(git
  cargo
  python3
  cmake
  clang
  shaderc
  vulkan-headers)
replaces=("wlx-overlay-s-git")
conflicts=("$_pkgname")
provides=("$_pkgname")
# can't update this URL, it'll break existing clones. the redirect is permanent anyway.
source=("$_pkgname::git+https://github.com/wlx-team/wayvr.git")
sha256sums=('SKIP')
options=(!lto)

# Use debug
export CARGO_PROFILE_RELEASE_DEBUG=2
export CMAKE_POLICY_VERSION_MINIMUM=3.5
export SHADERC_LIB_DIR=/usr/lib

pkgver() {
  cd "$_pkgname"
  git describe --long --tags --abbrev=7 | sed 's/^v//;s/\([^-]*-\)g/r\1/;s/-/./g'
}

prepare() {
  cd "$_pkgname"
  cd "$_pkgname"
  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
  cd "../${_pkgname}ctl"
  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "$_pkgname"
  cd "$_pkgname"
  cargo build --frozen --release --all-features
  cd "../${_pkgname}ctl"
  cargo build --frozen --release --all-features
}

package() {
  cd "$_pkgname"
  install -Dm0755 -t "$pkgdir/usr/bin/" "target/release/$_pkgname"
  install -Dm0755 -t "$pkgdir/usr/bin/" "target/release/${_pkgname}ctl"
  cd "$_pkgname/"
  install -Dm0644 -t "$pkgdir/usr/share/applications/" "$_pkgname.desktop"
  install -Dm0644 -t "$pkgdir/usr/share/icons/hicolor/128x128/apps/" "$_pkgname.png"
  install -Dm0644 -t "$pkgdir/usr/share/icons/hicolor/scalable/apps/" "$_pkgname.svg"
}
