# $Id: Portfile 71533 2010-09-15 20:26:12Z ryandesign@macports.org $

PortSystem 1.0

name		ghc-devel
version		6.11
categories	lang
maintainers	gwright
platforms	darwin
description	The Glorious Glasgow Haskell Compilation System (development version)
long_description	\
		The Glasgow Haskell Compiler is a robust,		\
		fully-featured, optimising compiler and interactive	\
		environment for Haskell 98, GHC compiles Haskell to	\
		either native code or C.  It implements numerous	\
		experimental language extensions to Haskell 98,		\
		for example: concurrency, a foreign language interface,	\
		multi-parameter type classes, scoped type variables,	\
		existential and universal quantification, unboxed	\
		types, exceptions, weak pointers, and so on.		\
		GHC comes with a generational garbage collector,	\
		and a space and time profiler. 

homepage	http://www.haskell.org/ghc/
set darcs_site	http://darcs.haskell.org/

# Fetch using git is not yet supported in the released version
# of MacPorts (requires 1.7).
#
#fetch.type	git
#git.url	http://darcs.haskell.org/ghc.git

set worksrcdir	ghc

pre-fetch {
         return -code error "ghc-devel is not currently supported"
}

fetch		{
		  system "cd ${workpath} && git clone ${darcs_site}/ghc.git"
}
 
variant test description {build testsuite and nofb benchmarks} {
	 ui_msg "testsuite and nofib benchmarks will be built"
}

post-fetch	{
		  system "cd ${worksrcpath} && chmod +x ./sync-all"
		  system "cd ${worksrcpath} && ./sync-all get"
		  system "cd ${worksrcpath} && ./sync-all --extralibs get"

		  if { [variant_isset test] } {
		  	system "cd ${worksrcpath} && ./sync-all --testsuite get"
			system "cd ${worksrcpath} && ./sync-all --nofib get"
		  }
		}

extract		{ }
checksum	{ }

depends_build	port:ghc	\
		port:hs-platform-alex	\
		port:hs-platform-happy	\
		port:git-core

depends_lib	port:libedit	\
		port:gmp

#user_notes	All of the executables have the version as a suffix,	\
#		so you must invoke ghc-6.9 or ghci-6.9 or hsc2hs-6.9...	\
#		Not all of the files in /bin are different from the	\
#		production version, but it seems safer not to overwrite	\
#		the versions that are officially supported.

#bugs		GHC does not support DESTDIR. Instead, we install	\
#		everything into ${destroot}${prefix}, and then fix up	\
#		the five scripts which actually have the installation	\
#		path hard coded.

post-patch	{
		system "touch ${worksrcpath}/libraries/base3-compat/LICENSE"
}

pre-configure   {
		set cfg [open "${worksrcpath}/mk/build.mk" w]
		puts $cfg "#"
		puts $cfg "# Local configuration overrides for MacPorts"
		puts $cfg "#"
		puts $cfg "SRC_CC_OPTS += -I${prefix}/include"
		puts $cfg "SRC_HC_OPTS += -I${prefix}/include -I/usr/include -L${prefix}/lib -L/usr/lib"
		puts $cfg "EXTRA_HSC2HS_OPTS += -I${prefix}/include"
		puts $cfg "EXTRA_LD_OPTS += -L${prefix}/lib"
		puts $cfg "EXTRA_LD_OPTS += -L/usr/lib"
		close $cfg

		system "cd ${worksrcpath} && sh boot"
}


configure.env	DYLD_FALLBACK_LIBRARY_PATH=${prefix}/lib
configure.cflags-append	"-I${prefix}/include"

configure.args	--prefix=${destroot}${prefix}			\
		--mandir=${destroot}${prefix}/share/man/	\
		--with-readline-includes=${prefix}/include	\
		--with-readline-libraries=${prefix}/lib		\
		--with-gmp-includes=${prefix}/include		\
		--with-gmp-libraries=${prefix}/lib		\
		--disable-openal				\
		--disable-alut

variant no_opengl	{
		configure.args-append --disable-opengl
		configure.args-append --disable-glut
}

build.env	DYLD_FALLBACK_LIBRARY_PATH=${prefix}/lib

post-destroot	{ cd ${destroot}${prefix}/bin
		  set ghc_script     [ glob ${destroot}${prefix}/bin/ghc-${version}.* ]
		  set ghci_script    [ glob ${destroot}${prefix}/bin/ghci-${version}.* ]
		  set ghc-pkg_script [ glob ${destroot}${prefix}/bin/ghc-pkg-${version}.* ]

		  foreach script_name [concat ${ghc_script} ${ghci_script} ${ghc-pkg_script} ] {
			reinplace s|${destroot}${prefix}|${prefix}|g ${destroot}${prefix}/bin/${script_name}
		  }

		  foreach script_name { ghcprof hsc2hs-ghc } {
			reinplace s|${destroot}${prefix}|${prefix}|g ${destroot}${prefix}/bin/${script_name}
		  }

		  reinplace "s|\\\$@\"\}|\\\$@\"\} -L${prefix}/lib -I${prefix}/include |" ${destroot}${prefix}/bin/ghc

		  set ghc_libdir [ glob ${destroot}${prefix}/bin/ghc-${version}.* ]
                  reinplace s|${destroot}${prefix}|${prefix}|g ${destroot}${prefix}/lib/${ghc_libdir}/package.conf

		  file delete ${destroot}${prefix}/bin/ghc
		  file delete ${destroot}${prefix}/bin/ghci
		  file delete ${destroot}${prefix}/bin/ghc-pkg

		  set ghc_date [ lindex [ split ${ghc_libdir} "." ] 2 ]

		  foreach bin_name { ghcprof hasktags hp2ps hsc2hs-ghc runghc } {
			file rename ${destroot}${prefix}/bin/${bin_name} ${destroot}${prefix}/bin/${bin_name}-${version}.${ghc_date}
		  }

		  system "cd ${destroot}${prefix}/lib/${ghc_libdir} && ranlib *.a"
}

