+# 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
+
+# --------------------------------
+# Subsets of packages
+
+# Packages that are built but not installed
+INTREE_ONLY_PACKAGES := haskeline mtl terminfo utf8-string xhtml
+
+# 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/dph-base dph/dph-prim-interface dph/dph-prim-seq \
+ dph/dph-common dph/dph-prim-par dph/dph-par dph/dph-seq
+
+# 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
+
+# --------------------------------
+# Building the lists of packages
+
+# We need to build two lists:
+#
+# $(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