# Maintainer: Valeria Fadeeva <valeria@fadeeva.me>

_gitname="$(basename $(pwd))"
pkgname=("$_gitname")
pkgver=0.10.1.212
pkgrel=1
pkgdesc="$(head -n 2 README.md | tail -n 1)"
arch=('x86_64')
url="https://git.melawy.ru/Installer/$_gitname"
groups=('melawy')

license=('GPL3')

makedepends=('meson' 'git' 'mold' 'rustup' 'clang')

depends=('gtk3' 'glib2' 'appstream-glib')

provides=("$_gitname")
conflicts=("$_gitname")

options=(strip)
source=("git+$url.git")

sha256sums=('SKIP')

pkgver() {
        cd "${srcdir}/${_gitname}/"
        printf "0.10.1.%s" "$(git rev-list --count HEAD)"
}

build() {
  cd "${srcdir}/${_gitname}/"

  if ! rustc --version | grep nightly >/dev/null 2>&1; then
    echo "Installing nightly compiler…"
    rustup toolchain install nightly
    rustup default nightly
  fi

  _cpuCount=$(grep -c -w ^processor /proc/cpuinfo)

  export RUSTFLAGS="-Cembed-bitcode -C opt-level=3 -Ccodegen-units=1 -Clinker=clang -C link-arg=-flto -Clink-arg=-fuse-ld=/usr/bin/mold"
  meson setup --buildtype=release --prefix=/usr build

  meson compile -C build --jobs $_cpuCount
}

package() {
  cd "${srcdir}/${_gitname}"/build

  export RUSTFLAGS="-Cembed-bitcode -C opt-level=3 -Ccodegen-units=1 -Clinker=clang -C link-arg=-flto -Clink-arg=-fuse-ld=/usr/bin/mold"
  DESTDIR="${pkgdir}" meson install

  install -Dvm644 ../${_gitname}.desktop \
    "$pkgdir/etc/skel/.config/autostart/${_gitname}.desktop"
}

# vim:set sw=2 sts=2 et:
