# Compiling Time: 30.17 SBU
# Maintainer: dex77 <dex77@frugalware.org>

pkgname=ghc
pkgver=9.0.1
_bootstrapver=8.8.4
_dist=fedora27
pkgrel=2
pkgdesc="The Glasgow Haskell Compiler"
url="https://www.haskell.org/ghc/"
depends=('gmp>=5.0.1' 'readline>=7.0-2' 'ncurses>=6.1-7' 'libedit>=20150325_3.1-3' 'libffi>=3.4')
groups=('devel-extra')
archs=('x86_64')
_F_archive_grepv="rc\|alpha\|beta"
options=('noextract' 'nolto')
up2date="Flastverdir http://downloads.haskell.org/~ghc/"
source=($url/dist/$pkgver/$pkgname-$pkgver-src.tar.xz \
	https://downloads.haskell.org/~ghc/${_bootstrapver}/ghc-${_bootstrapver}-x86_64-${_dist}-linux.tar.xz \
	autotools-fixes1.patch \
	autotools-fixes2.patch )
signatures=("${source[0]}.sig" "${source[1]}.sig" '' '')
options=('noclash')

subpkgs=("$pkgname-docs")
subdescs=("GHC HTML documentation..")
subgroups=('devel-extra')
subdepends=('')
subrodepends=("ghc")
subarchs=('x86_64')

replaces=('haskell-xhtml'
	'haskell-array'
	'haskell-binary'
	'haskell-containers'
	'haskell-deepseq'
	'haskell-haskeline'
	'haskell-terminfo'
	'haskell-transformers'
	'haskell-text'
	'haskell-mtl'
	'haskell-parsec')
conflicts=("${replaces[@]}")
provides=("${provides[@]}")
_Fbuild_no_patch="yes"
Fbuildchost="x86_64-unknown-linux"

build()
{
	export LANG=en_US.UTF-8

	Fexec cd $Fsrcdir || Fdie
	Fexec rm -rf $pkgname-$pkgver || Fdie
	Fextract $pkgname-$pkgver-src.tar.xz || Fdie
	Fexec mkdir -p temp-ghc-bootstrap || Fdie
	Fexec tar -C temp-ghc-bootstrap -xvf ghc-${_bootstrapver}-x86_64-${_dist}-linux.tar.xz || Fdie

	# install binary dist
	Fexec cd "$Fsrcdir/temp-ghc-bootstrap/ghc-${_bootstrapver}" || Fdie
	Fexec ./configure --prefix="$Fsrcdir/bootstrap" || Fdie
	Fexec make install || Fdie


	export LD=/usr/bin/ld
	Fexec cd "$Fsrcdir/$pkgname-$pkgver" || Fdie
	Fpatchall

	Fexec ./boot || Fdie
	Fbuild	--with-system-libffi \
		fp_prog_ar=/usr/bin/ar \
		GHC="$Fsrcdir/bootstrap/bin/ghc" \
		--with-ffi-includes="$(pkg-config --variable=includedir libffi)"

	Fmkdir etc/ld.so.conf.d/

	Fexec cd $Fdestdir || Fdie

	local i
	for i in $(find usr/lib -name "*.so*" -exec dirname {} \; | sort -u);
	do
		Fexec echo "/${i}" >> "$Fdestdir/etc/ld.so.conf.d/ghc.conf" || Fdie

	done

	Fsplit $pkgname-docs usr/share/doc/ghc-$pkgver

}

# optimization OK
