# Maintainer: Morten Linderud <foxboron@archlinux.org>

pkgname=git-lfs
pkgver=3.7.1
pkgrel=1
pkgdesc="Git extension for versioning large files"
arch=('x86_64' 'aarch64')
url="https://git-lfs.github.com"
license=('MIT')
makedepends=('go' 'ruby-ronn' 'go-tools' 'asciidoctor')
depends=('git')
source=("git+https://github.com/git-lfs/git-lfs.git#tag=v${pkgver}?signed")
validpgpkeys=('88ACE9B29196305BA9947552F1BA225C0223B187'  # brian m. carlson <sandals@crustytoothpaste.net>
              '86CD3297749375BCF8206715F54FE648088335A9') # Chris Darroch (CODE SIGNING KEY) <chrisd@apache.org>
sha256sums=('772c6b5471277a89cac3a3d1164278274108798b1b063af5f78a1a11098fd5b2')

build(){
  cd "$pkgname"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -modcacherw -ldflags=-linkmode=external"
  go mod vendor
  go generate ./commands
  go build .
  make man
}

check(){
  cd "$pkgname"
  go test -mod=vendor ./...
}

package() {
  cd "$pkgname"
  install -Dm755 $pkgname "$pkgdir"/usr/bin/$pkgname
  install -Dm644 LICENSE.md "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
  install -Dm644 -t "$pkgdir"/usr/share/man/man1 man/man1/*.1
  install -Dm644 -t "$pkgdir"/usr/share/man/man5 man/man5/*.5
  "${pkgname}" completion bash | install -Dm644 /dev/stdin \
    "${pkgdir}/usr/share/bash-completion/completions/${pkgname}"
  "${pkgname}" completion fish | install -Dm644 /dev/stdin \
    "${pkgdir}/usr/share/fish/vendor_completions.d/${pkgname}.fish"
  "${pkgname}" completion zsh | install -Dm644 /dev/stdin \
    "${pkgdir}/usr/share/zsh/site-functions/_${pkgname}"
}
