-include $(TOP)/ghc/mk/ghc.mk
-
-line = @echo "------------------------------------------------------------------------------"
-
-define BuildLibs
-$(line)
-@echo "Building Libraries"
-$(line)
-@$(MAKE) -C lib depend all
-endef
-
-define BuildCompiler
-$(line)
-@echo "Building Compiler"
-$(line)
-@$(MAKE) -C compiler depend all
-endef
-
-# dependencies:
-# everything needs utils
-# includes needs driver (for mkNativeGen.c)
-# make depend except in {utils,driver} needs includes
-# RTS and compiler need includes
-
-boot ::
- $(line)
- @echo "Building Utils"
- $(line)
- @$(MAKE) -C utils depend all
-
- $(line)
- @echo "Building Driver"
- $(line)
- @$(MAKE) -C driver all
-
- $(line)
- @echo "Building Includes"
- $(line)
- @$(MAKE) -C includes all
-
- $(line)
- @echo "Building Runtime System"
- $(line)
- @$(MAKE) -C runtime depend all
-
- $(line)
- @echo "Building Docs"
- $(line)
- @$(MAKE) -C docs depend all
-
-ifeq ($(HaskellCompilerType), HC_USE_HC_FILES)
- $(BuildLibs)
- $(BuildCompiler)
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/cabal-flags.mk
+
+ifeq "$(stage)" ""
+stage=1
+endif
+
+ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
+INSTALL_FLAGS =
+else
+INSTALL_FLAGS = --enable-shell-wrappers
+endif
+
+# Don't strip the inplace versions, we might need to debug them
+INPLACE_INSTALL_FLAGS += --disable-executable-stripping
+
+boot:: boot.stage.$(stage)
+
+all:: build.stage.$(stage)
+
+rebuild ::
+ -$(CABAL) clean --distpref dist-stage$(stage)
+ $(RM) -rf stage$(stage)-inplace
+ $(MAKE) boot all
+
+stage1 ::
+ $(MAKE) stage=1
+
+stage2 ::
+ $(MAKE) stage=2
+
+stage3 ::
+ $(MAKE) stage=3
+
+
+ifeq "$(CLEAN_ALL_STAGES)" "YES"
+clean distclean maintainer-clean:: clean.stage.1 clean.stage.2 clean.stage.3
+else
+clean distclean maintainer-clean:: clean.stage.$(stage)
+endif
+
+ifeq "$(CLEAN_ALL_STAGES)" "YES"
+distclean maintainer-clean::
+ $(RM) -f ghc-bin.cabal
+endif
+
+clean.stage.%:
+ $(RM) -rf stage$*-inplace
+# This is a bit naughty. We ought to use:
+# -$(CABAL) clean --distpref dist-stage$*
+# but that won't work if the Cabal file (a generated file) doesn't
+# exist. So we do this instead:
+ $(RM) -rf dist-stage$*
+
+CONFIGURE_FLAGS_STAGE1 += --flags=-ghci
+
+ifeq "$(GhcWithInterpreter)" "YES"
+CONFIGURE_FLAGS_STAGE2PLUS += --flags=ghci