Merge remote-tracking branch 'origin/master' into ghc-parmake-gsoc
[ghc.git] / ghc.mk
diff --git a/ghc.mk b/ghc.mk
index 6d0b379..82e9e5c 100644 (file)
--- a/ghc.mk
+++ b/ghc.mk
 
 default : all
 
 
 default : all
 
+
+##################################################
+# Check that we have a new enough 'make'
+
+HAVE_EVAL := NO
+$(eval HAVE_EVAL := YES)
+
+ifeq "$(HAVE_EVAL)" "NO"
+$(error Your make does not support eval. You need GNU make >= 3.81)
+endif
+
+ifeq "$(abspath /)" ""
+$(error Your make does not support abspath. You need GNU make >= 3.81)
+endif
+##################################################
+
+
 # Catch make if it runs away into an infinite loop
 ifeq      "$(MAKE_RESTARTS)" ""
 else ifeq "$(MAKE_RESTARTS)" "1"
 else
 # Catch make if it runs away into an infinite loop
 ifeq      "$(MAKE_RESTARTS)" ""
 else ifeq "$(MAKE_RESTARTS)" "1"
 else
-$(error Make has restarted itself $(MAKE_RESTARTS) times; is there a makefile bug?)
+$(error Make has restarted itself $(MAKE_RESTARTS) times; is there a makefile bug? See http://hackage.haskell.org/trac/ghc/wiki/Building/Troubleshooting#Makehasrestarteditself3timesisthereamakefilebug for details)
 endif
 
 ifneq "$(CLEANING)" "YES"
 endif
 
 ifneq "$(CLEANING)" "YES"
@@ -110,6 +127,14 @@ comma=,
 show:
        @echo '$(VALUE)="$($(VALUE))"'
 
 show:
        @echo '$(VALUE)="$($(VALUE))"'
 
+# echo is used by the nightly builders to query the build system for
+# information.
+# Using printf means that we don't get a trailing newline. We escape
+# backslashes and double quotes in the string to protect them from the
+# shell, and percent signs to protect them from printf.
+echo:
+       @printf "$(subst %,%%,$(subst ",\",$(subst \,\\\\,$($(VALUE)))))"
+
 # -----------------------------------------------------------------------------
 # Include subsidiary build-system bits
 
 # -----------------------------------------------------------------------------
 # Include subsidiary build-system bits
 
@@ -128,13 +153,13 @@ include mk/ways.mk
 include mk/custom-settings.mk
 
 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
 include mk/custom-settings.mk
 
 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
-ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
+ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
 ifeq "$(findstring dyn,$(GhcLibWays))" ""
 ifeq "$(findstring dyn,$(GhcLibWays))" ""
-$(error dyn is not in $$(GhcLibWays), but $$(DYNAMIC_BY_DEFAULT) is YES)
+$(error dyn is not in $$(GhcLibWays), but $$(DYNAMIC_GHC_PROGRAMS) is YES)
 endif
 else
 ifeq "$(findstring v,$(GhcLibWays))" ""
 endif
 else
 ifeq "$(findstring v,$(GhcLibWays))" ""
-$(error v is not in $$(GhcLibWays), and $$(DYNAMIC_BY_DEFAULT) is not YES)
+$(error v is not in $$(GhcLibWays), and $$(DYNAMIC_GHC_PROGRAMS) is not YES)
 endif
 endif
 ifeq "$(GhcProfiled)" "YES"
 endif
 endif
 ifeq "$(GhcProfiled)" "YES"
@@ -167,7 +192,7 @@ include rules/clean-target.mk
 # -----------------------------------------------------------------------------
 # The inplace tree
 
 # -----------------------------------------------------------------------------
 # The inplace tree
 
-$(eval $(call clean-target,inplace,,inplace/bin inplace/lib))
+$(eval $(call clean-target,root,inplace,inplace/bin inplace/lib))
 
 # -----------------------------------------------------------------------------
 # Whether to build dependencies or not
 
 # -----------------------------------------------------------------------------
 # Whether to build dependencies or not
@@ -196,7 +221,7 @@ include rules/way-prelims.mk
 $(foreach way,$(ALL_WAYS),\
   $(eval $(call way-prelims,$(way))))
 
 $(foreach way,$(ALL_WAYS),\
   $(eval $(call way-prelims,$(way))))
 
-ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
+ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
 GHCI_WAY = dyn
 HADDOCK_WAY = dyn
 else
 GHCI_WAY = dyn
 HADDOCK_WAY = dyn
 else
@@ -204,6 +229,15 @@ GHCI_WAY = v
 HADDOCK_WAY = v
 endif
 
 HADDOCK_WAY = v
 endif
 
+WINDOWS_DYN_PROG_RTS := rts
+ifeq "$(GhcThreaded)" "YES"
+WINDOWS_DYN_PROG_RTS := $(WINDOWS_DYN_PROG_RTS)_thr
+endif
+ifeq "$(GhcDebugged)" "YES"
+WINDOWS_DYN_PROG_RTS := $(WINDOWS_DYN_PROG_RTS)_debug
+endif
+WINDOWS_DYN_PROG_RTS := $(WINDOWS_DYN_PROG_RTS)_dyn_LIB_NAME
+
 # -----------------------------------------------------------------------------
 # Compilation Flags
 
 # -----------------------------------------------------------------------------
 # Compilation Flags
 
@@ -249,6 +283,11 @@ include rules/build-dependencies.mk
 include rules/include-dependencies.mk
 
 # -----------------------------------------------------------------------------
 include rules/include-dependencies.mk
 
 # -----------------------------------------------------------------------------
+# Dynamic library references
+
+include rules/relative-dynlib-references.mk
+
+# -----------------------------------------------------------------------------
 # Build package-data.mk files
 
 include rules/build-package-data.mk
 # Build package-data.mk files
 
 include rules/build-package-data.mk
@@ -428,7 +467,7 @@ endef
 $(eval $(call foreachLibrary,addExtraPackage))
 endif
 
 $(eval $(call foreachLibrary,addExtraPackage))
 endif
 
-# If we want to just install evreything, then we want all the packages
+# If we want to just install everything, then we want all the packages
 SUPERSIZE_INSTALL_PACKAGES := $(addprefix libraries/,$(PACKAGES_STAGE1))
 ifeq "$(Stage1Only)" "NO"
 SUPERSIZE_INSTALL_PACKAGES += compiler
 SUPERSIZE_INSTALL_PACKAGES := $(addprefix libraries/,$(PACKAGES_STAGE1))
 ifeq "$(Stage1Only)" "NO"
 SUPERSIZE_INSTALL_PACKAGES += compiler
@@ -438,7 +477,7 @@ SUPERSIZE_INSTALL_PACKAGES += $(addprefix libraries/,$(PACKAGES_STAGE2))
 INSTALL_DYNLIBS  :=
 ifeq "$(InstallExtraPackages)" "NO"
 INSTALL_PACKAGES := $(REGULAR_INSTALL_PACKAGES)
 INSTALL_DYNLIBS  :=
 ifeq "$(InstallExtraPackages)" "NO"
 INSTALL_PACKAGES := $(REGULAR_INSTALL_PACKAGES)
-ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
+ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
 INSTALL_DYNLIBS := $(REGULAR_INSTALL_DYNLIBS)
 endif
 else
 INSTALL_DYNLIBS := $(REGULAR_INSTALL_DYNLIBS)
 endif
 else
@@ -485,6 +524,7 @@ utils/ghc-pwd/dist-install/package-data.mk: compiler/stage2/package-data.mk
 utils/ghc-cabal/dist-install/package-data.mk: compiler/stage2/package-data.mk
 
 utils/ghctags/dist-install/package-data.mk: compiler/stage2/package-data.mk
 utils/ghc-cabal/dist-install/package-data.mk: compiler/stage2/package-data.mk
 
 utils/ghctags/dist-install/package-data.mk: compiler/stage2/package-data.mk
+utils/dll-split/dist-install/package-data.mk: compiler/stage2/package-data.mk
 utils/hpc/dist-install/package-data.mk: compiler/stage2/package-data.mk
 utils/ghc-pkg/dist-install/package-data.mk: compiler/stage2/package-data.mk
 utils/hsc2hs/dist-install/package-data.mk: compiler/stage2/package-data.mk
 utils/hpc/dist-install/package-data.mk: compiler/stage2/package-data.mk
 utils/ghc-pkg/dist-install/package-data.mk: compiler/stage2/package-data.mk
 utils/hsc2hs/dist-install/package-data.mk: compiler/stage2/package-data.mk
@@ -493,12 +533,17 @@ utils/runghc/dist-install/package-data.mk: compiler/stage2/package-data.mk
 utils/mkUserGuidePart/dist/package-data.mk: compiler/stage2/package-data.mk
 
 # add the final package.conf dependency: ghc-prim depends on RTS
 utils/mkUserGuidePart/dist/package-data.mk: compiler/stage2/package-data.mk
 
 # add the final package.conf dependency: ghc-prim depends on RTS
-libraries/ghc-prim/dist-install/package-data.mk : rts/package.conf.inplace
+libraries/ghc-prim/dist-install/package-data.mk : rts/dist/package.conf.inplace
 endif
 
 # --------------------------------
 # Misc package-related settings
 
 endif
 
 # --------------------------------
 # Misc package-related settings
 
+# Run Haddock for the packages that will be installed. We need to handle
+# compiler specially due to the different dist directory name.
+$(foreach p,$(INSTALL_PACKAGES),$(eval $p_dist-install_DO_HADDOCK = YES))
+compiler_stage2_DO_HADDOCK = YES
+
 BOOT_PKG_CONSTRAINTS := \
     $(foreach d,$(PACKAGES_STAGE0),\
         $(foreach p,$(basename $(notdir $(wildcard libraries/$d/*.cabal))),\
 BOOT_PKG_CONSTRAINTS := \
     $(foreach d,$(PACKAGES_STAGE0),\
         $(foreach p,$(basename $(notdir $(wildcard libraries/$d/*.cabal))),\
@@ -511,24 +556,6 @@ ALL_STAGE1_LIBS += $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-inst
 endif
 BOOT_LIBS = $(foreach lib,$(PACKAGES_STAGE0),$(libraries/$(lib)_dist-boot_v_LIB))
 
 endif
 BOOT_LIBS = $(foreach lib,$(PACKAGES_STAGE0),$(libraries/$(lib)_dist-boot_v_LIB))
 
-# -----------------------------------------------
-# Haddock-related bits
-
-# Run Haddock for the packages that will be installed. We need to handle
-# compiler specially due to the different dist directory name.
-$(foreach p,$(INSTALL_PACKAGES),$(eval $p_dist-install_DO_HADDOCK = YES))
-compiler_stage2_DO_HADDOCK = YES
-
-# Build the Haddock contents and index
-ifeq "$(HADDOCK_DOCS)" "YES"
-libraries/dist-haddock/index.html: inplace/bin/haddock$(exeext) $(ALL_HADDOCK_FILES)
-       cd libraries && sh gen_contents_index --intree
-ifeq "$(phase)" "final"
-$(eval $(call all-target,library_doc_index,libraries/dist-haddock/index.html))
-endif
-INSTALL_LIBRARY_DOCS += libraries/dist-haddock/*
-endif
-
 # ----------------------------------------
 # Special magic for the ghc-prim package
 
 # ----------------------------------------
 # Special magic for the ghc-prim package
 
@@ -568,18 +595,6 @@ $(error Unknown integer library: $(INTEGER_LIBRARY))
 endif
 endif
 
 endif
 endif
 
-# ----------------------------------------
-# Workarounds for problems building DLLs on Windows
-
-ifeq "$(TargetOS_CPP)" "mingw32"
-# We don't build the GHC package the dyn way on Windows, so
-# we can't build these packages the dyn way either. See trac #5987
-libraries/dph/dph-lifted-base_dist-install_EXCLUDED_WAYS := dyn
-libraries/dph/dph-lifted-boxed_dist-install_EXCLUDED_WAYS := dyn
-libraries/dph/dph-lifted-copy_dist-install_EXCLUDED_WAYS := dyn
-libraries/dph/dph-lifted-vseg_dist-install_EXCLUDED_WAYS := dyn
-endif
-
 # -----------------------------------------------------------------------------
 # Include build instructions from all subdirs
 
 # -----------------------------------------------------------------------------
 # Include build instructions from all subdirs
 
@@ -591,8 +606,6 @@ ifeq "$(Windows_Host)" "YES"
 BUILD_DIRS += utils/touchy
 endif
 
 BUILD_DIRS += utils/touchy
 endif
 
-BUILD_DIRS += docs/users_guide
-BUILD_DIRS += docs/man
 BUILD_DIRS += utils/unlit
 BUILD_DIRS += utils/hp2ps
 
 BUILD_DIRS += utils/unlit
 BUILD_DIRS += utils/hp2ps
 
@@ -609,6 +622,7 @@ BUILD_DIRS += driver/ghci
 BUILD_DIRS += driver/ghc
 BUILD_DIRS += driver/haddock
 BUILD_DIRS += libffi
 BUILD_DIRS += driver/ghc
 BUILD_DIRS += driver/haddock
 BUILD_DIRS += libffi
+BUILD_DIRS += utils/deriveConstants
 BUILD_DIRS += includes
 BUILD_DIRS += rts
 
 BUILD_DIRS += includes
 BUILD_DIRS += rts
 
@@ -632,18 +646,10 @@ endif
 
 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
 BUILD_DIRS += libraries/integer-gmp/gmp
 
 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
 BUILD_DIRS += libraries/integer-gmp/gmp
+BUILD_DIRS += libraries/integer-gmp/mkGmpDerivedConstants
 else ifneq "$(findstring clean,$(MAKECMDGOALS))" ""
 BUILD_DIRS += libraries/integer-gmp/gmp
 else ifneq "$(findstring clean,$(MAKECMDGOALS))" ""
 BUILD_DIRS += libraries/integer-gmp/gmp
-endif
-
-ifeq "$(CrossCompiling)-$(phase)" "YES-final"
-MAYBE_GHCTAGS=
-MAYBE_HPC=
-MAYBE_RUNGHC=
-else
-MAYBE_GHCTAGS=utils/ghctags
-MAYBE_HPC=utils/hpc
-MAYBE_RUNGHC=utils/runghc
+BUILD_DIRS += libraries/integer-gmp/mkGmpDerivedConstants
 endif
 
 BUILD_DIRS += utils/haddock
 endif
 
 BUILD_DIRS += utils/haddock
@@ -651,13 +657,15 @@ BUILD_DIRS += utils/haddock/doc
 BUILD_DIRS += compiler
 BUILD_DIRS += utils/hsc2hs
 BUILD_DIRS += utils/ghc-pkg
 BUILD_DIRS += compiler
 BUILD_DIRS += utils/hsc2hs
 BUILD_DIRS += utils/ghc-pkg
-BUILD_DIRS += utils/deriveConstants
 BUILD_DIRS += utils/testremove
 BUILD_DIRS += utils/testremove
-BUILD_DIRS += $(MAYBE_GHCTAGS)
+ifeq "$(Stage1Only)" "NO"
+BUILD_DIRS += utils/ghctags
+endif
+BUILD_DIRS += utils/dll-split
 BUILD_DIRS += utils/ghc-pwd
 BUILD_DIRS += utils/ghc-cabal
 BUILD_DIRS += utils/ghc-pwd
 BUILD_DIRS += utils/ghc-cabal
-BUILD_DIRS += $(MAYBE_HPC)
-BUILD_DIRS += $(MAYBE_RUNGHC)
+BUILD_DIRS += utils/hpc
+BUILD_DIRS += utils/runghc
 BUILD_DIRS += ghc
 
 ifneq "$(BINDIST)" "YES"
 BUILD_DIRS += ghc
 
 ifneq "$(BINDIST)" "YES"
@@ -666,6 +674,8 @@ BUILD_DIRS += utils/mkUserGuidePart
 endif
 endif
 
 endif
 endif
 
+BUILD_DIRS += docs/users_guide
+BUILD_DIRS += docs/man
 BUILD_DIRS += utils/count_lines
 BUILD_DIRS += utils/compare_sizes
 
 BUILD_DIRS += utils/count_lines
 BUILD_DIRS += utils/compare_sizes
 
@@ -708,7 +718,7 @@ $(shell echo "[]" >$(BOOTSTRAPPING_CONF))
 endif
 endif
 
 endif
 endif
 
-$(eval $(call clean-target,$(BOOTSTRAPPING_CONF),,$(BOOTSTRAPPING_CONF)))
+$(eval $(call clean-target,root,bootstrapping_conf,$(BOOTSTRAPPING_CONF)))
 
 # register the boot packages in strict sequence, because running
 # multiple ghc-pkgs in parallel doesn't work (registrations may get
 
 # register the boot packages in strict sequence, because running
 # multiple ghc-pkgs in parallel doesn't work (registrations may get
@@ -722,7 +732,7 @@ endif
 ifneq "$(BINDIST)" "YES"
 # Make sure we have all the GHCi libs by the time we've built
 # ghc-stage2.  DPH includes a bit of Template Haskell which needs the
 ifneq "$(BINDIST)" "YES"
 # Make sure we have all the GHCi libs by the time we've built
 # ghc-stage2.  DPH includes a bit of Template Haskell which needs the
-# GHCI libs, and we don't have a better way to express that dependency.
+# GHCi libs, and we don't have a better way to express that dependency.
 #
 GHCI_LIBS = $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_GHCI_LIB)) \
            $(compiler_stage2_GHCI_LIB)
 #
 GHCI_LIBS = $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_GHCI_LIB)) \
            $(compiler_stage2_GHCI_LIB)
@@ -744,6 +754,19 @@ libraries/vector/dist-install/build/Data/Vector/Fusion/Stream/Monadic.$($(way)_o
   ))
 endif
 
   ))
 endif
 
+# -----------------------------------------------
+# Haddock-related bits
+
+# Build the Haddock contents and index
+ifeq "$(HADDOCK_DOCS)" "YES"
+libraries/dist-haddock/index.html: $(haddock_INPLACE) $(ALL_HADDOCK_FILES)
+       cd libraries && sh gen_contents_index --intree
+ifeq "$(phase)" "final"
+$(eval $(call all-target,library_doc_index,libraries/dist-haddock/index.html))
+endif
+INSTALL_LIBRARY_DOCS += libraries/dist-haddock/*
+endif
+
 # -----------------------------------------------------------------------------
 # Creating a local mingw copy on Windows
 
 # -----------------------------------------------------------------------------
 # Creating a local mingw copy on Windows
 
@@ -794,7 +817,7 @@ define installLibsTo
                case $$i in \
                  *.a) \
                    $(call INSTALL_DATA,$(INSTALL_OPTS),$$i,$2); \
                case $$i in \
                  *.a) \
                    $(call INSTALL_DATA,$(INSTALL_OPTS),$$i,$2); \
-                   $(RANLIB) $2/`basename $$i` ;; \
+                   $(RANLIB_CMD) $2/`basename $$i` ;; \
                  *.dll) \
                    $(call INSTALL_PROGRAM,$(INSTALL_OPTS),$$i,$2) ; \
                    $(STRIP_CMD) $2/`basename $$i` ;; \
                  *.dll) \
                    $(call INSTALL_PROGRAM,$(INSTALL_OPTS),$$i,$2) ; \
                    $(STRIP_CMD) $2/`basename $$i` ;; \
@@ -879,31 +902,31 @@ INSTALL_DISTDIR_compiler = stage2
 
 # Now we can do the installation
 install_packages: install_libexecs
 
 # Now we can do the installation
 install_packages: install_libexecs
-install_packages: rts/package.conf.install
+install_packages: rts/dist/package.conf.install
        $(call INSTALL_DIR,"$(DESTDIR)$(topdir)")
        $(call removeTrees,"$(INSTALLED_PACKAGE_CONF)")
        $(call INSTALL_DIR,"$(INSTALLED_PACKAGE_CONF)")
        $(call INSTALL_DIR,"$(DESTDIR)$(topdir)/rts-1.0")
        $(call installLibsTo, $(RTS_INSTALL_LIBS), "$(DESTDIR)$(topdir)/rts-1.0")
        $(foreach p, $(INSTALL_DYNLIBS), \
        $(call INSTALL_DIR,"$(DESTDIR)$(topdir)")
        $(call removeTrees,"$(INSTALLED_PACKAGE_CONF)")
        $(call INSTALL_DIR,"$(INSTALLED_PACKAGE_CONF)")
        $(call INSTALL_DIR,"$(DESTDIR)$(topdir)/rts-1.0")
        $(call installLibsTo, $(RTS_INSTALL_LIBS), "$(DESTDIR)$(topdir)/rts-1.0")
        $(foreach p, $(INSTALL_DYNLIBS), \
-           $(call installLibsTo, $(wildcard libraries/$p/dist-install/build/*.so libraries/$p/dist-install/build/*.dll libraries/$p/dist-install/build/*.dylib), "$(DESTDIR)$(topdir)/$p-$(libraries/$p_dist-install_VERSION)"))
+           $(call installLibsTo, $(wildcard $p/dist-install/build/*.so $p/dist-install/build/*.dll $p/dist-install/build/*.dylib), "$(DESTDIR)$(topdir)/$($p_PACKAGE)-$($p_dist-install_VERSION)"))
        $(foreach p, $(INSTALL_PACKAGES),                             \
            $(call make-command,                                      \
                   "$(ghc-cabal_INPLACE)" copy                        \
        $(foreach p, $(INSTALL_PACKAGES),                             \
            $(call make-command,                                      \
                   "$(ghc-cabal_INPLACE)" copy                        \
-                                         "$(STRIP_CMD)"              \
                                          $p $(INSTALL_DISTDIR_$p)    \
                                          $p $(INSTALL_DISTDIR_$p)    \
+                                         "$(STRIP_CMD)"              \
                                          '$(DESTDIR)'                \
                                          '$(prefix)'                 \
                                          '$(ghclibdir)'              \
                                          '$(docdir)/html/libraries'))
                                          '$(DESTDIR)'                \
                                          '$(prefix)'                 \
                                          '$(ghclibdir)'              \
                                          '$(docdir)/html/libraries'))
-       "$(INSTALLED_GHC_PKG_REAL)" --force --global-package-db "$(INSTALLED_PACKAGE_CONF)" update rts/package.conf.install
+       "$(INSTALLED_GHC_PKG_REAL)" --force --global-package-db "$(INSTALLED_PACKAGE_CONF)" update rts/dist/package.conf.install
        $(foreach p, $(INSTALL_PACKAGES),                             \
            $(call make-command,                                      \
                   "$(ghc-cabal_INPLACE)" register                    \
        $(foreach p, $(INSTALL_PACKAGES),                             \
            $(call make-command,                                      \
                   "$(ghc-cabal_INPLACE)" register                    \
+                                         $p $(INSTALL_DISTDIR_$p)    \
                                          "$(INSTALLED_GHC_REAL)"     \
                                          "$(INSTALLED_GHC_PKG_REAL)" \
                                          "$(DESTDIR)$(topdir)"       \
                                          "$(INSTALLED_GHC_REAL)"     \
                                          "$(INSTALLED_GHC_PKG_REAL)" \
                                          "$(DESTDIR)$(topdir)"       \
-                                         $p $(INSTALL_DISTDIR_$p)    \
                                          '$(DESTDIR)'                \
                                          '$(prefix)'                 \
                                          '$(ghclibdir)'              \
                                          '$(DESTDIR)'                \
                                          '$(prefix)'                 \
                                          '$(ghclibdir)'              \
@@ -990,20 +1013,13 @@ unix-binary-dist-prep:
        $(call removeFiles,$(BIN_DIST_PREP_TAR))
 # h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
 # tree then we want to include the real file, not a symlink to it
        $(call removeFiles,$(BIN_DIST_PREP_TAR))
 # h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
 # tree then we want to include the real file, not a symlink to it
-       cd bindistprep && "$(TAR_CMD)" hcf - -T ../$(BIN_DIST_LIST) | bzip2 -c > ../$(BIN_DIST_PREP_TAR_BZ2)
+       cd bindistprep && "$(TAR_CMD)" hcf - -T ../bindist-list | bzip2 -c > ../$(BIN_DIST_PREP_TAR_BZ2)
 
 windows-binary-dist-prep:
        $(call removeTrees,bindistprep/)
        $(MAKE) prefix=$(TOP)/$(BIN_DIST_PREP_DIR) install
        cd bindistprep && "$(TAR_CMD)" cf - $(BIN_DIST_NAME) | bzip2 -c > ../$(BIN_DIST_PREP_TAR_BZ2)
 
 
 windows-binary-dist-prep:
        $(call removeTrees,bindistprep/)
        $(MAKE) prefix=$(TOP)/$(BIN_DIST_PREP_DIR) install
        cd bindistprep && "$(TAR_CMD)" cf - $(BIN_DIST_NAME) | bzip2 -c > ../$(BIN_DIST_PREP_TAR_BZ2)
 
-windows-installer:
-ifeq "$(ISCC_CMD)" ""
-       @echo No ISCC_CMD, so not making installer
-else
-       "$(ISCC_CMD)" /O. /Fbindistprep/$(WINDOWS_INSTALLER_BASE) - < distrib/ghc.iss
-endif
-
 # tryTimes tries to run its third argument multiple times, until it
 # succeeds. Don't call it directly; call try10Times instead.
 # The first and second argument to tryTimes are lists of values.
 # tryTimes tries to run its third argument multiple times, until it
 # succeeds. Don't call it directly; call try10Times instead.
 # The first and second argument to tryTimes are lists of values.
@@ -1021,9 +1037,6 @@ try10Times = $(call tryTimes,,x x x x x x x x x x,$1) { echo Failed; false; }
 .PHONY: publish-binary-dist
 publish-binary-dist:
        $(call try10Times,$(PublishCp) $(BIN_DIST_TAR_BZ2) $(PublishLocation)/dist)
 .PHONY: publish-binary-dist
 publish-binary-dist:
        $(call try10Times,$(PublishCp) $(BIN_DIST_TAR_BZ2) $(PublishLocation)/dist)
-ifeq "$(mingw32_TARGET_OS)" "1"
-       $(call try10Times,$(PublishCp) $(WINDOWS_INSTALLER) $(PublishLocation)/dist)
-endif
 
 ifeq "$(mingw32_TARGET_OS)" "1"
 DOCDIR_TO_PUBLISH = $(BIN_DIST_INST_DIR)/doc
 
 ifeq "$(mingw32_TARGET_OS)" "1"
 DOCDIR_TO_PUBLISH = $(BIN_DIST_INST_DIR)/doc
@@ -1045,7 +1058,7 @@ publish-docs:
 #
 
 # A source dist is built from a complete build tree, because we
 #
 
 # A source dist is built from a complete build tree, because we
-# require some extra files not contained in a darcs checkout: the
+# require some extra files not contained in a git checkout: the
 # output from Happy and Alex, for example.
 #
 # The steps performed by 'make dist' are as follows:
 # output from Happy and Alex, for example.
 #
 # The steps performed by 'make dist' are as follows:
@@ -1060,26 +1073,31 @@ publish-docs:
 SRC_DIST_ROOT      = sdistprep
 SRC_DIST_BASE_NAME = ghc-$(ProjectVersion)
 
 SRC_DIST_ROOT      = sdistprep
 SRC_DIST_BASE_NAME = ghc-$(ProjectVersion)
 
-SRC_DIST_GHC_NAME          = ghc-$(ProjectVersion)-src
-SRC_DIST_GHC_ROOT          = $(SRC_DIST_ROOT)/ghc
-SRC_DIST_GHC_DIR           = $(SRC_DIST_GHC_ROOT)/$(SRC_DIST_BASE_NAME)
-SRC_DIST_GHC_TARBALL       = $(SRC_DIST_ROOT)/$(SRC_DIST_GHC_NAME).tar.bz2
+SRC_DIST_GHC_NAME                 = ghc-$(ProjectVersion)-src
+SRC_DIST_GHC_ROOT                 = $(SRC_DIST_ROOT)/ghc
+SRC_DIST_GHC_DIR                  = $(SRC_DIST_GHC_ROOT)/$(SRC_DIST_BASE_NAME)
+SRC_DIST_GHC_TARBALL              = $(SRC_DIST_ROOT)/$(SRC_DIST_GHC_NAME).tar.bz2
 
 
-SRC_DIST_TESTSUITE_NAME    = ghc-$(ProjectVersion)-testsuite
-SRC_DIST_TESTSUITE_ROOT    = $(SRC_DIST_ROOT)/testsuite-ghc
-SRC_DIST_TESTSUITE_DIR     = $(SRC_DIST_TESTSUITE_ROOT)/$(SRC_DIST_BASE_NAME)
-SRC_DIST_TESTSUITE_TARBALL = $(SRC_DIST_ROOT)/$(SRC_DIST_TESTSUITE_NAME).tar.bz2
+SRC_DIST_WINDOWS_TARBALLS_NAME    = ghc-$(ProjectVersion)-windows-extra-src
+SRC_DIST_WINDOWS_TARBALLS_ROOT    = $(SRC_DIST_ROOT)/windows-tarballs
+SRC_DIST_WINDOWS_TARBALLS_DIR     = $(SRC_DIST_WINDOWS_TARBALLS_ROOT)/$(SRC_DIST_BASE_NAME)
+SRC_DIST_WINDOWS_TARBALLS_TARBALL = $(SRC_DIST_ROOT)/$(SRC_DIST_WINDOWS_TARBALLS_NAME).tar.bz2
+
+SRC_DIST_TESTSUITE_NAME           = ghc-$(ProjectVersion)-testsuite
+SRC_DIST_TESTSUITE_ROOT           = $(SRC_DIST_ROOT)/testsuite-ghc
+SRC_DIST_TESTSUITE_DIR            = $(SRC_DIST_TESTSUITE_ROOT)/$(SRC_DIST_BASE_NAME)
+SRC_DIST_TESTSUITE_TARBALL        = $(SRC_DIST_ROOT)/$(SRC_DIST_TESTSUITE_NAME).tar.bz2
 
 #
 # Files to include in source distributions
 #
 SRC_DIST_GHC_DIRS = mk rules docs distrib bindisttest libffi includes \
 
 #
 # Files to include in source distributions
 #
 SRC_DIST_GHC_DIRS = mk rules docs distrib bindisttest libffi includes \
-    utils docs rts compiler ghc driver libraries ghc-tarballs
+    utils docs rts compiler ghc driver libraries libffi-tarballs
 SRC_DIST_GHC_FILES += \
     configure.ac config.guess config.sub configure \
     aclocal.m4 README ANNOUNCE HACKING LICENSE Makefile install-sh \
 SRC_DIST_GHC_FILES += \
     configure.ac config.guess config.sub configure \
     aclocal.m4 README ANNOUNCE HACKING LICENSE Makefile install-sh \
-    ghc.spec.in ghc.spec settings.in VERSION \
-    boot boot-pkgs packages ghc.mk
+    settings.in VERSION \
+    boot packages ghc.mk
 
 VERSION :
        echo $(ProjectVersion) >VERSION
 
 VERSION :
        echo $(ProjectVersion) >VERSION
@@ -1121,6 +1139,17 @@ sdist-ghc-prep :
        $(call sdist_ghc_file,utils/haddock,dist,src,Haddock,Parse,y)
        cd $(SRC_DIST_GHC_DIR) && "$(FIND)" $(SRC_DIST_GHC_DIRS) \( -name .git -o -name "autom4te*" -o -name "*~" -o -name "\#*" -o -name ".\#*" -o -name "log" -o -name "*-SAVE" -o -name "*.orig" -o -name "*.rej" \) -print | "$(XARGS)" $(XARGS_OPTS) "$(RM)" $(RM_OPTS_REC)
 
        $(call sdist_ghc_file,utils/haddock,dist,src,Haddock,Parse,y)
        cd $(SRC_DIST_GHC_DIR) && "$(FIND)" $(SRC_DIST_GHC_DIRS) \( -name .git -o -name "autom4te*" -o -name "*~" -o -name "\#*" -o -name ".\#*" -o -name "log" -o -name "*-SAVE" -o -name "*.orig" -o -name "*.rej" \) -print | "$(XARGS)" $(XARGS_OPTS) "$(RM)" $(RM_OPTS_REC)
 
+.PHONY: sdist-windows-tarballs-prep
+sdist-windows-tarballs-prep :
+       $(call removeTrees,$(SRC_DIST_WINDOWS_TARBALLS_ROOT))
+       $(call removeFiles,$(SRC_DIST_WINDOWS_TARBALLS_TARBALL))
+       -mkdir $(SRC_DIST_ROOT)
+       mkdir $(SRC_DIST_WINDOWS_TARBALLS_ROOT)
+       mkdir $(SRC_DIST_WINDOWS_TARBALLS_DIR)
+       mkdir $(SRC_DIST_WINDOWS_TARBALLS_DIR)/ghc-tarballs
+       cd $(SRC_DIST_WINDOWS_TARBALLS_DIR)/ghc-tarballs && lndir $(TOP)/ghc-tarballs
+       $(call removeTrees,$(SRC_DIST_WINDOWS_TARBALLS_DIR)/ghc-tarballs/.git)
+
 .PHONY: sdist-testsuite-prep
 sdist-testsuite-prep :
        $(call removeTrees,$(SRC_DIST_TESTSUITE_ROOT))
 .PHONY: sdist-testsuite-prep
 sdist-testsuite-prep :
        $(call removeTrees,$(SRC_DIST_TESTSUITE_ROOT))
@@ -1133,9 +1162,10 @@ sdist-testsuite-prep :
        $(call removeTrees,$(SRC_DIST_TESTSUITE_DIR)/testsuite/.git)
 
 .PHONY: sdist
        $(call removeTrees,$(SRC_DIST_TESTSUITE_DIR)/testsuite/.git)
 
 .PHONY: sdist
-sdist : sdist-ghc-prep sdist-testsuite-prep
-       cd $(SRC_DIST_GHC_ROOT) && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> src_ghc_log | bzip2 > $(TOP)/$(SRC_DIST_GHC_TARBALL)
-       cd $(SRC_DIST_TESTSUITE_ROOT) && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> src_ghc_log | bzip2 > $(TOP)/$(SRC_DIST_TESTSUITE_TARBALL)
+sdist : sdist-ghc-prep sdist-windows-tarballs-prep sdist-testsuite-prep
+       cd $(SRC_DIST_GHC_ROOT)              && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> src_ghc_log               | bzip2 > $(TOP)/$(SRC_DIST_GHC_TARBALL)
+       cd $(SRC_DIST_WINDOWS_TARBALLS_ROOT) && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> windows_extra_src_ghc_log | bzip2 > $(TOP)/$(SRC_DIST_WINDOWS_TARBALLS_TARBALL)
+       cd $(SRC_DIST_TESTSUITE_ROOT)        && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> testsuite_log             | bzip2 > $(TOP)/$(SRC_DIST_TESTSUITE_TARBALL)
 
 sdist-manifest : $(SRC_DIST_GHC_TARBALL)
        tar tjf $(SRC_DIST_GHC_TARBALL) | sed "s|^ghc-$(ProjectVersion)/||" | sort >sdist-manifest
 
 sdist-manifest : $(SRC_DIST_GHC_TARBALL)
        tar tjf $(SRC_DIST_GHC_TARBALL) | sed "s|^ghc-$(ProjectVersion)/||" | sort >sdist-manifest
@@ -1214,26 +1244,64 @@ clean_bindistprep:
        $(call removeTrees,bindistprep/)
 
 distclean : clean
        $(call removeTrees,bindistprep/)
 
 distclean : clean
-       $(call removeFiles,config.cache config.status config.log mk/config.h mk/stamp-h)
-       $(call removeFiles,mk/config.mk mk/are-validating.mk mk/project.mk)
-       $(call removeFiles,mk/config.mk.old mk/project.mk.old)
-       $(call removeFiles,settings docs/users_guide/ug-book.xml)
-       $(call removeFiles,compiler/ghc.cabal compiler/ghc.cabal.old)
+# Clean the files that ./validate creates.
+       $(call removeFiles,mk/are-validating.mk)
+
+# Clean the files that we ask ./configure to create.
+       $(call removeFiles,mk/config.mk)
+       $(call removeFiles,mk/install.mk)
+       $(call removeFiles,mk/project.mk)
+       $(call removeFiles,compiler/ghc.cabal)
        $(call removeFiles,ghc/ghc-bin.cabal)
        $(call removeFiles,ghc/ghc-bin.cabal)
+       $(call removeFiles,utils/runghc/runghc.cabal)
+       $(call removeFiles,settings)
+       $(call removeFiles,docs/users_guide/ug-book.xml)
+       $(call removeFiles,docs/users_guide/ug-ent.xml)
+       $(call removeFiles,docs/index.html)
+       $(call removeFiles,libraries/prologue.txt)
+       $(call removeFiles,distrib/configure.ac)
+
+# ./configure also makes these.
+       $(call removeFiles,mk/config.h)
+
+# Internal files generated by ./configure for itself.
+       $(call removeFiles,config.cache config.status config.log)
+
+# ./configure build ghc-pwd in utils/ghc-pwd/dist-boot, so clean it up.
+       $(call removeTrees,utils/ghc-pwd/dist-boot)
+
+# The root Makefile makes .old versions of some files that configure
+# generates, so we clean those too.
+       $(call removeFiles,mk/config.mk.old)
+       $(call removeFiles,mk/project.mk.old)
+       $(call removeFiles,compiler/ghc.cabal.old)
+
+# Clean the *Config.h files generated by library configure scripts
        $(call removeFiles,libraries/base/include/HsBaseConfig.h)
        $(call removeFiles,libraries/base/include/HsBaseConfig.h)
+       $(call removeFiles,libraries/base/include/EventConfig.h)
        $(call removeFiles,libraries/directory/include/HsDirectoryConfig.h)
        $(call removeFiles,libraries/process/include/HsProcessConfig.h)
        $(call removeFiles,libraries/unix/include/HsUnixConfig.h)
        $(call removeFiles,libraries/directory/include/HsDirectoryConfig.h)
        $(call removeFiles,libraries/process/include/HsProcessConfig.h)
        $(call removeFiles,libraries/unix/include/HsUnixConfig.h)
+       $(call removeFiles,libraries/time/include/HsTimeConfig.h)
        $(call removeFiles,libraries/old-time/include/HsTimeConfig.h)
        $(call removeFiles,libraries/old-time/include/HsTimeConfig.h)
-       $(call removeTrees,utils/ghc-pwd/dist-boot)
+
+# The library configure scripts also like creating autom4te.cache
+# directories, so clean them all up.
+       $(call removeTrees,$(patsubst %, libraries/%/autom4te.cache, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
+
+# We make these when making or testing bindists
+       $(call removeFiles,bindist-list)
+       $(call removeTrees,bindisttest/a)
+
+# Not sure why this is being cleaned here.
        $(call removeTrees,includes/dist-derivedconstants)
        $(call removeTrees,includes/dist-derivedconstants)
+
+# Finally, clean the inplace tree.
        $(call removeTrees,inplace)
        $(call removeTrees,inplace)
-       $(call removeTrees,$(patsubst %, libraries/%/autom4te.cache, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
 
 maintainer-clean : distclean
        $(call removeFiles,configure mk/config.h.in)
        $(call removeTrees,autom4te.cache $(wildcard libraries/*/autom4te.cache))
 
 maintainer-clean : distclean
        $(call removeFiles,configure mk/config.h.in)
        $(call removeTrees,autom4te.cache $(wildcard libraries/*/autom4te.cache))
-       $(call removeFiles,ghc.spec)
        $(call removeFiles,$(patsubst %, libraries/%/GNUmakefile, \
                $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
        $(call removeFiles,$(patsubst %, libraries/%/ghc.mk, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
        $(call removeFiles,$(patsubst %, libraries/%/GNUmakefile, \
                $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
        $(call removeFiles,$(patsubst %, libraries/%/ghc.mk, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
@@ -1243,6 +1311,7 @@ maintainer-clean : distclean
        $(call removeFiles,libraries/directory/include/HsDirectoryConfig.h.in)
        $(call removeFiles,libraries/process/include/HsProcessConfig.h.in)
        $(call removeFiles,libraries/unix/include/HsUnixConfig.h.in)
        $(call removeFiles,libraries/directory/include/HsDirectoryConfig.h.in)
        $(call removeFiles,libraries/process/include/HsProcessConfig.h.in)
        $(call removeFiles,libraries/unix/include/HsUnixConfig.h.in)
+       $(call removeFiles,libraries/time/include/HsTimeConfig.h.in)
        $(call removeFiles,libraries/old-time/include/HsTimeConfig.h.in)
 
 .PHONY: all_libraries
        $(call removeFiles,libraries/old-time/include/HsTimeConfig.h.in)
 
 .PHONY: all_libraries
@@ -1260,7 +1329,7 @@ bootstrapping-files: $(libffi_HEADERS)
 ifeq "$(HADDOCK_DOCS)" "YES"
 BINDIST_HADDOCK_FLAG = --with-haddock="$(BINDIST_PREFIX)/bin/haddock"
 endif
 ifeq "$(HADDOCK_DOCS)" "YES"
 BINDIST_HADDOCK_FLAG = --with-haddock="$(BINDIST_PREFIX)/bin/haddock"
 endif
-ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
+ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
 BINDIST_LIBRARY_FLAGS = --enable-shared --disable-library-vanilla
 else
 BINDIST_LIBRARY_FLAGS = --enable-library-vanilla --disable-shared
 BINDIST_LIBRARY_FLAGS = --enable-shared --disable-library-vanilla
 else
 BINDIST_LIBRARY_FLAGS = --enable-library-vanilla --disable-shared
@@ -1282,13 +1351,26 @@ endif
 # -----------------------------------------------------------------------------
 # Numbered phase targets
 
 # -----------------------------------------------------------------------------
 # Numbered phase targets
 
+# In phase 1, we'll be building dependency files for most things
+# built by the bootstrapping compiler while make is 'include'ing
+# makefiles. But in order to build dependency files, we'll need to
+# build any automatically generated .hs files, which means that
+# we'll need to be able to build any tools that generate .hs files
+# etc. But in order to do that, we need to already know the
+# dependencies for those tools, so we build their dependency files
+# here.
 .PHONY: phase_0_builds
 .PHONY: phase_0_builds
-phase_0_builds: $(utils/ghc-pkg_dist_depfile_haskell)
-phase_0_builds: $(utils/ghc-pkg_dist_depfile_c_asm)
+# hsc2hs is needed, e.g. to make the .hs files for hpc.
 phase_0_builds: $(utils/hsc2hs_dist_depfile_haskell)
 phase_0_builds: $(utils/hsc2hs_dist_depfile_c_asm)
 phase_0_builds: $(utils/hsc2hs_dist_depfile_haskell)
 phase_0_builds: $(utils/hsc2hs_dist_depfile_c_asm)
+# genprimopcode is needed to make the .hs-incl files that are in the
+# ghc package.
 phase_0_builds: $(utils/genprimopcode_dist_depfile_haskell)
 phase_0_builds: $(utils/genprimopcode_dist_depfile_c_asm)
 phase_0_builds: $(utils/genprimopcode_dist_depfile_haskell)
 phase_0_builds: $(utils/genprimopcode_dist_depfile_c_asm)
+# deriveConstants is used to create header files included in the
+# ghc package.
+phase_0_builds: $(utils/deriveConstants_dist_depfile_haskell)
+phase_0_builds: $(utils/deriveConstants_dist_depfile_c_asm)
 
 .PHONY: phase_1_builds
 phase_1_builds: $(PACKAGE_DATA_MKS)
 
 .PHONY: phase_1_builds
 phase_1_builds: $(PACKAGE_DATA_MKS)