+$(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
+%/setup/Setup: $(BOOTSTRAPPING_STAMPS)
+ -$(RM) -rf $*/setup
+ mkdir $*/setup
+ $(CP) $*/Setup.*hs $*/setup
+ cd $*/setup && $(GHC) -i../../bootstrapping.Cabal \
+ -i../../bootstrapping.filepath \
+ -Wall -cpp --make Setup.*hs -o Setup
+
+ifBuildable/ifBuildable: ifBuildable.hs
+ -$(RM) -rf ifBuildable
+ mkdir ifBuildable
+ $(CP) ifBuildable.hs ifBuildable/
+ cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
+
+$(BOOTSTRAPPING_STAMPS): stamp/bootstrapping.%:
+ $(RM) -rf bootstrapping.$*
+ $(CP) -R $* bootstrapping.$*
+ $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
+ -exec $(RM) -f {} \;
+ touch $@
+
+.PHONY: all build configure
+
+all: build
+
+ifneq "$(NO_HADDOCK_DOCS)" "YES"
+all: doc
+endif
+
+build: $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR))
+
+configure: $(foreach SUBDIR,$(SUBDIRS), \
+ stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
+
+.PHONY: build.library.%
+
+# We should depend on %/%.cabal here (and in other rules), but make
+# makes that difficult.
+
+$(foreach SUBDIR,$(SUBDIRS), \
+ stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
+stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
+ -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
+ ( cd $* && setup/Setup configure \
+ $(CONFIGURE_OPTS) \
+ --prefix=$(prefix) \
+ --with-compiler=../../compiler/ghc-inplace$(dot_bat) \
+ --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace$(dot_bat) \
+ --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace$(dot_bat) \
+ --with-ld=$(LD) \
+ --datasubdir=ghc \
+ --haddock-args="--use-contents=../index.html \
+ --use-index=../doc-index.html" \
+ $(addprefix --configure-option=,$(CONFIGURE_ARGS)) \
+ --configure-option=--with-cc=$(CC) ) \
+ && touch $@ || touch $*/unbuildable
+# We don't touch $@ if configure failed as we would prefer to try
+# configuring it next time round, rather than assuming it'll still fail.
+# This is particularly important for corelibs, where failure means the
+# build dies!
+
+$(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
+build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
+ %/setup/Setup ifBuildable/ifBuildable
+ ifBuildable/ifBuildable $* setup/Setup build \
+ $(addprefix --ghc-option=,$(GhcLibHcOpts))
+ ifBuildable/ifBuildable $* setup/Setup register --inplace
+
+.PHONY: doc
+
+DOC_SUBDIRS = $(filter-out haskell98,$(SUBDIRS))
+
+doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
+ sh gen_contents_index
+
+$(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
+doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
+ %/setup/Setup ifBuildable/ifBuildable
+ ifBuildable/ifBuildable $* setup/Setup haddock
+
+.PHONY: install install-docs install.library.%
+
+INSTALL_DIR=$(prefix)/share/ghc/doc/html/
+
+install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))