#Packager: Tim Beech <tim ~dot~beech~at~gmail~dot~com>
#See the GHC website for build info. In brief, you need GHC
#to build GHC. That means first installing a binary distribution.
#Note this requires an old gmp (libgmp-4.3.2) to build and 
#run; the same problem with libffi. This SLKBUILD builds them
#and unpacks the binary GHC.
pkgname=ghc
pkgver=7.4.2
pkgrel=2tjb
#arch=noarch
#choose which source tarball we want to fit the architecture
case "$( uname -m )" in
	i?86) tararch=i386 ;;
	x86_64) tararch=x86_64 ;;
	*) tararch=$( uname -m ) ;;
esac
source=("http://ftp.gnu.org/gnu/gmp/gmp-4.3.2.tar.bz2" "http://ltsp.mirrors.tds.net/pub/sourceware.org/libffi/libffi-3.0.10.tar.gz" "http://www.haskell.org/ghc/dist/7.4.2/ghc-7.4.2-$tararch-unknown-linux.tar.bz2")
sourcetemplate=http://people.salixos.org/mimosa/packages/$pkgname/$pkgver/
docs=("announce" "readme" "install" "copying" "changelog" "authors" "news" "todo" "license" "hacking" "version")
url=www.haskell.org
#dotnew=()
#CFLAGS=
#CXXFLAGS=
#options=('noextract')

#doinst() {
#ghc-pkg recache
#}

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"ghc (the Gasgow Haskell Compiler)"
"GHC is an open source compiler and interactive environment for"
"the pure functional language Haskell. Profiling libraries and"
"documentation are included. If you have installed this GHC as an" 
"upgrade, you may need to unregister and reinstall cabalised packages."
""
"Homepage: http://haskell.org/ghc/"
)


build() {
	#build old version of libgmp 
	cd $startdir/src/gmp-4.3.2
	./configure --with-gnu-ld --enable-cxx --enable-mpbsd --build=$arch-slackware-linux
	make
	mkdir -p $startdir/pkg/usr/lib${LIBDIRSUFFIX}
	cp -P ./.libs/libgmp.so.3* /usr/lib${LIBDIRSUFFIX} # both these and libffi files are actually needed on the build system
	cp -P ./.libs/libgmp.so.3* $startdir/pkg/usr/lib${LIBDIRSUFFIX} # also needed in the package to run
	#build old version of libffi
	cd $startdir/src/libffi-3.0.10
	./configure && make
	mkdir -p $startdir/pkg/usr/lib${LIBDIRSUFFIX}
	cp -P ./*linux-gnu/.libs/libffi.so.5* /usr/lib${LIBDIRSUFFIX} # we need to be root to put them there (no fakeroot)
	cp -P ./*linux-gnu/.libs/libffi.so.5* $startdir/pkg/usr/lib${LIBDIRSUFFIX}
	#unpack ghc binary distribution
	cd $startdir/src/$pkgname-$pkgver
	./configure --prefix=/usr --libdir=/usr/lib${LIBDIRSUFFIX} --mandir=/usr/man --docdir=/usr/doc/$pkgname-$pkgver
	make install DESTDIR=$startdir/pkg
	#docs housekeeping
	chmod -R go-w $startdir/pkg/usr/doc
	#clean up
	rm /usr/lib${LIBDIRSUFFIX}/libgmp.so.3*
	rm /usr/lib${LIBDIRSUFFIX}/libffi.so.5*
} 
