# Template file for 'go1.12-bootstrap'
pkgname=go1.12-bootstrap
version=1.12.17
revision=1
archs="x86_64* i686* armv[67]l* aarch64* ppc64le*"
wrksrc="go"
short_desc="Go 1.12 (bootstrap compiler)"
maintainer="q66 <daniel@octaforge.org>"
license="BSD-3-Clause"
homepage="https://golang.org"
nostrip=yes
noverifyrdeps=yes
nocross=yes
lib32disabled=yes

if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
	depends+=" gcompat"
	hostmakedepends+=" patchelf"
fi

case "$XBPS_TARGET_MACHINE" in
	x86_64*)
		_dist_arch="amd64"
		checksum="a53dd476129d496047487bfd53d021dd17e0c96895865a0e7d0469ce3db8c8d2"
		;;
	i686*)
		_dist_arch="386"
		checksum="e33fc10c0486b02a019f120996d77792d8f19aae8bfdda97350a622a65d6b824"
		;;
	arm*)
		_dist_arch="armv6l"
		checksum="a883c806fccb3eddb26da4a1a1f8536de863aee6807ed6c99606261877af7b99"
		;;
	aarch64*)
		_dist_arch="arm64"
		checksum="9d0819cce1451abdb090071880fe8771f16a3bcee71d6f6906023d17799574e2"
		;;
	ppc64le*)
		_dist_arch="ppc64le"
		checksum="dca4df132da7579c352bccd9d6f4ecb8d8d61893a84b0feffcee2bb4246114a3"
		;;
esac

distfiles="https://dl.google.com/go/go${version}.linux-${_dist_arch}.tar.gz"

post_build() {
	[ "$XBPS_TARGET_LIBC" != "musl" ] && return 0

	# we don't have lib64 compatibility path on musl 64-bit systems
	# use patchelf to replace /lib64/<dynlinker> with /lib/<dynlinker>

	local _interp=$(patchelf --print-interpreter ${wrksrc}/bin/go)

	patchelf --set-interpreter ${_interp/lib64\//lib\/} ${wrksrc}/bin/go
	patchelf --set-interpreter ${_interp/lib64\//lib\/} ${wrksrc}/bin/godoc
}

do_install() {
	vmkdir usr/lib/go1.12
	vcopy bin usr/lib/go1.12
	vcopy src usr/lib/go1.12
	vcopy pkg usr/lib/go1.12
	vlicense LICENSE
}
