# Maintainer: Tim Singel <gamer.tdogtim@gmail.com>
pkgname=nebula-reader
pkgver=0.2.2
pkgrel=1
pkgdesc='Comic, manga and ebook reader for COSMIC and other desktops'
arch=('x86_64' 'aarch64')
url='https://github.com/NotTimm/NebulaReader'
license=('GPL-3.0-only')
depends=(
  'gcc-libs'
  'glibc'
  'libarchive'
  'libxkbcommon'
  'openssl'
  'wayland'
)
makedepends=(
  'cargo'
  'git'
  'pkgconf'
)
options=('!lto')
source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/refs/tags/v${pkgver}.tar.gz")
# Run packaging/aur/update-aur.sh <version> to fill in the real SHA-256 and
# regenerate .SRCINFO before pushing to the AUR.
sha256sums=('SKIP')

prepare() {
  cd "NebulaReader-${pkgver}"
  export RUSTUP_TOOLCHAIN=stable
  cargo fetch --locked --target "$(rustc --print host-tuple)"
}

build() {
  cd "NebulaReader-${pkgver}"
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_TARGET_DIR=target
  export NEBULA_DISTRO=1
  cargo build --frozen --release
}

check() {
  cd "NebulaReader-${pkgver}"
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_TARGET_DIR=target
  cargo test --frozen --release
}

package() {
  cd "NebulaReader-${pkgver}"
  install -Dm755 "target/release/${pkgname}" "${pkgdir}/usr/bin/${pkgname}"
  install -Dm644 "res/io.github.NotTimm.NebulaReader.desktop" \
    "${pkgdir}/usr/share/applications/io.github.NotTimm.NebulaReader.desktop"
  install -Dm644 "res/io.github.NotTimm.NebulaReader.metainfo.xml" \
    "${pkgdir}/usr/share/metainfo/io.github.NotTimm.NebulaReader.metainfo.xml"
  for png in res/icons/hicolor/*/apps/io.github.NotTimm.NebulaReader.png; do
    install -Dm644 "$png" "${pkgdir}/usr/share/icons/hicolor/${png#res/icons/hicolor/}"
  done
  install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
