This patch essentially changes the overall sequence of the 6.10.X makefiles to
make it compile in two stages with some resemblance to the original.  Stage 1
is the cross compiler.  Stage 2 is the libraries and everything else.

This is a brittle change to a make system that had become messy over the years.
The GHC make system has since been re-written, so these change will need to be
completely re-written in GHC HEAD.

--- ghc-6.10.2.orig/Makefile	2009-03-31 06:13:16.000000000 +1300
+++ ghc-6.10.2/Makefile	2009-06-18 15:54:37.000000000 +1200
@@ -72,7 +72,10 @@
 SUBDIRS_BUILD = includes utils driver docs compiler libraries/Cabal/doc
 endif
 
-SUBDIRS = gmp libffi includes utils docs rts compiler ghc driver libraries libraries/Cabal/doc
+# Cross compile: The only things from 'utils' we want are haddock, ghc-pkg & unlit
+SUBDIRS_STAGE1 = gmp libffi includes utils/haddock utils/ghc-pkg utils/unlit docs rts compiler ghc libraries \
+    libraries/Cabal/doc cabal-install/cabal-install
+SUBDIRS_STAGE2 = driver/ghc driver/ghc-pkg
 
 check-all: check-packages check-tools
 
@@ -140,6 +143,12 @@
 	$(MAKE) -C rts boot
 	$(MAKE) -C rts
 	$(MAKE) -C libraries all
+	# Cross-compile: Build some stuff in stage 1 that normally gets built in
+	# stage 2 because we want it on the build host, not the target.
+	$(MAKE) -C utils/haddock
+	$(MAKE) -C cabal-install/zlib
+	$(MAKE) -C cabal-install/HTTP
+	$(MAKE) -C cabal-install/cabal-install
 
 # When making distributions (i.e., whether with binary-dist or using the 
 # vanilla install target to create an installer package), we can have problems
@@ -150,11 +159,17 @@
 # includes in binary dists.
 stage2 : check-all
 	$(MAKE) -C compiler stage=2 boot
-	$(MAKE) -C compiler stage=2
-	$(MAKE) -C utils with-stage-2
+	# Cross compile: We don't actually build the compiler in stage 2.
+	#$(MAKE) -C compiler stage=2
+
+	# Cross compile: We only need a selection of the utils in 'utils' built for the target
+	#$(MAKE) -C utils with-stage-2  
+	# Build ghc-pkg in stage 2 because it needs different default directories
+	# to the one we built in stage 1.  (The makefile forces it to be built for the build host.)
+	$(MAKE) -C utils/ghc-pkg with-stage-2
 ifeq "$(HADDOCK_DOCS)" "YES"
-	$(MAKE) -C libraries doc
-	$(MAKE) -C compiler  doc stage=2
+	#$(MAKE) -C libraries doc   # TO DO - fix the docs
+	#$(MAKE) -C compiler  doc stage=2
 endif
 
 stage3 : check-all
@@ -196,14 +211,6 @@
 # -----------------------------------------------------------------------------
 # Installing
 
-# We want to install the stage 2 bootstrapped compiler by default, but we let
-# the user override this by saying 'make install stage=1', for example.
-ifeq "$(stage)" ""
-INSTALL_STAGE = stage=2
-else
-INSTALL_STAGE =
-endif
-
 install-strip:
 	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
 
@@ -212,12 +219,21 @@
 	$(MKDIRHIER) $(DESTDIR)$(datadir)
 	echo "[]" > $(DESTDIR)$(datadir)/package.conf
 	@case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
-	for i in $(SUBDIRS); do \
+	for i in $(SUBDIRS_STAGE1); do \
 	  echo "------------------------------------------------------------------------"; \
-	  echo "== $(MAKE) $@ $(MFLAGS);"; \
+	  echo "== $(MAKE) $@ stage=1 $(MFLAGS);"; \
+	  echo " in $(shell pwd)/$$i"; \
+	  echo "------------------------------------------------------------------------"; \
+	  $(MAKE) --no-print-directory -C $$i stage=1 $(MFLAGS) $@; \
+	  if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ;  then true; else exit 1; fi; \
+	done
+	@case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
+	for i in $(SUBDIRS_STAGE2); do \
+	  echo "------------------------------------------------------------------------"; \
+	  echo "== $(MAKE) $@ stage=2 $(MFLAGS);"; \
 	  echo " in $(shell pwd)/$$i"; \
 	  echo "------------------------------------------------------------------------"; \
-	  $(MAKE) --no-print-directory -C $$i $(INSTALL_STAGE) $(MFLAGS) $@; \
+	  $(MAKE) --no-print-directory -C $$i stage=2 $(MFLAGS) $@; \
 	  if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ;  then true; else exit 1; fi; \
 	done
 
@@ -264,7 +280,7 @@
 	  echo "== $(MAKE) $@ $(MFLAGS);"; \
 	  echo " in $(shell pwd)/$$i"; \
 	  echo "------------------------------------------------------------------------"; \
-	  $(MAKE) --no-print-directory -C $$i $(INSTALL_STAGE) $(MFLAGS) $@; \
+	  $(MAKE) --no-print-directory -C $$i stage=1 $(MFLAGS) $@; \
 	  if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ;  then true; else exit 1; fi; \
 	done
 
--- ghc-6.10.2.orig/mk/build.mk	1970-01-01 12:00:00.000000000 +1200
+++ ghc-6.10.2/mk/build.mk	2009-06-18 15:54:37.000000000 +1200
@@ -0,0 +1,14 @@
+#SRC_HC_OPTS     = -opta -m32 -optc -m32 -optl -m32
+GhcStage1HcOpts = -O2
+GhcLibHcOpts    = -O -fgenerics
+GhcLibWays      = v p
+GhcBootLibs     = NO
+GhcUnregisterised=YES
+GhcWithNativeCodeGen=NO
+GhcWithInterpreter=NO
+SplitObjs=NO
+UseLibFFIForAdjustors=NO
+GhcRTSWays := p thr thr_p
+GhcNotThreaded=NO
+
+#GhcRtsHcOpts=-optc-DDEBUG
--- ghc-6.10.2.orig/mk/config.mk.in	2009-03-31 06:13:16.000000000 +1300
+++ ghc-6.10.2/mk/config.mk.in	2009-06-18 15:54:37.000000000 +1200
@@ -56,7 +56,7 @@
 # random .o-file stuff might change even if the .hi syntax doesn't
 
 ProjectName       = @ProjectName@
-ProjectTags       =
+ProjectTags       = @TOOLCHAIN_VERSION_TAGS@
 ProjectVersion    = @ProjectVersion@$(ProjectTags)
 ProjectVersionInt = @ProjectVersionInt@
 ProjectPatchLevel = @ProjectPatchLevel@
@@ -637,7 +637,7 @@
 #pdfdir    := @pdfdir@
 #psdir     := @psdir@
 
-docdir    := $(datarootdir)/doc/ghc
+docdir    := $(datarootdir)/doc/ghc-$(ProjectVersion)
 htmldir   := $(docdir)
 dvidir    := $(docdir)
 pdfdir    := $(docdir)
@@ -903,8 +903,8 @@
 
 GHC_INPLACE = $(GHC_STAGE1)
 GHC_STAGE1  = $(GHC_COMPILER_DIR_ABS)/stage1-inplace/ghc
-GHC_STAGE2  = $(GHC_COMPILER_DIR_ABS)/stage2-inplace/ghc
-GHC_STAGE3  = $(GHC_COMPILER_DIR_ABS)/stage3-inplace/ghc
+GHC_STAGE2  = $(GHC_COMPILER_DIR_ABS)/stage1-inplace/ghc
+GHC_STAGE3  = $(GHC_COMPILER_DIR_ABS)/stage1-inplace/ghc
 # XXX All those used to have -no-user-package-conf, but then we can't
 # pass them to Cabal
 
@@ -981,6 +981,15 @@
 HaveGcc 	= @HaveGcc@
 UseGcc  	= YES
 WhatGccIsCalled = @WhatGccIsCalled@
+TARGET_GCC = @TARGET_GCC@
+TARGET_LD = @TARGET_LD@
+TARGET_AR = @TARGET_AR@
+TARGET_RANLIB = @TARGET_RANLIB@
+TARGET_STRIP = @TARGET_STRIP@
+TARGET_CPPFLAGS = @TARGET_CPPFLAGS@
+TARGET_CFLAGS = @TARGET_CFLAGS@
+TARGET_LDFLAGS = @TARGET_LDFLAGS@
+TOOLCHAIN_EXE_PREFIX = @TOOLCHAIN_EXE_PREFIX@
 GccVersion      = @GccVersion@
 ifeq "$(strip $(HaveGcc))" "YES"
 ifneq "$(strip $(UseGcc))"  "YES"
@@ -1196,7 +1205,7 @@
 GHC_ALEX_OPTS		= -g
 
 # Should we build haddock docs?
-HADDOCK_DOCS = YES
+HADDOCK_DOCS = NO
 # And HsColour the sources?
 ifeq "$(HSCOLOUR)" ""
 HSCOLOUR_SRCS = NO
--- ghc-6.10.2.orig/mk/package.mk	2009-03-31 06:13:15.000000000 +1300
+++ ghc-6.10.2/mk/package.mk	2009-06-18 15:54:37.000000000 +1200
@@ -86,7 +86,7 @@
 	    | sed -e 's/""//g' -e 's/:[   ]*,/: /g' \
 	    | $(GHC_PKG_INSTALL_PROG) --global-conf $(DESTDIR)$(datadir)/package.conf update - --force
 
-GHC_PKG_INSTALL_PROG = $(FPTOOLS_TOP_ABS)/utils/ghc-pkg/dist-install/build/ghc-pkg/ghc-pkg
+GHC_PKG_INSTALL_PROG = $(FPTOOLS_TOP_ABS)/utils/ghc-pkg/install-inplace/build/ghc-pkg/ghc-pkg
 
 # we could be more accurate here and add a dependency on
 # driver/package.conf, but that doesn't work too well because of
--- ghc-6.10.2.orig/mk/cabal-flags.mk	2009-03-31 06:13:16.000000000 +1300
+++ ghc-6.10.2/mk/cabal-flags.mk	2009-06-18 15:54:37.000000000 +1200
@@ -3,11 +3,12 @@
 space=$(nothing) $(nothing)
 comma=,
 
-GHC_PKG_INSTALL_PROG = $(FPTOOLS_TOP_ABS)/utils/ghc-pkg/dist-install/build/ghc-pkg/ghc-pkg
+GHC_PKG_INSTALL_PROG = $(FPTOOLS_TOP_ABS)/utils/ghc-pkg/install-inplace/build/ghc-pkg/ghc-pkg
 
 LIBRARIES_ABS = $(FPTOOLS_TOP_ABS)/libraries
 UTILS_ABS     = $(FPTOOLS_TOP_ABS)/utils
-CABAL = $(LIBRARIES_ABS)/cabal-bin $(GHC) $(LIBRARIES_ABS)/bootstrapping.conf $(CABAL_DOTTED_VERSION)
+CABAL_BOOT = $(LIBRARIES_ABS)/cabal-bin $(GHC) $(LIBRARIES_ABS)/bootstrapping.conf $(CABAL_DOTTED_VERSION)
+CABAL = $(LIBRARIES_ABS)/cabal-bin $(GHC_STAGE1) $(LIBRARIES_ABS)/bootstrapping.conf $(CABAL_DOTTED_VERSION)
 INSTALL_PACKAGE = \
     $(UTILS_ABS)/installPackage/install-inplace/bin/installPackage
 STAGE3_PACKAGE_CONF = $(FPTOOLS_TOP_ABS)/stage3.package.conf
@@ -25,8 +26,6 @@
 
 COMMON_CONFIGURE_FLAGS =          \
     --libsubdir='$$pkgid'         \
-    --with-gcc=$(WhatGccIsCalled) \
-    --with-ld=$(LD)               \
     $(addprefix --hsc2hs-option=,$(SRC_HSC2HS_OPTS))
 
 ifeq "$(HSCOLOUR_SRCS)" "YES"
@@ -73,10 +72,18 @@
 INPLACE_DIRS_CONFIGURE_FLAGS = \
     --prefix=`$(FPTOOLS_TOP_ABS)/utils/pwd/pwd forwardslash`/install-inplace
 
-USE_BOOT_CONFIGURE_FLAGS = \
+DISABLE_TOOLCHAIN= \
     --with-compiler=$(GHC) \
     --with-hc-pkg=$(GHC_PKG) \
-	--package-db $(FPTOOLS_TOP_ABS)/libraries/bootstrapping.conf
+    --package-db $(FPTOOLS_TOP_ABS)/libraries/bootstrapping.conf \
+    --with-gcc=$(WhatGccIsCalled) \
+    --with-ld=$(LD) \
+    --target-ar="$(AR)" \
+    --target-ranlib="$(RANLIB)" \
+    --target-strip="$(STRIP)" \
+    --target-cppflags="$(CPPFLAGS)" \
+    --target-cflags="$(CFLAGS)" \
+    --target-ldflags="$(LDFLAGS)"
 
 USE_STAGE_CONFIGURE_FLAGS = \
     --with-hc-pkg=$(GHC_PKG_INPLACE) \
@@ -85,12 +92,10 @@
 
 USE_STAGE1_CONFIGURE_FLAGS = \
     --with-compiler=$(GHC_STAGE1) \
-    $(USE_STAGE_CONFIGURE_FLAGS)
+    $(USE_STAGE_CONFIGURE_FLAGS) \
+        --package-db $(FPTOOLS_TOP_ABS)/libraries/installing.conf
 
-USE_STAGE2_CONFIGURE_FLAGS =            \
-    --with-compiler=$(GHC_STAGE2)       \
-    $(USE_STAGE_CONFIGURE_FLAGS)        \
-	--package-db $(STAGE3_PACKAGE_CONF)
+USE_STAGE2_CONFIGURE_FLAGS = --should-not-be-used!
 
 BUILD_FLAGS = $(addprefix --ghc-option=,$(SRC_HC_OPTS))
 
--- ghc-6.10.2.orig/mk/target.mk	2009-03-31 06:13:15.000000000 +1300
+++ ghc-6.10.2/mk/target.mk	2009-06-18 15:54:37.000000000 +1200
@@ -273,8 +273,8 @@
 ifneq "$(way)" "i"
 define BUILD_STATIC_LIB
 $(RM) $@
-$(AR) $(AR_OPTS) $@ $(STUBOBJS) $(LIBOBJS)
-$(RANLIB) $@
+$(TARGET_AR) clqs $(AR_OPTS) $@ $(STUBOBJS) $(LIBOBJS)
+$(TARGET_RANLIB) $@
 endef
 else
 define BUILD_STATIC_LIB
@@ -306,8 +306,8 @@
 ifeq "$(ArSupportsInput)" ""
 define BUILD_STATIC_LIB
 $(RM) $@ $@.tmp
-(echo $(STUBOBJS) $(C_OBJS) $(GC_C_OBJS); $(FIND) $(patsubst %.$(way_)o,%_split,$(HS_OBJS)) -name '*.$(way_)o' -print) | xargs $(AR) $@
-$(RANLIB) $@
+(echo $(STUBOBJS) $(C_OBJS) $(GC_C_OBJS); $(FIND) $(patsubst %.$(way_)o,%_split,$(HS_OBJS)) -name '*.$(way_)o' -print) | xargs $(TARGET_AR) clqs $@
+$(TARGET_RANLIB) $@
 endef
 else
 define BUILD_STATIC_LIB
@@ -316,9 +316,9 @@
 echo $(C_OBJS) >> $@.list
 echo $(GC_C_OBJS) >> $@.list
 $(FIND) $(patsubst %.$(way_)o,%_split,$(HS_OBJS)) -name '*.$(way_)o' -print >> $@.list
-$(AR) $(AR_OPTS) $@ $(ArSupportsInput) $@.list
+$(TARGET_AR) clqs $(AR_OPTS) $@ $(ArSupportsInput) $@.list
 $(RM) $@.list
-$(RANLIB) $@
+$(TARGET_RANLIB) $@
 endef
 endif
 
--- ghc-6.10.2.orig/mk/install.mk	2009-03-31 06:13:16.000000000 +1300
+++ ghc-6.10.2/mk/install.mk	2009-06-18 15:54:37.000000000 +1200
@@ -197,7 +197,7 @@
 		case $$i in \
 		  *.a) \
 		    $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
-		    $(RANLIB) $(DESTDIR)$(libdir)/`basename $$i` ;; \
+		    $(TARGET_RANLIB) $(DESTDIR)$(libdir)/`basename $$i` ;; \
 		  *.dll) \
 		    $(INSTALL_DATA) -s $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir) ;; \
 		  *.so) \
--- ghc-6.10.2.orig/compiler/Makefile	2009-03-31 06:13:16.000000000 +1300
+++ ghc-6.10.2/compiler/Makefile	2009-06-18 15:54:37.000000000 +1200
@@ -191,33 +191,36 @@
 
 # In a source dist we don't need to worry about Parser.y(.pp) as we have
 # the .hs file pre-generated
-ifneq "$(wildcard parser/Parser.y.pp)" ""
-PARSER_Y = parser/Parser.y
-endif
+PARSER_Y = parser/Parser.y parser/Lexer.x
+
+parser/Parser.y.pp: parser/Parser.y.pp.source
+	cp $< $@
+	rm -f parser/Parser.hs  # Prevent the pre-happy'ed version being used
+
+parser/Lexer.x: parser/Lexer.x.source
+	cp $< $@
+	rm -f parser/Lexer.hs  # Prevent the pre-alex'ed version being used
 
 boot.stage.%: $(PRIMOP_BITS) $(CONFIG_HS) $(PARSER_Y)
 	test -f $(STAGE3_PACKAGE_CONF) || echo "[]" > $(STAGE3_PACKAGE_CONF)
-	$(CABAL) configure --distpref dist-stage$* \
-	                   $(CONFIGURE_FLAGS_STAGE$*) \
-	                   $(INSTALL_DIRS_CONFIGURE_FLAGS) \
-	                   $(COMMON_CONFIGURE_FLAGS) \
-	                   --ghc-option=-DSTAGE=$*
+	$(CABAL_BOOT) configure --distpref dist-stage$* $(DISABLE_TOOLCHAIN) \
+            --ghc-option=-DSTAGE=2  # lie because compiler assumes STAGE 1=bootstrap, not production compiler
 	$(RM) -f Makefile-stage$*
-	$(CABAL) makefile  --distpref dist-stage$* -f Makefile-stage$*
+	$(CABAL_BOOT) makefile  --distpref dist-stage$* -f Makefile-stage$*
 
 build.stage.%:
 	$(MAKE) -f Makefile-stage$* stage=$*
-	$(CABAL) register  --distpref dist-stage$* --inplace
+	$(CABAL_BOOT) register  --distpref dist-stage$* --inplace
 	$(MAKE) -C ../ghc stage=$*
 
 doc.stage.%:
-	$(CABAL) haddock --distpref dist-stage$* \
+	$(CABAL_BOOT) haddock --distpref dist-stage$* \
 					 --html-location='../$$pkg' \
 	                 --haddock-option=--optghc=-DSTAGE=$* \
 	                 --with-haddock=$(FPTOOLS_TOP_ABS)/utils/haddock/install-inplace/bin/haddock
 
 install:
-	$(INSTALL_PACKAGE) install '$(GHC_PKG_INSTALL_PROG)' '$(DESTDIR)$(datadir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' --distpref dist-stage2
+	$(INSTALL_PACKAGE) install '$(GHC_PKG_INSTALL_PROG)' '$(DESTDIR)$(datadir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' --distpref dist-stage1
 
 # -----------------------------------------------------------------------------
 # Create compiler configuration
@@ -262,7 +265,11 @@
 	@echo "cRAWCPP_FLAGS         :: String" >> $(CONFIG_HS)
 	@echo "cRAWCPP_FLAGS         = \"$(RAWCPP_FLAGS)\"" >> $(CONFIG_HS)
 	@echo "cGCC                  :: String" >> $(CONFIG_HS)
-	@echo "cGCC                  = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
+	@echo "cGCC                  = \"$(TARGET_GCC)\"" >> $(CONFIG_HS)
+	@echo "cGCCOptions           :: [String]" >> $(CONFIG_HS)
+	@echo "cGCCOptions           = words \"$(TARGET_CPPFLAGS) $(TARGET_CFLAGS)\"" >> $(CONFIG_HS)
+	@echo "cTARGET_LDFLAGS       :: [String]" >> $(CONFIG_HS)
+	@echo "cTARGET_LDFLAGS       = words \"$(TARGET_LDFLAGS)\"" >> $(CONFIG_HS)
 	@echo "cMKDLL                :: String" >> $(CONFIG_HS)
 	@echo "cMKDLL                = \"$(BLD_DLL)\"" >> $(CONFIG_HS)
 	@echo "cLdIsGNULd            :: String" >> $(CONFIG_HS)
@@ -483,5 +490,5 @@
 endif
 
 include $(TOP)/mk/bindist.mk
-LIB_DIST_DIR = dist-stage2
+LIB_DIST_DIR = dist-stage1
 
--- ghc-6.10.2.orig/ghc/Makefile	2009-03-31 06:13:15.000000000 +1300
+++ ghc-6.10.2/ghc/Makefile	2009-06-18 15:54:37.000000000 +1200
@@ -108,17 +108,16 @@
 dist-stage1 dist-stage2 dist-stage3: dist-stage%: boot.stage.%
 
 boot.stage.%:
-	$(CABAL) configure --distpref dist-stage$*         \
-	                   $(INSTALL_DIRS_CONFIGURE_FLAGS) \
-	                   $(CONFIGURE_FLAGS_STAGE$*)      \
-	                   $(COMMON_CONFIGURE_FLAGS)       \
-	                   --libsubdir=.                   \
-	                   --datadir='$$libdir'            \
-	                   --datasubdir=.
+	$(CABAL_BOOT) configure --distpref dist-stage1 $(CONFIGURE_FLAGS_STAGE$*) $(DISABLE_TOOLCHAIN) \
+            $(INSTALL_DIRS_CONFIGURE_FLAGS) \
+            --libsubdir=.                   \
+            --datadir='$$libdir'            \
+            --datasubdir=.
+
 
 build.stage.%: dist-stage%
 	$(TOUCH_MAIN)
-	$(CABAL) build     --distpref dist-stage$* $(BUILD_FLAGS)
+	$(CABAL_BOOT) build     --distpref dist-stage1 $(BUILD_FLAGS)
 	$(INSTALL_PACKAGE) install '$(GHC_PKG_PROG)' 'XXX/package.conf' "" \
 	                   $(FPTOOLS_TOP_ABS)/ghc/stage$*-inplace          \
 	                   $(FPTOOLS_TOP_ABS)/ghc/stage$*-inplace          \
@@ -130,17 +129,18 @@
 	                   '$$prefix/doc'                                  \
 	                   '$$prefix/html'                                 \
 	                   '$$prefix/haddock'                              \
-	                   --distpref dist-stage$*                         \
+	                   --distpref dist-stage1                   \
 	                   $(INPLACE_INSTALL_FLAGS)                        \
 	                   $(INSTALL_FLAGS)
 
 # XXX For now we always install the stage 2 compiler
+# Cross compile: Not any more we don't.
 install:
 	$(INSTALL_PACKAGE) install UNUSED UNUSED '$(DESTDIR)' '$(prefix)' \
 	                   '$(prefix)' '$(bindir)' '$(libdir)'            \
                        '$(libexecdir)' '$(dynlibdir)' '$(datadir)'    \
                        '$(docdir)' '$(htmldir)' '$(haddockdir)'       \
-	                   --distpref dist-stage2                         \
+	                   --distpref dist-stage1                         \
 	                   $(INSTALL_FLAGS)
 
 html:
@@ -150,5 +150,5 @@
 	@:
 
 include $(TOP)/mk/bindist.mk
-EXE_DIST_DIR = dist-stage2
+EXE_DIST_DIR = dist-stage1
 
--- ghc-6.10.2.orig/libraries/Makefile	2009-03-31 06:13:16.000000000 +1300
+++ ghc-6.10.2/libraries/Makefile	2009-06-18 15:54:37.000000000 +1200
@@ -124,7 +124,7 @@
 
 .PHONY: boot
 
-boot: ifBuildable/ifBuildable cabal-bin bootstrapping.conf
+boot: ifBuildable/ifBuildable cabal-bin bootstrapping.conf installing.conf
 
 cabal-bin: cabal-bin.hs
 	-mkdir bootstrapping
@@ -132,24 +132,27 @@
 
 bootstrapping.conf: cabal-bin
 	echo "[]" > $@.tmp
-	-cd extensible-exceptions && $(CABAL) clean     --distpref=dist-bootstrapping
-	cd extensible-exceptions && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
-	cd extensible-exceptions && $(CABAL) build     --distpref=dist-bootstrapping
-	cd extensible-exceptions && $(CABAL) install   --distpref=dist-bootstrapping --inplace
-	-cd filepath && $(CABAL) clean     --distpref=dist-bootstrapping
-	cd filepath && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
-	cd filepath && $(CABAL) build     --distpref=dist-bootstrapping
-	cd filepath && $(CABAL) install   --distpref=dist-bootstrapping --inplace
-	-cd Cabal    && $(CABAL) clean     --distpref=dist-bootstrapping
-	cd Cabal    && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
-	cd Cabal    && $(CABAL) build     --distpref=dist-bootstrapping
-	cd Cabal    && $(CABAL) install   --distpref=dist-bootstrapping --inplace
-	-cd hpc    && $(CABAL) clean     --distpref=dist-bootstrapping
-	cd hpc    && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
-	cd hpc    && $(CABAL) build     --distpref=dist-bootstrapping
-	cd hpc    && $(CABAL) install   --distpref=dist-bootstrapping --inplace
+	-cd extensible-exceptions && $(CABAL_BOOT) clean     --distpref=dist-bootstrapping
+	cd extensible-exceptions && $(CABAL_BOOT) configure --distpref=dist-bootstrapping $(DISABLE_TOOLCHAIN) --package-db=$(HERE_ABS)/$@.tmp
+	cd extensible-exceptions && $(CABAL_BOOT) build     --distpref=dist-bootstrapping
+	cd extensible-exceptions && $(CABAL_BOOT) install   --distpref=dist-bootstrapping --inplace
+	-cd filepath && $(CABAL_BOOT) clean     --distpref=dist-bootstrapping
+	cd filepath && $(CABAL_BOOT) configure --distpref=dist-bootstrapping $(DISABLE_TOOLCHAIN) --package-db=$(HERE_ABS)/$@.tmp
+	cd filepath && $(CABAL_BOOT) build     --distpref=dist-bootstrapping
+	cd filepath && $(CABAL_BOOT) install   --distpref=dist-bootstrapping --inplace
+	-cd Cabal    && $(CABAL_BOOT) clean     --distpref=dist-bootstrapping
+	cd Cabal    && $(CABAL_BOOT) configure --distpref=dist-bootstrapping $(DISABLE_TOOLCHAIN) --package-db=$(HERE_ABS)/$@.tmp
+	cd Cabal    && $(CABAL_BOOT) build     --distpref=dist-bootstrapping
+	cd Cabal    && $(CABAL_BOOT) install   --distpref=dist-bootstrapping --inplace
+	-cd hpc    && $(CABAL_BOOT) clean     --distpref=dist-bootstrapping
+	cd hpc    && $(CABAL_BOOT) configure --distpref=dist-bootstrapping $(DISABLE_TOOLCHAIN) --package-db=$(HERE_ABS)/$@.tmp
+	cd hpc    && $(CABAL_BOOT) build     --distpref=dist-bootstrapping
+	cd hpc    && $(CABAL_BOOT) install   --distpref=dist-bootstrapping --inplace
 	mv $@.tmp $@
 
+installing.conf: cabal-bin
+	echo "[]" > $@
+
 ifBuildable/ifBuildable: ifBuildable.hs
 	-$(RM) -rf ifBuildable
 	mkdir ifBuildable
@@ -230,9 +233,11 @@
 	  $(CABAL) makefile -f GNUmakefile; \
 	  cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
 	  $(MAKE) $(MFLAGS) && \
-	  $(CABAL) register --inplace; \
+	  $(CABAL) register --inplace -v; \
 	fi
 
+#$(GHC_PKG_PROG) register dist/inplace-pkg-config --global --global-conf=$(LIBRARIES_ABS)/installing.conf --force;
+
 MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
 
 # Build the library using 'setup build' (not the default)
@@ -242,7 +247,7 @@
 	if $(IFBUILDABLE) $*; then \
 	  cd $* && \
 	  $(CABAL) build $(BUILD_FLAGS); \
-	  $(CABAL) register --inplace; \
+	  $(CABAL) register --inplace -v; \
 	fi
 
 .PHONY: doc html
@@ -290,6 +295,7 @@
 	$(RM) -rf bootstrapping
 	$(RM) -f bootstrapping.conf     bootstrapping.conf.old
 	$(RM) -f bootstrapping.conf.tmp bootstrapping.conf.tmp.old
+	$(RM) -f installing.conf
 	$(RM) -f cabal-bin cabal-bin.exe
 	$(RM) -rf ifBuildable
 	$(RM) -f libraries.txt index.html doc-index.html doc-index*.html
--- ghc-6.10.2.orig/rts/Makefile	2009-03-31 06:13:15.000000000 +1300
+++ ghc-6.10.2/rts/Makefile	2009-06-18 15:54:37.000000000 +1200
@@ -186,6 +186,10 @@
 SRC_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
 LIB_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
 
+# iPhone / cross-compile
+SRC_CC_OPTS += $(TARGET_CPPFLAGS) $(TARGET_CFLAGS)
+LIB_LD_OPTS += $(TARGET_LDFLAGS)
+
 # XXX DQ is now the same on all platforms, so get rid of it
 DQ = \"
 
--- ghc-6.10.2.orig/utils/Makefile	2009-03-31 06:13:15.000000000 +1300
+++ ghc-6.10.2/utils/Makefile	2009-06-18 15:54:37.000000000 +1200
@@ -59,7 +59,7 @@
 # libraries. The reason we use stage2 rather than stage1 is that some
 # utils, e.g. haddock, need the GHC API package.
 
-WITH_BOOTSTRAPPING_COMPILER = installPackage ghc-pkg hsc2hs hpc
+WITH_BOOTSTRAPPING_COMPILER = installPackage ghc-pkg
 
 WITH_STAGE2 = installPackage ghc-pkg hasktags runghc hpc pwd haddock
 ifneq "$(NO_INSTALL_HSC2HS)" "YES"
--- ghc-6.10.2.orig/utils/haddock/Makefile	2009-03-31 06:13:57.000000000 +1300
+++ ghc-6.10.2/utils/haddock/Makefile	2009-06-18 15:54:37.000000000 +1200
@@ -14,6 +14,7 @@
 EXTRA_STAGE2_CONFIGURE_FLAGS += --enable-library-profiling
 EXTRA_STAGE2_CONFIGURE_FLAGS += --enable-executable-profiling
 endif
+EXTRA_INPLACE_CONFIGURE_FLAGS +=
 
 # Ideally we'd automatically find these from the .cabal file:
 BINDIST_EXTRAS += html/haddock-DEBUG.css \
@@ -23,7 +24,17 @@
                   html/minus.gif         \
                   html/plus.gif
 
-include $(TOP)/mk/cabal.mk
+include $(TOP)/mk/cabal-flags.mk
+
+.PHONY: default all with-bootstrapping-compiler with-stage-2 clean distclean
+
+default all: with-bootstrapping-compiler
+
+with-bootstrapping-compiler:
+	$(CABAL_BOOT) configure --distpref=install-inplace $(DISABLE_TOOLCHAIN) \
+                $(INPLACE_DIRS_CONFIGURE_FLAGS) $(EXTRA_INPLACE_CONFIGURE_FLAGS)
+	$(CABAL_BOOT) build --distpref=install-inplace
+	$(CABAL_BOOT) install --distpref=install-inplace
 
 # bindist.mk isn't expecting a library to be in the same package as an
 # executable, so we have to help it out
@@ -50,7 +61,7 @@
 DYN_FLAGS = --ghc-option=-dynamic
 endif
 
-install-inplace:
+install:
 	$(INSTALL_PACKAGE) install '$(GHC_PKG_PROG)' '$(INPLACE_PKG_CONF)' ''  \
 	    '$(FPTOOLS_TOP_ABS)/utils/haddock/install-inplace' \
 	    '$(FPTOOLS_TOP_ABS)/utils/haddock/install-inplace' \
@@ -62,8 +73,9 @@
 	    '$$prefix/doc'                                     \
 	    '$$prefix/html'                                    \
 	    '$$prefix/haddock'                                 \
-	    --distpref dist-install                            \
+	    --distpref install-inplace                         \
 	    $(INSTALL_INPLACE_FLAGS)
+
 ifeq "$(BuildSharedLibs)" "YES"
 	    mv dist-install/build/haddock/haddock.dyn dist-install/build/haddock/haddock # remove the wrapper
-endif
\ No newline at end of file
+endif
--- ghc-6.10.2.orig/utils/installPackage/Makefile	2009-03-31 06:13:15.000000000 +1300
+++ ghc-6.10.2/utils/installPackage/Makefile	2009-06-18 15:54:37.000000000 +1200
@@ -1,7 +1,7 @@
 
 TOP=../..
 include $(TOP)/mk/boilerplate.mk
-include $(TOP)/mk/cabal.mk
+include $(TOP)/mk/cabal-flags.mk
 
 # If the bootstrapping compiler already has a newer version of Cabal
 # than the in-tree Cabal, then we need to forcibly use the in-tree one.
@@ -11,3 +11,13 @@
 EXTRA_INPLACE_CONFIGURE_FLAGS += $(CABAL_CONSTRAINT)
 EXTRA_STAGE2_CONFIGURE_FLAGS  += $(CABAL_CONSTRAINT)
 
+.PHONY: default all with-bootstrapping-compiler with-stage-2 clean distclean
+
+default all: with-bootstrapping-compiler
+
+with-bootstrapping-compiler:
+	$(CABAL_BOOT) configure --distpref=install-inplace $(DISABLE_TOOLCHAIN) $(EXTRA_INPLACE_CONFIGURE_FLAGS) \
+            $(INPLACE_DIRS_CONFIGURE_FLAGS)
+	$(CABAL_BOOT) build --distpref=install-inplace
+	$(CABAL_BOOT) install --distpref=install-inplace
+
--- ghc-6.10.2.orig/utils/ghc-pkg/Makefile	2009-03-31 06:13:15.000000000 +1300
+++ ghc-6.10.2/utils/ghc-pkg/Makefile	2009-06-18 15:54:37.000000000 +1200
@@ -5,12 +5,32 @@
 EXTRA_INPLACE_CONFIGURE_FLAGS = $(INPLACE_GHC_DATADIR_CONFIGURE_FLAGS)
 EXTRA_STAGE2_CONFIGURE_FLAGS = --datasubdir=.
 
+INSTALL_FLAGS = --enable-shell-wrappers
+
 include $(TOP)/mk/boilerplate.mk
-include $(TOP)/mk/cabal.mk
+include $(TOP)/mk/cabal-flags.mk
+
+.PHONY: default all with-bootstrapping-compiler with-stage-2 clean distclean
+
+default all: with-bootstrapping-compiler
+
+with-bootstrapping-compiler:
+	$(CABAL_BOOT) configure --distpref=install-inplace $(DISABLE_TOOLCHAIN) $(EXTRA_INPLACE_CONFIGURE_FLAGS) \
+            $(INPLACE_DIRS_CONFIGURE_FLAGS)
+	$(CABAL_BOOT) build --distpref=install-inplace
+	$(CABAL_BOOT) install --distpref=install-inplace --enable-shell-wrappers
 
 with-bootstrapping-compiler: Version.hs
 with-stage-2: Version.hs
 
+install:
+	$(INSTALL_PACKAGE) install UNUSED UNUSED '$(DESTDIR)' '$(prefix)' \
+	                   '$(prefix)' '$(bindir)' '$(libdir)'            \
+                       '$(libexecdir)' '$(dynlibdir)' '$(datadir)'    \
+                       '$(docdir)' '$(htmldir)' '$(haddockdir)'       \
+	                   --distpref install-inplace              \
+	                   $(INSTALL_FLAGS)
+
 Version.hs: Makefile $(TOP)/mk/config.mk
 	$(RM) -f Version.hs
 	echo "module Version where"                    >> Version.hs
--- ghc-6.10.2.orig/driver/ghc/Makefile	2009-03-31 06:13:16.000000000 +1300
+++ ghc-6.10.2/driver/ghc/Makefile	2009-06-18 15:54:37.000000000 +1200
@@ -9,11 +9,13 @@
 SCRIPT_BASE = ghc
 SCRIPT_VERSIONED_BASE = $(SCRIPT_BASE)-$(ProjectVersion)
 SCRIPT           = $(SCRIPT_DIR)/$(SCRIPT_BASE)
+SCRIPT_TAGGED    = $(SCRIPT_DIR)/$(TOOLCHAIN_EXE_PREFIX)$(SCRIPT_BASE)
 SCRIPT_VERSIONED = $(SCRIPT_DIR)/$(SCRIPT_VERSIONED_BASE)
 
 install::
 	mv $(SCRIPT) $(SCRIPT_VERSIONED)
-	ln -s $(SCRIPT_VERSIONED_BASE) $(SCRIPT)
+	rm -f $(SCRIPT_TAGGED)
+	ln -s $(SCRIPT_VERSIONED_BASE) $(SCRIPT_TAGGED)
 endif
 
 include $(TOP)/mk/bindist.mk
--- ghc-6.10.2.orig/driver/ghc-pkg/Makefile	2009-03-31 06:13:15.000000000 +1300
+++ ghc-6.10.2/driver/ghc-pkg/Makefile	2009-06-18 15:54:37.000000000 +1200
@@ -6,11 +6,13 @@
 SCRIPT_BASE = ghc-pkg
 SCRIPT_VERSIONED_BASE = $(SCRIPT_BASE)-$(ProjectVersion)
 SCRIPT           = $(SCRIPT_DIR)/$(SCRIPT_BASE)
+SCRIPT_TAGGED    = $(SCRIPT_DIR)/$(TOOLCHAIN_EXE_PREFIX)$(SCRIPT_BASE)
 SCRIPT_VERSIONED = $(SCRIPT_DIR)/$(SCRIPT_VERSIONED_BASE)
 
 install::
 	mv $(SCRIPT) $(SCRIPT_VERSIONED)
-	ln -s $(SCRIPT_VERSIONED_BASE) $(SCRIPT)
+	rm -f $(SCRIPT_TAGGED) 
+	ln -s $(SCRIPT_VERSIONED_BASE) $(SCRIPT_TAGGED)
 endif
 
 include $(TOP)/mk/bindist.mk

