# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=go-task
pkgver=3.12.0
pkgrel=1
pkgdesc='A task runner/simpler Make alternative written in Go'
arch=('x86_64')
url='https://taskfile.dev'
license=('MIT')
depends=('glibc')
makedepends=('git' 'go')
options=('!lto')
install=go-task.install
_commit='f2abc13ce2e26017b69ea7de1327aa8be7892da5'
source=("$pkgname::git+https://github.com/go-task/task#commit=$_commit")
md5sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # download dependencies
  go mod download
}

build() {
  cd "$pkgname"

  # set Go flags
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"

  go build -v \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-linkmode external -extldflags ${LDFLAGS} \
    -X main.version=${pkgver}" \
    -o go-task \
    ./cmd/...
}

check() {
  cd "$pkgname"

  go test -v ./...
}

package() {
  cd "$pkgname"

  # binary
  install -vDm755 -t "$pkgdir/usr/bin" go-task

  # XXX: completions require a bit of massaging, so they're not packaged yet

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}