# Maintainer: loathingkernel at cachyos dot org

pkgname=rare
pkgver=1.12.0.178
pkgrel=1
pkgdesc="Open source alternative for Epic Games Launcher, using Legendary"
arch=('any')
url="https://github.com/RareDevs/Rare"
license=('GPL3')
depends=(
  clang
  lld
  patchelf
  pyside6
)
makedepends=(
  git
)
optdepends=(
  "wine: run Windows games"
  "proton: run Windows games"
)
source=("git+https://github.com/RareDevs/Rare.git#tag=$pkgver"
        rare.sh)
sha256sums=('b07634169e79aa5a2bce552d3314742f6e9c622d218b5f7f77a1a8a21536eb83'
            '175c6284247bd9f40b2057d80a33498f8b54d1249468bbb2d0c26b497f912e43')

prepare() {
  cd Rare
  python -m venv venv
  source venv/bin/activate
  pip install nuitka ruff
  pip install -r misc/requirements.in
  deactivate
}

build() {
  cd Rare
  source venv/bin/activate
  ./tools/ui2py.sh --force
  ./tools/qrc2py.sh --force
  ./tools/ts2qm.py
  export SETUPTOOLS_SCM_PRETEND_VERSION="$pkgver"
  python -m setuptools_scm --force-write-version-files
  nuitka_opts=(
    '--output-dir=build'
    '--show-scons'
    '--clang'
    '--lto=no'
    '--static-libpython=no'
    '--standalone'
    '--enable-plugin=anti-bloat'
    '--enable-plugin=pyside6'
    '--enable-plugin=multiprocessing'
    '--no-deployment-flag=self-execution'
    '--show-modules'
    '--show-anti-bloat-changes'
    '--follow-stdlib'
    '--follow-imports'
    '--nofollow-import-to="*.tests"'
    '--nofollow-import-to="*.distutils"'
    '--nofollow-import-to="distutils"'
    '--nofollow-import-to="unittest"'
    '--nofollow-import-to="pydoc"'
    '--nofollow-import-to="tkinter"'
    '--nofollow-import-to="test"'
    '--prefer-source-code'
    '--include-package=pypresence'
    '--include-package-data=qtawesome'
    '--include-data-dir=rare/resources/images/=rare/resources/images/'
    '--include-data-files=rare/resources/languages/rare_*.qm=rare/resources/languages/'
    '--output-filename=Rare.bin'
    '--file-description=Rare.bin'
    '--company-name=RareDevs'
    '--product-name=Rare'
    "--file-version=$SETUPTOOLS_SCM_PRETEND_VERSION"
    "--product-version=$SETUPTOOLS_SCM_PRETEND_VERSION"
  )
  python -m nuitka "${nuitka_opts[@]}" rare < /dev/null
  deactivate
}

package() {
  cd Rare
  install -Dm755 "$srcdir/rare.sh" "$pkgdir/usr/bin/rare"
  install -Dm644 "misc/${pkgname%-git}.desktop" "$pkgdir/usr/share/applications/${pkgname%-git}.desktop"
  install -Dm644 "rare/resources/images/Rare.png" "$pkgdir/usr/share/pixmaps/${pkgname%-git}.png"
  cd build/rare.dist
  find . -type f -exec install -Dm 644 "{}" "$pkgdir/opt/rare/{}" \;
  chmod 755 "$pkgdir/opt/rare/Rare.bin"
}

