#Packager: Tim Beech <tim~dot~beech~AT~gmail~dot~com>
#with acknowledgement to Jonathan Lahav's Arch Linux package
#an old version of gmp is needed, also possibly libffi

pkgname=ghc
pkgver=7.6.3
pkgrel=1tjb
#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=("build.mk" "http://ftp.gnu.org/gnu/gmp/gmp-4.3.2.tar.bz2" "http://www.haskell.org/ghc/dist/${pkgver}/ghc-${pkgver}-$tararch-unknown-linux.tar.bz2" "http://ltsp.mirrors.tds.net/pub/sourceware.org/libffi/libffi-3.0.10.tar.gz")
sourcetemplate=http://people.salixos.org/mimosa/packages/$pkgname/$pkgver/
docs=("readme" "install" "copying" "changelog" "authors" "news" "todo")
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}
	cp -P ./.libs/libgmp.so.3* $startdir/pkg/usr/lib${LIBDIRSUFFIX} 
	#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 itself
	cp $startdir/src/build.mk $startdir/src/$pkgname-$pkgver/mk/ #the Arch package provides this build.mk
	cd $startdir/src/$pkgname-$pkgver                            #possibly just to reflect the original build
	./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##these seem to be needed at runtime, not just build deps; so could be inconvenient to remove them
	#rm /usr/lib${LIBDIRSUFFIX}/libgmp.so.3*
	#rm /usr/lib${LIBDIRSUFFIX}/libffi.so.5*
} 

