To create an unregisterised bundle, run make witht he targets "boostrap"
and "hc-file-bundle". I'm using the following settings in mk/build.mk:

	GhcBootLibs =		YES
	GhcLibHcOpts =   	-O -fvia-C -keep-hc-files
	GhcLibWays =
	GhcRTSWays =
	GhcRtsHcOpts =		-keep-hc-files
	GhcStage1HcOpts =	-O
	GhcStage2HcOpts =	-O -fvia-C -keep-hc-files
	GhcUnregisterised =	YES
	GhcWithInterpreter =	NO
	GhcWithSMP =		NO
	SRC_HC_OPTS =    	-H64
	SplitObjs =      	NO

===== Start of diffs, comments above each diff ===

No need to build compat when booting from HC files.
Generate and include dependency makefiles.
Don't bail out on a missing Parser.hs (from package haskell-src,
i.e. extralibs).

diff -rNup ghc-6.8.2.orig/Makefile ghc-6.8.2/Makefile
--- ghc-6.8.2.orig/Makefile	Mon Dec 10 19:11:32 2007
+++ ghc-6.8.2/Makefile	Fri Apr 18 15:55:54 2008
@@ -59,7 +59,7 @@ include $(TOP)/mk/boilerplate.mk
 
 # We can't 'make boot' in libraries until stage1 is built
 ifeq "$(BootingFromHc)" "YES"
-SUBDIRS_BUILD = gmp includes rts compat compiler docs utils driver
+SUBDIRS_BUILD = gmp includes rts compiler docs utils driver
 else
 SUBDIRS_BUILD = gmp includes compat utils driver docs compiler rts libraries/Cabal/doc
 endif
@@ -498,13 +498,15 @@ endif
 # HC file bundles
 
 hc-file-bundle :
+	cd libraries && $(MAKE) bootmakefiles
 	$(RM) -r ghc-$(ProjectVersion)
 	$(LN_S) . ghc-$(ProjectVersion)
 	$(FIND) ghc-$(ProjectVersion)/compiler \
 	     ghc-$(ProjectVersion)/utils \
-	     ghc-$(ProjectVersion)/compat \
 	     ghc-$(ProjectVersion)/libraries -follow \
-	  \( -name "*.hc" -o -name "*_hsc.[ch]" -o -name "*_stub.[ch]" \) -print > hc-files-to-go
+	  \( -name "*.hc" -o -name "*_hsc.[ch]" -o -name "*_stub.[ch]" \
+		-o -name boot.mk \
+	  \) -print > hc-files-to-go
 	for f in `$(FIND) ghc-$(ProjectVersion)/compiler ghc-$(ProjectVersion)/utils ghc-$(ProjectVersion)/libraries -name "*.hsc" -follow -print` ""; do \
 	     if test "x$$f" != "x" && test -e `echo "$$f" | sed 's/hsc$$/hs/g'`; then \
 	        echo `echo "$$f" | sed 's/hsc$$/hs/g' ` >> hc-files-to-go ; \
@@ -515,11 +517,11 @@ hc-file-bundle :
 	        echo `echo "$$f" | sed 's/cmm$$/hc/g' ` >> hc-files-to-go ; \
 	     fi; \
 	done;
+	echo ghc-$(ProjectVersion)/driver/package.conf.inplace >> hc-files-to-go
 	echo ghc-$(ProjectVersion)/libraries/base/GHC/PrimopWrappers.hs >> hc-files-to-go
 	echo ghc-$(ProjectVersion)/compiler/parser/Parser.hs >> hc-files-to-go
 	echo ghc-$(ProjectVersion)/compiler/parser/ParserCore.hs >> hc-files-to-go
 	echo ghc-$(ProjectVersion)/compiler/main/ParsePkgConf.hs >> hc-files-to-go
-	echo ghc-$(ProjectVersion)/libraries/haskell-src/Language/Haskell/Parser.hs >> hc-files-to-go
 	tar czf ghc-$(ProjectVersion)-$(TARGETPLATFORM)-hc.tar.gz `cat hc-files-to-go`
 
 # -----------------------------------------------------------------------------

Don't use homebrewn pwd implemented in Haskell.
Yes, I know, this patch will break MINGW, but I've already suggested
a fix to the mailing lists.

diff -rNup ghc-6.8.2.orig/aclocal.m4 ghc-6.8.2/aclocal.m4
--- ghc-6.8.2.orig/aclocal.m4	Mon Dec 10 19:11:31 2007
+++ ghc-6.8.2/aclocal.m4	Fri Apr 18 15:56:09 2008
@@ -1098,24 +1098,7 @@ AC_REQUIRE([AC_PROG_CC])
 AC_DEFUN([FP_FIND_ROOT],[
 AC_MSG_CHECKING(for path to top of build tree)
 
-dnl This would be
-dnl     make -C utils/pwd clean && make -C utils/pwd
-dnl except we don't want to have to know what make is called. Sigh.
-if test ! -f utils/pwd/pwd && test ! -f utils/pwd/pwd.exe; then
-  cd utils/pwd
-  rm -f *.o
-  rm -f *.hi
-  rm -f pwd
-  rm -f pwd.exe
-  $WithGhc -v0 --make pwd -o pwd
-  cd ../..
-fi
-
-hardtop=`utils/pwd/pwd forwardslash`
-
-if ! test -d "$hardtop"; then
-  AC_MSG_ERROR([cannot determine current directory])
-fi   
+hardtop=`pwd`
 
 dnl Remove common automounter nonsense
 dnl


When bootstrapping from HC-files, don't try to build with interpreter
and don't links against libghccompat.
Use CC to build ghc-inplace, not HC.
Don't set DESTDIR (sorry, I forgot why I need this).
Pull in required libraries.

diff -rNup ghc-6.8.2.orig/compiler/Makefile ghc-6.8.2/compiler/Makefile
--- ghc-6.8.2.orig/compiler/Makefile	Mon Dec 10 19:11:32 2007
+++ ghc-6.8.2/compiler/Makefile	Fri Apr 18 15:55:54 2008
@@ -442,7 +442,7 @@ SRC_HC_OPTS += -package hpc -package bytestring
 PKG_DEPENDS += hpc bytestring
 endif
 
-ifeq "$(GhcWithInterpreter) $(bootstrapped)" "YES YES"
+ifeq "$(GhcWithInterpreter) $(bootstrapped) $(BootingFromHc)" "YES YES NO"
 
 # Yes, include the interepreter and Template Haskell extensions
 SRC_HC_OPTS += -DGHCI -package template-haskell
@@ -723,10 +723,11 @@ primop-usage.hs-incl: prelude/primops.txt
 #-----------------------------------------------------------------------------
 # 		Linking
 
-# Include libghccompat in stage1 only.  In stage2 onwards, all these
-# libraries will be available from the main libraries.
+# Include libghccompat in stage1 only, and only if not bootstrapping
+# from HC files.  In stage2 onwards, all these libraries will be
+# available from the main libraries.
 
-ifeq "$(stage)" "1"
+ifeq "$(BootingFromHc)$(stage)" "NO1"
 include $(GHC_COMPAT_DIR)/compat.mk
 endif
 
@@ -753,7 +754,11 @@ $(INPLACE_SRC): ghc-inplace.c
 	$(SED) -e "s@GHC_PATH@$(GHC_PATH)@g" -e "s@TOP_ABS@$(FPTOOLS_TOP_ABS)@g" < $< > $@
 
 $(INPLACE_PROG): $(INPLACE_SRC)
+ifneq "$(BootingFromHc)" "YES"
 	$(HC) -cpp $(INPLACE_EXTRA_FLAGS) $< -o $@
+else
+	$(CC) $(HC_BOOT_CC_OPTS) $(INPLACE_EXTRA_FLAGS) $< -o $@
+endif
 
 all :: $(INPLACE_PROG)
 
@@ -775,7 +780,6 @@ endif
 # but put it together with the libraries.
 # Also don't want any interface files installed
 
-DESTDIR = $(INSTALL_LIBRARY_DIR_GHC)
 
 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
 INSTALL_LIBEXECS += $(GHC_PROG)
@@ -1023,6 +1027,15 @@ $(odir)/utils/FastMutInt.$(way_)o	:  ../includes/MachD
 MKDEPENDHS_HC_OPTS = $(patsubst -i$(odir)/%, -i%, $(HC_OPTS))
 
 MKDEPENDHS=$(HC)
+
+ifeq "$(BootingFromHc)" "YES"
+include $(TOP)/libraries/Cabal/boot.mk
+include $(TOP)/libraries/bytestring/boot.mk
+include $(TOP)/libraries/haskell98/boot.mk
+# XXX why is hpc needed?
+include $(TOP)/libraries/hpc/boot.mk
+HC_BOOT_CC_OPTS += $(foreach P,$(DEP_PKGS),-I$(TOP)/libraries/$P/include)
+endif
 
 # Must do this *after* including target.mk, because $(HS_SRCS) isn't set yet.
 depend :: $(STAGE_PLATFORM_H) $(HS_SRCS) $(C_SRCS)


Add a target to create some makefile fragments that will be included
by a special makefile called Makefile.boot that'll be copied into
all library directories when bootstrapping from HC files.

diff -rNup ghc-6.8.2.orig/libraries/Makefile ghc-6.8.2/libraries/Makefile
--- ghc-6.8.2.orig/libraries/Makefile	Mon Dec 10 19:11:32 2007
+++ ghc-6.8.2/libraries/Makefile	Fri Apr 18 15:55:54 2008
@@ -20,13 +20,6 @@
 #   [ -e foo/configure.ac ] && ( cd foo && autoreconf )
 #   make make.library.foo
 
-.PHONY: default_target show
-
-default_target: all
-
-show:
-	@echo '$(VALUE)="$($(VALUE))"'
-
 # make doesn't give us an easy way to get the libraries built in
 # dependency order the first time, but not rebuild base (for example)
 # when we want to rebuild another library later.
@@ -38,6 +31,16 @@ show:
 TOP=..
 include $(TOP)/mk/boilerplate.mk
 
+ifneq "$(BootingFromHc)" "YES"
+
+.PHONY: default_target show
+
+default_target: all
+
+show:
+	@echo '$(VALUE)="$($(VALUE))"'
+
+
 SUBDIRS  = base array packedstring containers bytestring
 SUBDIRS += old-locale old-time filepath directory
 ifeq "$(GhcLibsWithUnix)" "YES"
@@ -402,3 +405,50 @@ binary-dist.library.%:
 html-no-chunks chm HxS fo dvi ps pdf:
 	@:
 
+# Build some simple Makefile fragments to get all transitive
+# dependencies and other information for bootstrapping from HC files
+
+.PHONY: bootmakefiles
+
+bootmakefiles: boot.mk \
+		$(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/boot.mk)
+
+%/boot.mk: Makefile
+	echo ifndef $*-version > $@
+	echo 'PACKAGE ?= $*' >> $@
+	for f in version exposed-modules hidden-modules extra-libraries; do \
+		$(TOP)/utils/ghc-pkg/ghc-pkg-inplace field $* $$f | \
+			sed -e "s/$$f:/$*-$$f =/" \
+				-e 's/$$/ \\/' \
+				-e '$$s/ \\$$//'; \
+	done >> $@
+	# Hack! This information isn't registered in the package.conf,
+	# so get it from the cabal-generated GNUmakefile. This should be
+	# really done with a small Haskell program using Cabal.
+	{ cd $* && $(MAKE) --no-print-directory -s -f GNUmakefile \
+		show VALUE=C_SRCS; } | sed 's/^/$*-/;s/"//g' >> $@
+	$(TOP)/utils/ghc-pkg/ghc-pkg-inplace field $* depends | \
+		tr ' ' '\n' | \
+		sed -e 's/-[0-9][0-9.]*//g' -e 's/depends://' \
+			-e '/^rts$$/d' -e '/^$$/d' \
+			-e 's!^!include $$(TOP)/libraries/!' \
+			-e 's!$$!/boot.mk!' >> $@
+	echo 'DEP_PKGS := $* $$(filter-out $*, $$(DEP_PKGS))' >> $@
+	echo endif >> $@
+
+boot.mk:
+	echo "SUBDIRS = $(SUBDIRS)" > $@
+
+
+else
+
+# BootingFromHc
+include boot.mk
+
+boot:: $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/Makefile)
+
+%/Makefile: Makefile.boot
+	$(CP) $^ $@
+
+include $(TOP)/mk/target.mk
+endif


Makefile for building the libraries when bootstrapping from HC
files.  It's the same for all libraries and gets the library-specific
information from  the generated boot.mk files.

diff -rNup ghc-6.8.2.orig/libraries/Makefile.boot ghc-6.8.2/libraries/Makefile.boot
--- ghc-6.8.2.orig/libraries/Makefile.boot	Thu Jan  1 01:00:00 1970
+++ ghc-6.8.2/libraries/Makefile.boot	Fri Apr 18 15:55:52 2008
@@ -0,0 +1,50 @@
+TOP=../..
+include $(TOP)/mk/boilerplate.mk
+include boot.mk
+
+modules = $($(PACKAGE)-exposed-modules) $($(PACKAGE)-hidden-modules)
+
+ALL_DIRS = $(patsubst %/,%,$(sort $(dir $(subst .,/,$(modules)))))
+
+C_SRCS = $($(PACKAGE)-C_SRCS)
+
+HC_BOOT_CC_OPTS += $(addprefix -I../, $(addsuffix /include, $(DEP_PKGS)))
+
+# Ad hoc exclusion of sources that aren't used.
+base-EXCLUDED_SRCS = GHC/Prim.hs
+filepath-EXCLUDED_SRCS = System/FilePath/Internal.hs
+
+EXCLUDED_SRCS = $($(PACKAGE)-EXCLUDED_SRCS)
+EXCLUDED_SRCS += Setup.hs Setup.lhs DefaultSetup.lhs
+
+odir = dist/build
+
+STUB_SRCS = $(wildcard $(patsubst %, $(odir)/%/*_stub.c, $(ALL_DIRS)))
+STUB_OBJS += $(patsubst %.c, %.o, $(STUB_SRCS))
+
+LIBOBJS = $(addprefix $(odir)/,$(OBJS)) $(STUB_OBJS)
+LIBRARY = $(odir)/libHS$(PACKAGE).a
+
+boot::	stamp-configure
+
+all::	$(LIBRARY)
+
+stamp-configure:
+	if [ -x configure ]; then \
+		./configure \
+		           $(CONFIGURE_OPTS) \
+		           --prefix=/NONEXISTANT \
+		           --bindir=/NONEXISTANT \
+		           --libdir=/NONEXISTANT \
+		           --libexecdir=/NONEXISTANT \
+		           --datadir=/NONEXISTANT \
+		           --with-hc=../../compiler/stage1/ghc-inplace \
+		           --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace \
+		           --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace \
+		           --with-ld=$(LD) \
+		           $(CONFIGURE_ARGS) \
+		           --with-cc=$(CC); \
+	fi
+	touch $@
+
+include $(TOP)/mk/target.mk


Replacement hack for ifBuildable. I don't remember wether this is
really needed for bootstrapping from HC files.

diff -rNup ghc-6.8.2.orig/libraries/ifBuildable.sh ghc-6.8.2/libraries/ifBuildable.sh
--- ghc-6.8.2.orig/libraries/ifBuildable.sh	Thu Jan  1 01:00:00 1970
+++ ghc-6.8.2/libraries/ifBuildable.sh	Fri Apr 18 15:55:52 2008
@@ -0,0 +1,19 @@
+#!/bin/sh
+#
+# Replacement of that strange ifBuildable.hs
+
+if [ $# != 1 ]; then
+	echo 'Syntax: ifBuildable <package>' >& 2
+	exit 1
+fi
+
+set -e
+
+cd "$1"
+
+if [ -f unbuildable ] &&
+	{ [ "$1" = readline ] || ! grep -qF "$1" ../boot-packages; }
+then
+	echo 'Warning: Package is unbuildable' >& 2
+	exit 1
+fi


Search GMP_LIB_DIRS when linking (not related to bootstrapping, and
probably already fixed).
Fix list of libraries linked into stage1 / HC-bootstrap.

diff -rNup ghc-6.8.2.orig/mk/bootstrap.mk ghc-6.8.2/mk/bootstrap.mk
--- ghc-6.8.2.orig/mk/bootstrap.mk	Mon Dec 10 19:11:31 2007
+++ ghc-6.8.2/mk/bootstrap.mk	Fri Apr 18 15:55:54 2008
@@ -83,29 +83,17 @@ endif
 
 ifeq "$(HaveLibGmp)" "NO"
 DASH_L_GHC_RTS_GMP_DIR=-L$(FPTOOLS_TOP_ABS)/$(GHC_RTS_DIR_REL)/gmp
+else
+DASH_L_GHC_RTS_GMP_DIR=$(foreach D,$(GMP_LIB_DIRS),-L$D)
 endif
 
-HC_BOOT_LD_OPTS =				\
-   -L$(FPTOOLS_TOP_ABS)/$(GHC_RTS_DIR_REL)	\
-   $(DASH_L_GHC_RTS_GMP_DIR)                    \
-   -L$(FPTOOLS_TOP_ABS)/libraries/base		\
-   -L$(FPTOOLS_TOP_ABS)/libraries/base/cbits	\
-   -L$(FPTOOLS_TOP_ABS)/libraries/haskell98	\
-   -L$(FPTOOLS_TOP_ABS)/libraries/parsec        \
-   -L$(FPTOOLS_TOP_ABS)/libraries/regex-base    \
-   -L$(FPTOOLS_TOP_ABS)/libraries/regex-posix   \
-   -L$(FPTOOLS_TOP_ABS)/libraries/regex-compat  \
-   -L$(FPTOOLS_TOP_ABS)/libraries/Cabal
+# XXX DEP_PKGS stuff should probably moved to compiler/Makefile.
+HC_BOOT_LD_OPTS =					\
+   -L$(FPTOOLS_TOP_ABS)/$(GHC_RTS_DIR_REL)		\
+   $(DASH_L_GHC_RTS_GMP_DIR)                    	\
+   $(foreach P,$(DEP_PKGS),-L$(FPTOOLS_TOP_ABS)/libraries/$P/dist/build)
 
-ifeq "$(GhcWithInterpreter)" "YES"
 HC_BOOT_LD_OPTS += \
-   -L$(FPTOOLS_TOP_ABS)/libraries/template-haskell	\
-   -L$(FPTOOLS_TOP_ABS)/libraries/readline	\
-   -L$(FPTOOLS_TOP_ABS)/libraries/unix          \
-   -L$(FPTOOLS_TOP_ABS)/libraries/unix/cbits
-endif
-
-HC_BOOT_LD_OPTS += \
    -u "$(UNDERSCORE)base_GHCziBase_Izh_static_info" \
    -u "$(UNDERSCORE)base_GHCziBase_Czh_static_info" \
    -u "$(UNDERSCORE)base_GHCziFloat_Fzh_static_info" \
@@ -139,13 +127,11 @@ HC_BOOT_LD_OPTS += \
    -u "$(UNDERSCORE)__stginit_Prelude"
 
 
-HC_BOOT_LIBS =
+HC_BOOT_LIBS =   $(addprefix -lHS, $(DEP_PKGS)) \
+		 $(addprefix -l, $(foreach P, $(DEP_PKGS), \
+					$($P-extra-libraries))) \
+		 -lHSrts -lgmp -lm $(EXTRA_HC_BOOT_LIBS)
 
-ifeq "$(GhcWithInterpreter)" "YES"
-HC_BOOT_LIBS += -lHSreadline -lHStemplate-haskell -lHSunix -lHSunix_cbits
-endif
-
-HC_BOOT_LIBS +=  -lHSregex-compat -lHSregex-posix -lHSregex-base -lHSCabal -lHShaskell98 -lHSbase -lHSbase_cbits -lHSparsec -lHSrts -lgmp -lm -lrt $(EXTRA_HC_BOOT_LIBS)
 
 ifeq "$(GhcLibsWithReadline)" "YES"
 HC_BOOT_LIBS += $(patsubst %, -l%, $(LibsReadline))


GMP_INCLUDE_DIRS is required for bootstrapping from HC files, but
it shouldn't hurt other builds, so add it here.

diff -rNup ghc-6.8.2.orig/mk/opts.mk ghc-6.8.2/mk/opts.mk
--- ghc-6.8.2.orig/mk/opts.mk	Mon Dec 10 19:11:31 2007
+++ ghc-6.8.2/mk/opts.mk	Fri Apr 18 15:55:55 2008
@@ -77,6 +77,9 @@ BLD_DLL_OPTS       = $(SRC_BLD_DLL_OPTS) $(WAY$(_way)_
 CPP_OPTS           = $(SRC_CPP_OPTS) $(WAY$(_way)_CPP_OPTS) $(EXTRA_CPP_OPTS)
 CTAGS_OPTS         = $(SRC_CTAGS_OPTS) $(WAY$(_way)_CTAGS_OPTS) $(EXTRA_CTAGS_OPTS)
 CC_OPTS            = $(SRC_CC_OPTS) $(WAY$(_way)_CC_OPTS) $($*_CC_OPTS) $(EXTRA_CC_OPTS)
+ifneq "$(GMP_INCLUDE_DIRS)" ""
+CC_OPTS		  += -I$(GMP_INCLUDE_DIRS)
+endif
 FLEX_OPTS          = $(SRC_FLEX_OPTS) $(WAY$(_way)_FLEX_OPTS) $(EXTRA_FLEX_OPTS)
 HADDOCK_OPTS       = $(SRC_HADDOCK_OPTS) $(WAY$(_way)_HADDOCK_OPTS) $($*_HADDOCK_OPTS) $(EXTRA_HADDOCK_OPTS)
 HAPPY_OPTS         = $(SRC_HAPPY_OPTS) $($(HcFlavour)_HAPPY_OPTS) $(WAY$(_way)_HAPPY_OPTS) $($*_HAPPY_OPTS) $(EXTRA_HAPPY_OPTS)


Some tweaks needed for bootstrapping from HC files.

diff -rNup ghc-6.8.2.orig/mk/suffix.mk ghc-6.8.2/mk/suffix.mk
--- ghc-6.8.2.orig/mk/suffix.mk	Mon Dec 10 19:11:31 2007
+++ ghc-6.8.2/mk/suffix.mk	Fri Apr 18 15:55:55 2008
@@ -125,15 +125,31 @@ ifeq "$(BootingFromUnregisterisedHc)" "YES"
 # without mangling
 
 $(odir_)%.o : %.hc
-	$(CC) -x c $< -o $@ -c -O $(HC_BOOT_CC_OPTS) -I.  `echo $(patsubst -monly-%-regs, -DSTOLEN_X86_REGS=%, $(filter -monly-%-regs, $($*_HC_OPTS))) | sed 's/^$$/-DSTOLEN_X86_REGS=4/'`
+	@mkdir -p $(dir $@)
+	$(CC) -x c $< -o $@ -c -O $(HC_BOOT_CC_OPTS) -I. -Iinclude \
+		$(addprefix -I,$(odir)) \
+		`echo $(patsubst -monly-%-regs, -DSTOLEN_X86_REGS=%, $(filter -monly-%-regs, $($*_HC_OPTS))) | sed 's/^$$/-DSTOLEN_X86_REGS=4/'`
 
+$(odir_)%.o : $(odir_)%.hc
+	$(CC) -x c $< -o $@ -c -O $(HC_BOOT_CC_OPTS) -I. -Iinclude \
+		$(addprefix -I,$(odir)) \
+		`echo $(patsubst -monly-%-regs, -DSTOLEN_X86_REGS=%, $(filter -monly-%-regs, $($*_HC_OPTS))) | sed 's/^$$/-DSTOLEN_X86_REGS=4/'`
+
 else
 
 # with mangling
 
 $(odir_)%.raw_s : %.hc
-	$(CC) -x c $< -o $@ -S -O $(HC_BOOT_CC_OPTS) -I.  `echo $(patsubst -monly-%-regs, -DSTOLEN_X86_REGS=%, $(filter -monly-%-regs, $($*_HC_OPTS))) | sed 's/^$$/-DSTOLEN_X86_REGS=4/'`
+	@mkdir -p $(dir $@)
+	$(CC) -x c $< -o $@ -S -O $(HC_BOOT_CC_OPTS) -I. -Iinclude \
+		$(addprefix -I,$(odir)) \
+		`echo $(patsubst -monly-%-regs, -DSTOLEN_X86_REGS=%, $(filter -monly-%-regs, $($*_HC_OPTS))) | sed 's/^$$/-DSTOLEN_X86_REGS=4/'`
 
+$(odir_)%.raw_s : $(odir_)%.hc
+	$(CC) -x c $< -o $@ -S -O $(HC_BOOT_CC_OPTS) -I. -Iinclude \
+		$(addprefix -I,$(odir)) \
+		`echo $(patsubst -monly-%-regs, -DSTOLEN_X86_REGS=%, $(filter -monly-%-regs, $($*_HC_OPTS))) | sed 's/^$$/-DSTOLEN_X86_REGS=4/'`
+
 $(odir_)%.s : $(odir_)%.raw_s
 	$(MANGLER) $< $@ $(patsubst -monly-%-regs, %, $(filter -monly-%-regs, $($*_HC_OPTS)))
 
@@ -208,25 +224,37 @@ else
 
 $(odir_)%.$(way_)o : %.c
 	@$(RM) $@
-	$(CC) $(CC_OPTS) -c $< -o $@
+	@mkdir -p $(dir $@)
+	$(CC) $(CC_OPTS) -Iinclude -c $< -o $@
 
 $(odir_)%.$(way_)o : %.$(way_)s
 	@$(RM) $@
+	@mkdir -p $(dir $@)
 	$(AS) $(AS_OPTS) -o $@ $<
 
 $(odir_)%.$(way_)o : %.S
 	@$(RM) $@
+	@mkdir -p $(dir $@)
 	$(CC) $(CC_OPTS) -c $< -o $@
 
 $(odir_)%.$(way_)s : %.c
 	@$(RM) $@
-	$(CC) $(CC_OPTS) -S $< -o $@
+	@mkdir -p $(dir $@)
+	$(CC) $(CC_OPTS) -Iinclude -S $< -o $@
 
 endif
 
+ifneq "$(BootingFromHc)" "YES"
 # stubs are automatically generated and compiled by GHC
 %_stub.$(way_)o: %.o
 	@:
+else
+# have to compile the stubs from the HC file bundle
+$(odir_)%.o : $(odir_)%.c
+	@$(RM) $@
+	@mkdir -p $(dir $@)
+	$(CC) $(CC_OPTS) -Iinclude -c $< -o $@
+endif
 
 # -----------------------------------------------------------------------------
 # Flex/lex


Don't try to build unused tools.

diff -rNup ghc-6.8.2.orig/utils/Makefile ghc-6.8.2/utils/Makefile
--- ghc-6.8.2.orig/utils/Makefile	Mon Dec 10 19:11:32 2007
+++ ghc-6.8.2/utils/Makefile	Fri Apr 18 15:55:55 2008
@@ -6,7 +6,7 @@ ifeq "$(DOING_BIN_DIST)" "YES"
 SUBDIRS = mkdirhier ghc-pkg hasktags hp2ps hsc2hs parallel prof unlit runghc hpc pwd
 else
 ifeq "$(BootingFromHc)" "YES"
-SUBDIRS = mkdependC mkdirhier runstdtest genapply genprimopcode ghc-pkg unlit
+SUBDIRS = mkdependC mkdirhier runstdtest unlit
 else
 SUBDIRS = mkdependC mkdirhier runstdtest ghc-pkg hasktags hp2ps hsc2hs \
 	  parallel prof unlit genprimopcode genapply runghc hpc pwd

