+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 {} \;
+
+# Tar up the distribution and build a manifest
+binary-dist ::
+ ( cd $(BIN_DIST_TOPDIR); tar cf - $(BIN_DIST_NAME) | bzip2 >$(BIN_DIST_TARBALL) )
+ ( cd $(BIN_DIST_TOPDIR); bunzip2 -c $(BIN_DIST_TARBALL) | tar tf - | sed "s/^ghc-$(ProjectVersion)/fptools/" | sort >bin-manifest-$(ProjectVersion) )
+
+# Upload the distribution and documentation
+ifneq "$(PublishLocation)" ""
+binary-dist ::
+ @for i in 0 1 2 3 4 5 6 7 8 9; do \
+ echo "Try $$i: $(PublishCp) $(BIN_DIST_TARBALL) $(PublishLocation)"; \
+ if $(PublishCp) $(BIN_DIST_TARBALL) $(PublishLocation); then break; fi\
+ done
+ $(PublishCp) -r $(BIN_DIST_DIR)/share/html/* $(PublishLocation)/docs