# Template file for 'eduvpn-common'
pkgname=eduvpn-common
version=5.0.1
revision=1
build_style=go
go_import_path=codeberg.org/eduVPN/eduvpn-common
hostmakedepends="python3-setuptools python3-wheel python3-packaging-bootstrap"
short_desc="Code to be shared between eduVPN clients"
maintainer="John <me@johnnynator.dev>"
license="MIT"
homepage="https://www.eduvpn.org/"
distfiles="https://codeberg.org/eduVPN/eduvpn-common/releases/download/${version}/eduvpn-common-${version}.tar.xz"
checksum=5b97feaaf14456ee3eb30853c1c78c2b166de541d8f8ee1db7ea0d0ccfc812c3

subpackages="eduvpn-cli"

if [ "$XBPS_TARGET_LIBC" = "glibc" ]; then
	# Creating shared libraries for musl with go isn't fully supported
	#broken="https://github.com/golang/go/issues/54805"
	subpackages+=" python3-eduvpn_common"
fi

do_build() {
	go build -x -o libeduvpn_common-${version}.so \
		-mod="vendor" -modcacherw \
		-buildmode=c-shared -ldflags "${go_ldflags}" \
		${go_import_path}/exports
	mv libeduvpn_common-${version}.h eduvpn_common.h
	go install -x -p "$XBPS_MAKEJOBS" -ldflags "${go_ldflags}" \
		-mod="vendor" -modcacherw \
		${go_import_path}/cmd/eduvpn-cli
	if [ "$XBPS_TARGET_LIBC" = "glibc" ]; then
		cd wrappers/python
		python3 setup.py build
	fi
}

do_install() {
	vlicense LICENSE
	vinstall libeduvpn_common-${version}.so 755 /usr/lib
	vinstall eduvpn_common.h 644 /usr/include
	for f in ${GOPATH}/bin/* ${GOPATH}/bin/**/*; do
		if [ -f "$f" ] && [ -x "$f" ]; then
			vbin "$f"
		fi
	done
	if [ "$XBPS_TARGET_LIBC" = "glibc" ]; then
		cd wrappers/python
		python3 setup.py install --prefix=/usr --root=${DESTDIR}
	fi
}

eduvpn-cli_package() {
	conflicts="eduvpn-client>=0"
	short_desc+=" - Cli"
	pkg_install() {
		vmove usr/bin
	}
}

python3-eduvpn_common_package() {
	short_desc+=" - Python3 bindings"
	depends="${sourcepkg}>=${version}_${revision}"
	pkg_install() {
		vmove ${py3_sitelib}
	}
}
