+# Don't try to delete directories:
+.PRECIOUS: %/.
+
+# Create build directories on demand. NB. the | below: this indicates
+# that $(MKDIRHIER) is an order-only dependency, which means that this
+# rule fires after building mkdirhier, but we won't try to recreate
+# directories if mkdirhier changes.
+%/. : | $(MKDIRHIER)
+ "$(MKDIRHIER)" $@
+
+# -----------------------------------------------------------------------------
+# Packages
+
+# --------------------------------
+# Properties of packages
+# These lists say "if this package is built, here's a property it has"
+# They do not say "this package will be built"; see $(PACKAGES_xx) for that
+
+# Packages that are built but not installed
+INTREE_ONLY_PACKAGES := haskeline mtl terminfo utf8-string xhtml
+
+DPH_PACKAGES := dph/dph-base dph/dph-prim-interface dph/dph-prim-seq \
+ dph/dph-common dph/dph-prim-par dph/dph-par dph/dph-seq \
+ vector primitive
+
+# Packages that, if present, must be built by the stage2 compiler,
+# because they use TH and/or annotations, or depend on other stage2
+# packages:
+STAGE2_PACKAGES := $(DPH_PACKAGES) haskell98 haskell2010
+# Packages that we shouldn't build if we don't have TH (e.g. because
+# we're building a profiled compiler):
+TH_PACKAGES := $(DPH_PACKAGES)
+
+# Packages that are built by stage0, in addition to stage1. These
+# packages are dependencies of GHC, that we do not assume the stage0
+# compiler already has installed (or up-to-date enough).
+#
+# We assume that the stage0 compiler has a suitable bytestring package,
+# so we don't have to include it below.
+STAGE0_PACKAGES = Cabal hpc extensible-exceptions binary bin-package-db
+
+# These packages are installed, but are installed hidden
+# Why install them at all? Because the 'ghc' package depends on them
+HIDDEN_PACKAGES = binary
+
+# $(EXTRA_PACKAGES) is another classification, of packages built but
+# not installed
+# It is set in rules/extra-package.mk,
+# by $(call extra-packages) a little further down
+# this ghc.mk
+
+
+# --------------------------------
+# Packages to build
+# The lists of packages that we *actually* going to build in each stage:
+#
+# $(STAGE0_PACKAGE) does double duty; it really is the list of packages
+# we build the bootstrap compiler in stage 0
+#
+# $(PACKAGES) A list of directories relative to libraries/ containing
+# packages that will be built by stage1, in dependency
+# order.
+#
+# $(PACKAGES_STAGE2) Ditto, for stage2.
+#
+
+define addPackageGeneral
+# args: $1 = PACKAGES variable, $2 = package, $3 = condition
+ ifeq "$3" ""
+ $1 += $2
+ else