# Maintainer: Coelacanthus <uwu@coelacanthus.name>

pkgname=nali-go
pkgver=0.8.1
pkgrel=1
pkgdesc='An offline tool for querying IP geographic information and CDN provider.'
arch=('x86_64')
url="https://github.com/zu1k/nali"
license=('MIT')
conflicts=('nali-cli')
depends=('glibc')
makedepends=('go')
source=("$pkgname-$pkgver::https://github.com/zu1k/nali/archive/refs/tags/v$pkgver.tar.gz")
sha256sums=('8918e4c1c720dad1590a42fa04c5fea1ec862148127206e716daa16c1ce3561c')
b2sums=('20954cd7071469abcd6caf19d5264b2f45bfd4fe0ebecc203965f305cc2e9d0a1b8000638dc508764644b036237706e8e26bc31c7c67b5db4aab0797694fc41c')
# FIXME: Golang no support
options=(!lto)

build() {
  cd "$srcdir/nali-$pkgver"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOPATH="${srcdir}"
  export GOFLAGS="-buildmode=pie -mod=readonly -modcacherw"
  go build \
      -ldflags "-compressdwarf=false -linkmode external -X \"github.com/zu1k/nali/internal/constant.Version=$pkgver\"" \
      -o $pkgname .
}

package() {
  cd "$srcdir/nali-$pkgver"
  install -Dm755 $pkgname "$pkgdir"/usr/bin/$pkgname
  ln -sf ./$pkgname "$pkgdir"/usr/bin/nali
  mkdir -p "$pkgdir/usr/share/bash-completion/completions/"
  ./$pkgname completion bash > "$pkgdir/usr/share/bash-completion/completions/nali"
  mkdir -p "$pkgdir/usr/share/zsh/site-functions/"
  ./$pkgname completion zsh > "$pkgdir/usr/share/zsh/site-functions/_nali"
  mkdir -p "$pkgdir/usr/share/fish/completions/"
  ./$pkgname completion fish > "$pkgdir/usr/share/fish/completions/nali.fish"
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
# vim:set ts=2 sw=2 et:
