# Builds the package from this checkout: cd packaging/arch && makepkg -si
_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"

pkgname=tunal
# The workspace version plus the commit, so every update installs as an upgrade.
pkgver="$(sed -n 's/^version = "\(.*\)"/\1/p' "$_root/Cargo.toml" | head -n1).r$(git -C "$_root" rev-list --count HEAD).g$(git -C "$_root" rev-parse --short=7 HEAD)"
pkgrel=1
pkgdesc="File manager with Material You styling, music tags, devices and SFTP"
arch=(x86_64 aarch64)
url="https://archlinux.tail7c4f5e.ts.net/git/astar76/Tunal"
license=(GPL-3.0-or-later Apache-2.0)
depends=(
    alsa-lib fontconfig glibc hicolor-icon-theme libgcc libglvnd libx11 libxcursor libxi
    libxkbcommon libxkbcommon-x11 wayland xdg-utils
)
makedepends=(cargo git)
optdepends=(
    "polkit: administrator file operations"
    "xdg-desktop-portal: accent colour, dark mode and file pickers"
    "ffmpeg: video thumbnails"
    "7zip: 7z and most other archives"
    "libarchive: tar archives"
    "zip: zip archives"
    "udisks2: USB drives and other disks"
    "usbmuxd: iOS devices"
)
options=(!debug !lto)

build() {
    cd "$_root"
    # The checkout's own build cache, with its flags, so an update only compiles what changed.
    unset RUSTFLAGS CFLAGS CXXFLAGS LDFLAGS CARGO_TARGET_DIR
    cargo build --release --locked -p tunal
}

package() {
    cd "$_root"
    DESTDIR="$pkgdir" bash scripts/install.sh --system --no-build
    install -Dm644 -t "$pkgdir/usr/share/licenses/$pkgname" assets/fonts/LICENSE
}
