# Maintainer: Leonidas Spyropoulos <artafinde@archlinux.org>
# Contributor: Daniel Milde <daniel at milde dot cz>

pkgname=gdu
pkgver=5.31.0
pkgrel=1
license=('MIT')
pkgdesc="Fast disk usage analyzer"
depends=('glibc')
makedepends=('go' 'git')
arch=('x86_64' 'aarch64')
url="https://github.com/dundee/gdu"
source=("git+https://github.com/dundee/gdu.git#tag=v${pkgver}?signed")
sha256sums=('7e9eadf28fa2c46a284282a30478e350ee1fd9fbb8d6fecbc4a6ffcd4bb8d5cc')
validpgpkeys=(
  360B658707A1A44CA57FB67EEF0BA1C4F3990103  # Daniel Milde <daniel@milde.cz>, retrieved from https://github.com/dundee.gpg
  )

prepare() {
  cd ${pkgname}
  mkdir -p dist/
}

build() {
  cd ${pkgname}
  local _DATE=$(git log -1 --pretty=%ct) # get commit date to make it REPRODUCABLE
  local _BUILDINFO="-X 'github.com/dundee/gdu/v5/build.Version=${pkgver}' \
                    -X 'github.com/dundee/gdu/v5/build.User=${PACKAGER}' \
                    -X 'github.com/dundee/gdu/v5/build.Time=${_DATE}'"
                    
  GOPATH="${srcdir}"
  go build \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -pgo=default.pgo \
    -ldflags "-compressdwarf=false -linkmode external -extldflags \"${LDFLAGS}\" ${_BUILDINFO}" \
    -o dist/gdu \
    github.com/dundee/gdu/v5/cmd/gdu
}

check() {
  cd ${pkgname}
  go test -skip 'TestAnalyzePathWithIgnoring' ./...
}

package() {
  cd ${pkgname}
  install -Dm755 dist/$pkgname "${pkgdir}/usr/bin/$pkgname"
  install -Dm644 gdu.1    "${pkgdir}/usr/share/man/man1/$pkgname.1"
  install -D -m644 LICENSE.md  "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

# vim:set ts=2 sw=2 et:
