Index: Portfile
===================================================================
--- Portfile	(revision 32681)
+++ Portfile	(working copy)
@@ -2,7 +2,7 @@
 
 PortSystem 1.0
 name		ghc
-version		6.6.1
+version		6.8.2
 categories	lang
 maintainers	gwright@macports.org
 platforms	darwin
@@ -28,12 +28,12 @@
 distfiles	${name}-${version}-src.tar.bz2		\
 		${name}-${version}-src-extralibs.tar.bz2
 
-checksums	${name}-${version}-src.tar.bz2			md5 ba9f4aec2fde5ff1e1548ae69b78aeb0 \
-		${name}-${version}-src-extralibs.tar.bz2	md5 43a26b81608b206c056adc3032f7da2a
+checksums	${name}-${version}-src.tar.bz2			md5 43108417594be7eba0918c459e871e40 \
+		${name}-${version}-src-extralibs.tar.bz2	md5 d199c50814188fb77355d41058b8613c
 
-patchfiles	patch-configure.ac	\
-		patch-GHC.hs		\
-		patch-package.conf.in
+patchfiles	patch-Install.hs \
+        patch-configure.ac
+#		patch-package.conf.in
 
 depends_lib	port:readline \
 		port:gmp
@@ -74,36 +74,6 @@
 
 		depends_lib-append	port:readline-5
 
-		pre-configure	{
-			cd ${worksrcpath}
-			system "autoreconf"
-
-			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
-
-			reinplace "s|/opt/local|${workpath}/ghc-bootstrap|g" ${workpath}/ghc-bootstrap/lib/ghc-${ghc_bootversion}/package.conf
-
-			reinplace "s|GHCBIN=\"/opt/local|GHCBIN=\"${workpath}/${name}-bootstrap|" ${workpath}/${name}-bootstrap/bin/ghc
-
-			reinplace "s|TOPDIROPT=\"-B/opt/local|TOPDIROPT=\"-B${workpath}/${name}-bootstrap|" ${workpath}/${name}-bootstrap/bin/ghc
-
-			reinplace "s|-L/opt/local|-L${prefix}|" ${workpath}/${name}-bootstrap/bin/ghc
-
-			reinplace "s|-I/opt/local|-I${prefix}|" ${workpath}/${name}-bootstrap/bin/ghc
-
-		  	reinplace "s|/opt/local|${prefix}|" ${workpath}/${name}-bootstrap/lib/ghc-${ghc_bootversion}/ghc-asm
-
-		  	reinplace "s|/opt/local|${prefix}|" ${workpath}/${name}-bootstrap/lib/ghc-${ghc_bootversion}/ghc-split
-		}
-
 		configure.args-append --with-ghc='${workpath}/${name}-bootstrap/bin/ghc'
 		build.cmd	gmake
 	}
@@ -123,36 +93,6 @@
 					${name}-${version}-src-extralibs.tar.bz2 \
 					${name}-${ghc_bootversion}-darwin-bootstrap-tiger.tar.bz2
 
-		pre-configure	{
-			cd ${worksrcpath}
-			system "autoreconf"
-
-			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
-
-			reinplace "s|/opt/local|${workpath}/ghc-bootstrap|g" ${workpath}/ghc-bootstrap/lib/ghc-${ghc_bootversion}/package.conf
-
-			reinplace "s|GHCBIN=\"/opt/local|GHCBIN=\"${workpath}/${name}-bootstrap|" ${workpath}/${name}-bootstrap/bin/ghc
-
-			reinplace "s|TOPDIROPT=\"-B/opt/local|TOPDIROPT=\"-B${workpath}/${name}-bootstrap|" ${workpath}/${name}-bootstrap/bin/ghc
-
-			reinplace "s|-L/opt/local|-L${prefix}|" ${workpath}/${name}-bootstrap/bin/ghc
-
-			reinplace "s|-I/opt/local|-I${prefix}|" ${workpath}/${name}-bootstrap/bin/ghc
-
-		  	reinplace "s|/opt/local|${prefix}|" ${workpath}/${name}-bootstrap/lib/ghc-${ghc_bootversion}/ghc-asm
-
-		  	reinplace "s|/opt/local|${prefix}|" ${workpath}/${name}-bootstrap/lib/ghc-${ghc_bootversion}/ghc-split
-		}
-
 		configure.args-append --with-ghc='${workpath}/${name}-bootstrap/bin/ghc'
 	}
 
@@ -171,53 +111,79 @@
 					${name}-${version}-src-extralibs.tar.bz2 \
 					${name}-${ghc_bootversion}-i386-apple-darwin-bootstrap.tar.bz2
 
-		pre-configure	{
-			cd ${worksrcpath}
-			system "autoreconf"
+		configure.args-append --with-ghc='${workpath}/${name}-bootstrap/bin/ghc'
+	}
 
-			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
+platform darwin 9 i386 {
+		global ghc_bootversion
+		set ghc_bootversion	6.8.2
 
-			reinplace "s|/opt/local|${workpath}/ghc-bootstrap|g" ${workpath}/ghc-bootstrap/lib/ghc-${ghc_bootversion}/package.conf
+		master_sites-append	${homepage}/dist/${ghc_bootversion}/:bootstrap
 
-			reinplace "s|GHCBIN=\"/opt/local|GHCBIN=\"${workpath}/${name}-bootstrap|" ${workpath}/${name}-bootstrap/bin/ghc
+		distfiles-append	${name}-${ghc_bootversion}-darwin-i386-leopard-bootstrap.tar.bz2:bootstrap
 
-			reinplace "s|TOPDIROPT=\"-B/opt/local|TOPDIROPT=\"-B${workpath}/${name}-bootstrap|" ${workpath}/${name}-bootstrap/bin/ghc
+		checksums-append	${name}-${ghc_bootversion}-darwin-i386-leopard-bootstrap.tar.bz2 md5 735a6dca41f36044199784d5bd1ece69
 
-			reinplace "s|-L/opt/local|-L${prefix}|" ${workpath}/${name}-bootstrap/bin/ghc
+		extract.only		${name}-${version}-src.tar.bz2 \
+					       ${name}-${version}-src-extralibs.tar.bz2 \
+					       ${name}-${ghc_bootversion}-darwin-i386-leopard-bootstrap.tar.bz2
 
-			reinplace "s|-I/opt/local|-I${prefix}|" ${workpath}/${name}-bootstrap/bin/ghc
+		configure.args-append --with-ghc='${workpath}/${name}-bootstrap/bin/ghc'
+	}
 
-		  	reinplace "s|/opt/local|${prefix}|" ${workpath}/${name}-bootstrap/lib/ghc-${ghc_bootversion}/ghc-asm
+pre-configure	{
+	system "cd ${worksrcpath} && autoreconf"
 
-		  	reinplace "s|/opt/local|${prefix}|" ${workpath}/${name}-bootstrap/lib/ghc-${ghc_bootversion}/ghc-split
-		}
+	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"
+	puts $cfg "CPPFLAGS += -I${prefix}/include"
+	puts $cfg "LDFLAGS += -L${prefix}/lib"
+	close $cfg
 
-		configure.args-append --with-ghc='${workpath}/${name}-bootstrap/bin/ghc'
-	}
+    # Prepare bootstrap compiler for use in building current GHC
+	reinplace "s|/opt/local|${workpath}/ghc-bootstrap|g" ${workpath}/${name}-bootstrap/lib/ghc-${ghc_bootversion}/package.conf
+	reinplace "s|GHCBIN=/opt/local\\(.*\\)|GHCBIN=${workpath}/${name}-bootstrap\\1|" ${workpath}/${name}-bootstrap/bin/ghc
+	reinplace "s|TOPDIROPT=-B/opt/local\\(.*\\)|TOPDIROPT=-B${workpath}/${name}-bootstrap\\1|" ${workpath}/${name}-bootstrap/bin/ghc
+	reinplace "s|-L/opt/local\\(.*\\)|-L${prefix}\\1|" ${workpath}/${name}-bootstrap/bin/ghc
+	reinplace "s|-I/opt/local\\(.*\\)|-I${prefix}\\1|" ${workpath}/${name}-bootstrap/bin/ghc
+	reinplace "s|/opt/local|${prefix}|" ${workpath}/${name}-bootstrap/lib/ghc-${ghc_bootversion}/ghc-asm
+	reinplace "s|/opt/local|${prefix}|" ${workpath}/${name}-bootstrap/lib/ghc-${ghc_bootversion}/ghc-split
 
+	# Deal with GMP
+	reinplace "s|GHC_CC_OPTS += \\(.*\\)|GHC_CC_OPTS += ${prefix}/include \\1|" ${worksrcpath}/libraries/Cabal/Distribution/Simple/GHC/Makefile.in
+	system "ln -sf ${prefix}/include/gmp.h ${worksrcpath}/libraries/base/include"
+	system "ln -sf ${prefix}/include/gmpxx.h ${worksrcpath}/libraries/base/include"
+	system "ln -sf ${prefix}/include/gmp.h ${worksrcpath}/includes"
+	system "ln -sf ${prefix}/include/gmpxx.h ${worksrcpath}/includes"
 
+	reinplace "s|\\(SUBDIRS += \$\(wildcard OpenAL\).*\\)|#\\1|" ${worksrcpath}/libraries/Makefile
+}
+
+
+
 #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.
 
-configure.ldflags-append	"-L/usr/lib"
+configure.ldflags-append	"-L/usr/lib -L${prefix}/lib"
 configure.cflags-append		"-I${prefix}/include"
-configure.env		DYLD_FALLBACK_LIBRARY_PATH=${prefix}/lib
+configure.env		DYLD_FALLBACK_LIBRARY_PATH=${prefix}/lib \
+                    CFLAGS=-I${prefix}/include
 
-configure.args	--prefix=${destroot}/${prefix}			\
-		--mandir=${destroot}/${prefix}/share/man/	\
+configure.args	--prefix=${destroot}${prefix}			\
+		--mandir=${destroot}${prefix}/share/man/	\
 		--with-readline-includes=${prefix}/include	\
 		--with-readline-libraries=${prefix}/lib		\
+		--with-gmp-libraries=${prefix}/lib \
+		--with-gmp-includes=${prefix}/include \
 		--disable-openal				\
 		--disable-alut
 
@@ -227,23 +193,24 @@
 	system "env DYLD_FALLBACK_LIBRARY_PATH=${prefix}/lib ${build.cmd} ${build.target}"
 }
 
+destroot {
+	system "${build.cmd} install"
+}
 
-
 # Note the middle "/" in the ${destroot}/${prefix} pattern. It is required,
 # because the actual text we are trying to match has a "//" between the
 # destroot and the prefix pieces.
 
 post-destroot	{
-	reinplace s|${destroot}/${prefix}|${prefix}|g ${destroot}/${prefix}/bin/ghc
-	reinplace s|${destroot}/${prefix}|${prefix}|g ${destroot}/${prefix}/bin/ghci
-	reinplace s|${destroot}/${prefix}|${prefix}|g ${destroot}/${prefix}/bin/ghc-pkg
-	reinplace s|${destroot}/${prefix}|${prefix}|g ${destroot}/${prefix}/bin/ghcprof
-	reinplace s|${destroot}/${prefix}|${prefix}|g ${destroot}/${prefix}/bin/hsc2hs
+	reinplace s|${destroot}${prefix}|${prefix}|g ${destroot}/${prefix}/bin/ghc
+	reinplace s|${destroot}${prefix}|${prefix}|g ${destroot}/${prefix}/bin/ghci
+	reinplace s|${destroot}${prefix}|${prefix}|g ${destroot}/${prefix}/bin/ghc-pkg
+	reinplace s|${destroot}${prefix}|${prefix}|g ${destroot}/${prefix}/bin/ghcprof
+	reinplace s|${destroot}${prefix}|${prefix}|g ${destroot}/${prefix}/bin/hsc2hs
 
 	reinplace "s|\\\$@\"\}|\\\$@\"\} -L${prefix}/lib -I${prefix}/include |" ${destroot}/${prefix}/bin/ghc
 
-	reinplace s|${destroot}/${prefix}|${prefix}|g ${destroot}${prefix}/lib/${name}-${version}/package.conf
+	reinplace s|${destroot}${prefix}|${prefix}|g ${destroot}${prefix}/lib/${name}-${version}/package.conf
 
-	cd ${destroot}${prefix}/lib/ghc-${version}
-        system "ranlib *.a"
+	system "cd ${destroot}${prefix}/lib/ghc-${version} && ranlib *.a"
 }

