# Template file for 'cabal-install'
pkgname=cabal-install
version=3.10.3.0
revision=1
build_helper="haskell"
hostmakedepends="python3 ghc curl tar"
makedepends="zlib-devel"
depends="ghc"
short_desc="Command-line interface for Cabal and Hackage"
maintainer="Orphaned <orphan@voidlinux.org>"
license="BSD-3-Clause"
homepage="https://www.haskell.org/cabal/"
distfiles="https://github.com/haskell/cabal/archive/refs/tags/cabal-install-v${version}.tar.gz"
checksum=075fba81fca61f6957dae3a542a3213415682dd9767f6ccdf3f9059f2cd0f156
nopie_files="/usr/bin/cabal"
nocross=yes

# Keep in sync with ghc
_ghc_ver=9.8.4

post_extract() {
	if [ -e ${FILESDIR}/linux-${_ghc_ver}.json ]; then
		cp "${FILESDIR}/linux-${_ghc_ver}.json" bootstrap/
	fi
}

pre_build() {
	if [ -e bootstrap/linux-${_ghc_ver}.json ]; then
		if [ "$XBPS_TARGET_WORDSIZE" = 32 ]; then
			# https://github.com/haskell/cabal/issues/7313
			sed -i 's/+ofd-locking/-ofd-locking/g' bootstrap/linux-${_ghc_ver}.json
		fi
	else
		# To generate a bootstrap plan for a new ghc version ensure a
		# cabal binary is available, run this, then move the plan to
		# FILESDIR
		cabal update
		make bootstrap-json-${_ghc_ver}
		msg_normal "Please install bootstrap/linux-${_ghc_ver}.json in ${FILESDIR}\n"
		exit 1
	fi
}

do_build() {
	PREFIX=$PWD bootstrap/bootstrap.py -d bootstrap/linux-${_ghc_ver}.json
}

do_install() {
	vbin _build/bin/cabal
	PREFIX=$PWD _build/bin/cabal man --raw > cabal.1
	vman cabal.1
	vlicense LICENSE
}
