+# We should depend on %/%.cabal here (and in other rules), but make
+# makes that difficult.
+
+ALL_CONFIGURE_FLAGS = \
+ $(INSTALL_DIRS_CONFIGURE_FLAGS) \
+ $(USE_STAGE1_CONFIGURE_FLAGS) \
+ $(COMMON_CONFIGURE_FLAGS) \
+ --haddock-options="--use-contents=../index.html \
+ --use-index=../doc-index.html" \
+ $(CONFIGURE_OPTS)
+
+stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).dph/dph-par: \
+ dph/dph-par
+
+stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).dph/dph-seq: \
+ dph/dph-seq
+
+dph/%:
+ $(MAKE) -C dph $*
+
+$(foreach SUBDIR,$(SUBDIRS), \
+ stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
+stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: cabal-bin
+ -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
+ $(MKDIRHIER) `dirname $@`
+ ( cd $* && $(CABAL) configure $(ALL_CONFIGURE_FLAGS) ) \
+ && 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 bootlibs, where failure means the
+# build dies!
+
+# Build the library using 'make'
+# We re-run 'setup makefile' each time, just in case any preprocessing
+# needs to be done. However, we're careful not to overwrite GNUmakefile
+# if it hasn't changed, so that dependency-generation isn't forced
+# every time.
+$(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR)):\
+make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
+ cabal-bin ifBuildable/ifBuildable
+ if $(IFBUILDABLE) $*; then \
+ cd $* && \
+ cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
+ mv GNUmakefile GNUmakefile.tmp; \
+ $(CABAL) makefile -f GNUmakefile; \
+ cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
+ $(MAKE) $(MFLAGS) && \
+ $(CABAL) register --inplace; \
+ fi
+
+MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
+
+# Build the library using 'setup build' (not the default)
+$(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
+build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
+ cabal-bin ifBuildable/ifBuildable
+ if $(IFBUILDABLE) $*; then \
+ cd $* && \
+ $(CABAL) build $(BUILD_FLAGS); \
+ $(CABAL) register --inplace; \
+ fi
+
+.PHONY: doc html
+
+html: doc
+
+# No docs for compat libraries for now.
+DOC_SUBDIRS = $(filter-out %-compat, $(SUBDIRS))
+
+doc: $(foreach SUBDIR,$(DOC_SUBDIRS),doc.library.$(SUBDIR))
+ sh gen_contents_index --inplace
+
+# Making hyperlinked source only works if we have hscolour
+ifneq "$(HSCOLOUR)" ""
+CABAL_HADDOCK_FLAGS += --hyperlink-source
+endif
+CABAL_HADDOCK_FLAGS += --with-haddock=$(FPTOOLS_TOP_ABS)/utils/haddock/install-inplace/bin/haddock
+
+$(foreach SUBDIR,$(DOC_SUBDIRS),doc.library.$(SUBDIR)):\
+doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
+ cabal-bin ifBuildable/ifBuildable
+ if $(IFBUILDABLE) $*; then \
+ cd $* && $(CABAL) haddock --html-location='../$$pkg' \
+ $(CABAL_HADDOCK_FLAGS); \
+ fi
+ifneq "$(HSCOLOUR)" ""
+# We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
+# mismatch
+# XXX We also need to check that the directory exists, as e.g. dph disables
+# haddock, so the directory doesn't get made. We should remove this once
+# we can always haddock everything.
+ if $(IFBUILDABLE) $* && [ -d $*/dist/doc/html/*/src/ ]; then cp hscolour.css $*/dist/doc/html/*/src/; fi
+endif
+
+.PHONY: maintainer-clean distclean clean clean.library.%
+
+maintainer-clean: clean
+distclean: clean
+
+clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
+ -cd filepath && $(CABAL) clean --distpref=dist-bootstrapping
+ -cd Cabal && $(CABAL) clean --distpref=dist-bootstrapping
+ -cd hpc && $(CABAL) clean --distpref=dist-bootstrapping
+ $(RM) -rf bootstrapping
+ $(RM) -f bootstrapping.conf bootstrapping.conf.old
+ $(RM) -f bootstrapping.conf.tmp bootstrapping.conf.tmp.old
+ $(RM) -f cabal-bin cabal-bin.exe
+ $(RM) -rf ifBuildable
+ $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
+ $(RM) -f haddock* *.gif
+ $(RM) -rf stamp/*
+ifneq "$(wildcard dph)" ""
+ $(MAKE) -C dph clean
+endif
+
+maintainer-clean distclean:
+ $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
+
+$(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
+clean.library.%:
+ $(RM) -f stamp/configure.library.*.$* $*/unbuildable
+ -cd $* && $(CABAL) clean
+ $(RM) -f $*/Setup $*/Setup.exe $*/Setup.hi $*/Setup.o
+ $(RM) $*/GNUmakefile $*/Makefile.local
+endif