+# We need to turn on profiling either if we have been asked to
+# (GhcLibProfiled = YES) or if we want GHC itself to be compiled with
+# profiling enabled (GhcProfiled = YES).
+ifneq "$(GhcLibProfiled) $(GhcProfiled)" "NO NO"
+CONFIGURE_FLAGS_STAGE2 += --enable-library-profiling
+# And if we're profiling GHC then we want lots of SCCs.
+# We also don't want to waste time building the non-profiling library,
+# either normally or for ghci. Unfortunately this means that we have to
+# tell ghc-pkg --force as it gets upset when libHSghc-6.9.a doesn't
+# exist.
+ifeq "$(GhcProfiled)" "YES"
+CONFIGURE_FLAGS_STAGE2 += --ghc-option=-auto-all
+CONFIGURE_FLAGS_STAGE2 += --disable-library-vanilla
+CONFIGURE_FLAGS_STAGE2 += --disable-library-for-ghci
+CONFIGURE_FLAGS_STAGE2 += --ghc-pkg-option=--force
+endif
+endif
+
+ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
+# The #include is vital for the via-C route with older compilers, else the C
+# compiler doesn't realise that the stcall foreign imports are indeed
+# stdcall, and doesn't generate the Foo@8 name for them
+# As it's only important for older compilers we don't need to do anything
+# for stage2+.
+CONFIGURE_FLAGS_STAGE1 += --ghc-option='-\#include' \
+ --ghc-option='"<windows.h>"' \
+ --ghc-option='-\#include' \
+ --ghc-option='"<process.h>"'
+endif
+
+# ghc_strlen percolates through so many modules that it is easier to get its
+# prototype via a global option instead of a myriad of per-file OPTIONS.
+# Again, this is only important for older compilers, so we don't do it in
+# stage 2+.
+CONFIGURE_FLAGS_STAGE1 += --ghc-options='-\#include "cutils.h"'
+
+CONFIGURE_FLAGS_STAGE3 = $(CONFIGURE_FLAGS_STAGE2)
+CONFIGURE_FLAGS_STAGE1 += $(USE_BOOT_CONFIGURE_FLAGS)
+CONFIGURE_FLAGS_STAGE2 += $(USE_STAGE1_CONFIGURE_FLAGS)
+CONFIGURE_FLAGS_STAGE3 += $(USE_STAGE2_CONFIGURE_FLAGS)
+CONFIGURE_FLAGS_STAGE3 += --package-db $(STAGE3_PACKAGE_CONF)
+
+# In a source dist we don't need to worry about Parser.y(.pp) as we have
+# the .hs file pre-generated
+ifneq "$(wildcard parser/Parser.y.pp)" ""
+PARSER_Y = parser/Parser.y
+endif
+
+boot.stage.%: $(PRIMOP_BITS) $(CONFIG_HS) $(PARSER_Y)
+ test -f $(STAGE3_PACKAGE_CONF) || echo "[]" > $(STAGE3_PACKAGE_CONF)
+ $(CABAL) configure --distpref dist-stage$* \
+ $(CONFIGURE_FLAGS_STAGE$*) \
+ $(INSTALL_DIRS_CONFIGURE_FLAGS) \
+ $(COMMON_CONFIGURE_FLAGS) \
+ --ghc-option=-DSTAGE=$*
+ $(RM) -f Makefile-stage$*
+ $(CABAL) makefile --distpref dist-stage$* -f Makefile-stage$*
+
+build.stage.%:
+ $(MAKE) -f Makefile-stage$* stage=$*
+ $(CABAL) register --distpref dist-stage$* --inplace
+ $(MAKE) -C ../ghc stage=$*
+
+doc.stage.%:
+ $(CABAL) haddock --distpref dist-stage$* \
+ --html-location='../$$pkg' \
+ --haddock-option=--optghc=-DSTAGE=$* \
+ --haddock-option=+RTS --haddock-option=-s --haddock-option=-c --haddock-option=-RTS \
+ --with-haddock=$(FPTOOLS_TOP_ABS)/utils/haddock/install-inplace/bin/haddock
+
+install:
+ $(INSTALL_PACKAGE) install '$(GHC_PKG_INSTALL_PROG)' '$(DESTDIR)$(datadir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' --distpref dist-stage2
+