# Contributor: Kevin Daudt <kdaudt@alpinelinux.org>
# Maintainer: Kevin Daudt <kdaudt@alpinelinux.org>
pkgname=gdu
pkgver=5.30.1
_majorver=${pkgver%%.*}
pkgrel=5
pkgdesc="Fast disk usage calculator with console interface"
url="https://github.com/dundee/gdu"
arch="all"
license="MIT"
makedepends="go gzip"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/dundee/gdu/archive/refs/tags/v$pkgver.tar.gz
	ash.patch
	"

export GOFLAGS="$GOFLAGS -modcacherw"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	default_prepare

	rm -rf vendor/
}

build() {
	local versionflags
	versionflags="
	-X github.com/dundee/gdu/v$_majorver/build.Version=$pkgver
	-X github.com/dundee/gdu/v$_majorver/build.User=buildozer
	-X 'github.com/dundee/gdu/v$_majorver/build.Time=$(date)'
	"
	go build -v \
		-ldflags="$versionflags" \
		./cmd/gdu

	gzip gdu.1
}

check() {
	# These tests are failing on 32-bit with: "error:
	# cannot allocate memory while mmapping
	# /tmp/badger/000002.vlog with size: 2147483646"
	case "$CARCH" in
	arm*|x86)
		go test -skip 'TestStoredAnalyzer|TestRemoveStoredFile|Test.*Storage' -v ./... ;;
	*)
		go test -v ./... ;;
	esac
}

package() {
	install -Dm0755 gdu -t "$pkgdir"/usr/bin/
	install -Dm0644 gdu.1.gz -t "$pkgdir"/usr/share/man/man1/
	install -Dm0644 LICENSE.md -t "$pkgdir"/usr/share/licenses/gdu/
}

sha512sums="
a12b04438e248486e10fd448f5e9fc76d4a424bfe6522085ee75665bbf91cf934f03770054cff38a58e32744d20bb56717e90c4c79a1dc1ae9a35a556ee8930c  gdu-5.30.1.tar.gz
cc85da4cb2c015166c916ea33768c6b486b8c12bdfce37ffcf1b9c8b7e9c6504de25425d6f71d3d03750fc82732ee69ab34c5f494b0ef3d8c5cc4e4f79e79cd7  ash.patch
"
