+# Doc building with Haddock
+
+EXCLUDED_HADDOCK_SRCS = \
+ GHC/Err.lhs \
+ Data/Generics.hs \
+ GHC/PArr.hs
+
+HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS))))
+
+HADDOCK = $(FPTOOLS_TOP)/haddock/src/haddock-inplace
+
+# Urgh, hack needed to ensure that the value of HS_SRCS is computed in time for
+# the docs rule below.
+PRE_SRCS := $(ALL_SRCS)
+
+.PHONY: docs
+haddock-docs : $(HS_PPS)
+ $(HADDOCK) -t "Haskell Core Libraries" -h -s "." $(HS_PPS)
+
+%.raw-hs : %.lhs
+ $(GHC_INPLACE) $(HC_OPTS) -D__HADDOCK__ -E -cpp $< -o $<.tmp && sed -e 's/^#.*//' <$<.tmp >$@
+
+%.raw-hs : %.hs
+ $(GHC_INPLACE) $(HC_OPTS) -E -cpp $< -o $<.tmp && sed -e 's/^#.*//' <$<.tmp >$@
+
+# -----------------------------------------------------------------------------