# Copyright 2024-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit go-module

DESCRIPTION="Command line interface for LibreSpeed speed test backends"
HOMEPAGE="https://github.com/librespeed/speedtest-cli"

SRC_URI="
	https://github.com/librespeed/speedtest-cli/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz
	mirror://jacksonchen666/${P}-vendor.tar.xz
"
S="${WORKDIR}/speedtest-cli-${PV}/"

# TODO: LGPL-3 or later?
LICENSE="LGPL-3"
# deps license checked as of 7573b65ebc89a4cf463334dbdfab5b3edc706149
LICENSE+=" Apache-2.0 MIT BSD BSD-2"
SLOT="0"
KEYWORDS="~amd64 ~arm64"

#DEPEND=""
RDEPEND="${DEPEND}"
# go version from go.mod
BDEPEND=">=dev-lang/go-1.26.0"
RESTRICT="mirror"

src_unpack() {
	go-module_src_unpack
}

src_compile() {
	DEFS_PATH="github.com/librespeed/speedtest-cli"
	ego build -ldflags "-w -X \"${DEFS_PATH}/defs.ProgName=${PN}\" \
		-X \"${DEFS_PATH}/defs.ProgVersion=${PV}\"
		-X \"${DEFS_PATH}/defs.BuildDate=$(date -u "+%Y-%m-%d %H:%M:%S %Z")\"" \
		-o librespeed-cli -trimpath main.go
}

src_install() {
	default

	dobin librespeed-cli
}