# Maintainer: Kimiblock Moe
# Contributor: HurricanePootis <hurricanepootis@protonmail.com>
pkgname=an-anime-game-launcher-bwrap
pkgver=3.19.7
pkgrel=4
pkgdesc="A Launcher for a specific anime game with auto-patching, discord rpc and time tracking"
arch=('x86_64')
provides=('an-anime-game-launcher' 'an-anime-game-launcher-portable')
conflicts=('an-anime-game-launcher')
url="https://github.com/an-anime-team/an-anime-game-launcher"
license=('GPL-3.0-only')
options=(!lto)
depends=('gtk4' 'libadwaita' 'glibc' 'hicolor-icon-theme' 'gcc-libs' 'glib2'
	 'pango' 'xz' 'bzip2' 'cairo' 'p7zip' 'portable' 'protobuf')
makedepends=('rust' 'git' 'portable-packer')
optdepends=(
	 'mangohud: FPS Overlay')
source=("git+$url.git"
	"config.toml"
	"desktop.file")
sha256sums=('SKIP'
            '9efeb3496896a06c2d524d4636548972a495f8da55d3495b8bcc07f120147ab2'
            'bd7626b79160696218abc22c4633b0c13f3c8647b183ceb7b30f75a22b969beb')

prepare() {
	cd "$srcdir/an-anime-game-launcher"
	export RUSTUP_TOOLCHAIN=stable
	cargo fetch --locked --target "host-tuple"
}

build() {
	cd "$srcdir/an-anime-game-launcher"
	export RUSTUP_TOOLCHAIN=stable
	export CARGO_TARGET_DIR=target
#	export CFLAGS+=" -ffat-lto-objects"
	cargo build --release --target-dir target
}

package() {
	cd "$srcdir/an-anime-game-launcher"
	install -Dm755 "target/release/anime-game-launcher" "$pkgdir/usr/bin/an-anime-game-launcher"
	install -Dm644 "assets/anime-game-launcher.desktop" "$pkgdir/usr/share/applications/an-anime-game-launcher.desktop"
	install -Dm644 "assets/images/icon.png" "$pkgdir/usr/share/icons/hicolor/512x512/apps/moe.launcher.an-anime-game-launcher.png"
	install -dm755 "$pkgdir/usr/share/pixmaps"
	ln -s "/usr/share/icons/hicolor/512x512/apps/moe.launcher.an-anime-game-launcher.png" "$pkgdir/usr/share/pixmaps/an-anime-game-launcher.png"

	declare -x -g pkgdir
	declare -x -g pkgname
	declare -x -g srcdir
	portable-packer \
		-v \
		--distro arch \
		--mode post \
		--hash true \
		--config-ng "${srcdir}/config.toml" \
		--desktop-file "${srcdir}/desktop.file"
}
