# Template file for 'ghc-bin'
pkgname=ghc-bin
version=9.8.4
revision=1
archs="i686 x86_64* aarch64*"
hostmakedepends="patchelf"
depends="gcc libffi-devel gmp-devel"
short_desc="Glasgow Haskell Compiler - precompiled binaries"
maintainer="Orphaned <orphan@voidlinux.org>"
license="BSD-3-Clause"
homepage="http://www.haskell.org/ghc/"
nocross=yes
nostrip=yes
noshlibprovides=yes
conflicts="ghc>=0 ghc-doc>=0 ghc-devel>=0"

case "$XBPS_TARGET_MACHINE" in
x86_64*)
	distfiles="https://downloads.haskell.org/ghc/${version}/ghc-${version}-x86_64-alpine3_12-linux-static.tar.xz"
	checksum=02535eaef4f57aef8b7b272ef6f48d386d186ebd07fa47e227b46b93fa7eb0ab
	;;
i686)
	distfiles="https://downloads.haskell.org/ghc/${version}/ghc-${version}-i386-deb10-linux.tar.xz"
	checksum=e5efce16c654d5e702986258a87dd9531e1722b8051823c8ce1150ce3c5899ae
	;;
aarch64)
	distfiles="https://downloads.haskell.org/ghc/${version}/ghc-${version}-aarch64-deb11-linux.tar.xz"
	checksum=310204daf2df6ad16087be94b3498ca414a0953b29e94e8ec8eb4a5c9bf603d3
	;;
aarch64-musl)
	distfiles="https://downloads.haskell.org/ghc/${version}/ghc-${version}-aarch64-alpine3_18-linux.tar.xz"
	checksum=b5c86a0cda0bd62d5eeeb52b1937c3bd00c70cd67dd74226ce787d5c429a4e62
	;;
*)
	broken="No distfiles available for this target"
	;;
esac

do_configure() {
	./configure --prefix=/usr
}

do_install() {
	make install DESTDIR="$DESTDIR"

	# quiet lint: vlicense not needed, installed by make
}

post_install() {
	if [ "$XBPS_TARGET_MACHINE" = "aarch64-musl" ]; then
		for _cur_binary in $(find ${DESTDIR} -type f -exec file {} \; |grep ELF |grep -v static |cut -d ':' -f 1); do
			patchelf --replace-needed libc.musl-aarch64.so.1 libc.so $_cur_binary
		done
	fi
}
