+.PHONY: binary-dist-doc-%
+
+BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
+
+LIBRARY_SUBDIRS=$(shell $(MAKE) -s -C libraries subdirs)
+
+BINARY_DIST_LIBRARY_RULES=$(foreach d,$(LIBRARY_SUBDIRS),binary-dist-lib-$d)
+
+binary-dist:: $(BINARY_DIST_LIBRARY_RULES)
+ cp libraries/Makefile $(BIN_DIST_LIBDIR)
+ cp libraries/gen_contents_index $(BIN_DIST_LIBDIR)
+ cp libraries/index.html $(BIN_DIST_LIBDIR)
+ cp libraries/doc-index.html $(BIN_DIST_LIBDIR)
+ cp -a libraries/stamp $(BIN_DIST_LIBDIR)
+
+$(BINARY_DIST_LIBRARY_RULES): binary-dist-lib-%:
+ $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*/setup
+ cp libraries/$*/setup/Setup $(BIN_DIST_LIBDIR)/$*/setup
+ cp libraries/$*/*.cabal $(BIN_DIST_LIBDIR)/$*
+ cp -a libraries/$*/dist $(BIN_DIST_LIBDIR)/$*
+ find $(BIN_DIST_LIBDIR)/$*/dist \
+ \( \( -name "*.o" -o -name "*.p_o" \) -a \! -name "HS*" \) \
+ -exec rm {} \;
+
+# Jiggle the files around to make a valid Windows distribution if necessary
+ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
+binary-dist :: fiddle-binary-dist
+endif
+
+.PHONY: fiddle-binary-dist
+fiddle-binary-dist:
+ cd $(BIN_DIST_DIR) && ../distrib/prep-bin-dist-mingw