# $Id: Portfile,v 1.10 2006/02/23 21:58:53 gwright Exp $

PortSystem 1.0
name		ghc-devel
version		6.5
revision	3
categories	lang
maintainers	gwright@opendarwin.org
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/

set worksrcdir	ghc

fetch		{ cd ${workpath}
		  system "darcs get --partial ${darcs_site}ghc"

		  cd ${worksrcdir}
		  system "chmod +x ./darcs-all"
		  system "./darcs-all get"
}

variant test	{ ui_msg "testsuite and nofib benchmarks will be built" }

post-fetch	{ cd ${worksrcpath}
		  if { [variant_isset test] } {
		  	system "darcs get --partial ${darcs_site}testsuite"
			system "darcs get --partial ${darcs_site}nofib"
		  }

		  system "./darcs-all pull -a"
		}

extract		{ }
checksum	{ }

depends_build	port:ghc	\
		port:alex	\
		port:darcs	\
		port:happy

depends_lib	port:readline	\
		port:gmp

#user_notes	All of the executables have the version as a suffix,	\
#		so you must invoke ghc-6.5 or ghci-6.5 or hsc2hs-6.5...	\
#		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.


platform darwin i386 {
		ui_msg "ghc-devel is not supported on OS X i386 yet"
		exit 1
}

platform darwin 6 {
		ui_msg "ghc-devel is not supported on Jaguar (OS X 10.2.x)"
		exit 1
}

platform darwin 7 {
                depends_build-append	path:${prefix}/bin/gmake:gmake

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

			cd ${worksrcpath}
			system "autoreconf"
		}

                build.cmd       gmake
        }


platform darwin 8 {
		patchfiles-append	patch-GC.c

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

			cd ${worksrcpath}
			system "autoreconf"
		}
}

configure.env	LDFLAGS="-L${prefix}/lib"	\
		CPPFLAGS="-I${prefix}/include"	\
		CFLAGS="-I${prefix}/include"

configure.args	--prefix=${destroot}/${prefix}			\
		--mandir=${destroot}/${prefix}/share/man/

variant noopengl	{ configure.args-append --disable-hopengl }

post-destroot	{ foreach script_name { ghc ghci ghc-pkg } {
			reinplace s|${destroot}/${prefix}|${prefix}|g ${destroot}/${prefix}/bin/${script_name}-${version}
		  }

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

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

                  reinplace s|${destroot}/${prefix}|${prefix}|g ${destroot}/${prefix}/lib/ghc-${version}/package.conf

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

		  foreach bin_name {ghcprof hasktags hp2ps hsc2hs runghc runhaskell stat2resid} {
			file rename ${destroot}/${prefix}/bin/${bin_name} ${destroot}/${prefix}/bin/${bin_name}-${version}
		  }

		  cd ${destroot}/${prefix}/lib/ghc-${version}
		  system "ranlib *.a"
}

