# Maintainer: noturbob <142563527+noturbob@users.noreply.github.com>
pkgname=slat
pkgver=0.2.0
pkgrel=1
pkgdesc='Terminal multiplexer with tiling panes, tabs and workspaces that keep running after you close the window'
arch=('x86_64' 'aarch64')
url='https://github.com/noturbob/slat'
license=('MIT')
depends=('glibc')
makedepends=('go')
source=("$pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz")
sha256sums=('SKIP')

build() {
  cd "$pkgname-$pkgver"
  export CGO_CPPFLAGS="$CPPFLAGS"
  export CGO_CFLAGS="$CFLAGS"
  export CGO_CXXFLAGS="$CXXFLAGS"
  export CGO_LDFLAGS="$LDFLAGS"
  export GOFLAGS='-buildmode=pie -trimpath -mod=readonly -modcacherw'
  go build -ldflags "-linkmode=external -X github.com/noturbob/slat/internal/app.Version=v$pkgver" \
    -o slat ./cmd/slat
}

check() {
  cd "$pkgname-$pkgver"
  # The end-to-end tests need a PTY and a shell, which clean chroots may lack.
  go test ./internal/vt/ ./internal/layout/ ./internal/config/ ./cmd/slat/
}

package() {
  cd "$pkgname-$pkgver"
  install -Dm755 slat "$pkgdir/usr/bin/slat"
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
  install -Dm644 config.example.toml "$pkgdir/usr/share/doc/$pkgname/config.example.toml"
}
