# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>

pkgname=go-tools
epoch=4
pkgver=0.23.0
pkgrel=1
pkgdesc='Developer tools for the Go programming language'
arch=(x86_64 powerpc64le riscv64)
url='https://golang.org/'
license=(BSD)
depends=(glibc)
makedepends=(git go)
source=(go-tools::git+https://go.googlesource.com/tools#tag=v$pkgver)
sha256sums=('c404923c2655a985db4654165a8e917b036e6e8e7b19a8f6bb38222bbd903766')

_tools=(benchcmp callgraph compilebench digraph eg fiximports
        go-contrib-init godex godoc goimports gomvpkg gorename gotype 
        goyacc html2article present ssadump stringer toolstash)

prepare() {
    cd go-tools
    mkdir -p bin/
}

build() {
  cd go-tools
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -mod=readonly -modcacherw"
  go build -ldflags "-compressdwarf=false -linkmode external" -o bin/ ./cmd/...
}

check() {
  cd go-tools
  # Needs to be updated and godoc is failing the test suite
  # See https://github.com/golang/go/issues/35690
  go test ./cmd/...  || true
}

package() {
  cd go-tools
  for tool in ${_tools[@]}; do
    install -Dm755 bin/$tool "$pkgdir/usr/bin/$tool"
  done

  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
