# Template file for 'ghc-bin'
pkgname=ghc-bin
version=9.0.2
revision=1
archs="i686 x86_64* ppc64le* ppc64 aarch64*"
wrksrc="ghc-${version%[!0-9]}"
hostmakedepends="perl libffi libnuma"
depends="ncurses perl gcc libffi-devel gmp-devel"
short_desc="Glorious Haskell Compiler - precompiled binaries"
maintainer="slotThe <soliditsallgood@mailbox.org>"
license="BSD-3-Clause"
homepage="http://www.haskell.org/ghc/"
nocross=yes
nostrip=yes
noshlibprovides=yes
conflicts="ghc>=0 ghc-doc>=0"
case "$XBPS_TARGET_MACHINE" in
x86_64)
	distfiles="https://downloads.haskell.org/ghc/${version%[!0-9]}/ghc-${version}-x86_64-deb9-linux.tar.xz"
	checksum=805f5628ce6cec678ba77ff48c924831ebdf75ec2c66368e8935a618913a150e
	;;
x86_64-musl)
	# create with "make binary-dist"
	distfiles="https://alpha.de.repo.voidlinux.org/distfiles/ghc-${version}-x86_64-void-linux-musl.tar.xz"
	checksum=e21eaddeffcd5de7abe43b1f3982a3bc2c5b5f408d2574857cb2b0368106e12c
	;;
i686)
	distfiles="https://downloads.haskell.org/ghc/${version%[!0-9]}/ghc-${version}-i386-deb9-linux.tar.xz"
	checksum=fdeb9f8928fbe994064778a8e1e85bb1a58a6cd3dd7b724fcc2a1dcfda6cad47
	;;
ppc64le)
	distfiles="https://alpha.de.repo.voidlinux.org/distfiles/ghc-${version}-powerpc64le-void-linux.tar.xz"
	checksum=7de8114c991f9a2a3b0f5e472da76e3956be6447efec4b1157f14e707049f22d
	;;
ppc64le-musl)
	distfiles="https://alpha.de.repo.voidlinux.org/distfiles/ghc-${version}-powerpc64le-void-linux-musl.tar.xz"
	checksum=37de8e069712307c9b2039e92f56e540e80ca1390dd27aa247ebe18c40e0c629
	;;
ppc64)
	distfiles="https://alpha.de.repo.voidlinux.org/distfiles/ghc-${version}-powerpc64-void-linux.tar.xz"
	checksum=6eb8684fdbede0cded7e3f7b93574b968f5f66dd2fcd4ec30ac5f0c402af6602
	;;
aarch64)
	distfiles="https://alpha.de.repo.voidlinux.org/distfiles/ghc-${version}-aarch64-void-linux.tar.xz"
	checksum=44a20a896246dce64392b7d0feedd0a28a9d733245a803e95dbe4b4b7e15b4fd
	depends+=" llvm"
	;;
aarch64-musl)
	distfiles="https://alpha.de.repo.voidlinux.org/distfiles/ghc-${version}-aarch64-void-linux-musl.tar.xz"
	checksum=de98e2ff33a25cb32a28c738066fecacb736a33cac12688876eec4eb96d88607
	depends+=" llvm"
	;;
*)
	broken="No distfiles available for this target"
	;;
esac

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

do_install() {
	ln -sf /usr/lib/libncursesw.so.6 libtinfo.so.5
	export LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH

	make install DESTDIR="$DESTDIR"

	# Fake libtinfo into rpath of ghc:
	ln -sf /usr/lib/libncursesw.so.6 \
		$DESTDIR/usr/lib/ghc-${version%[!0-9]}/rts/libtinfo.so.5
	vlicense LICENSE
}
