+# This script is called at the appropriate point during 'make binary-dist'.
+# The result is a tarball at the top of your GHC build tree, named something
+# like ghc-6.6.1-i386-unknown-mingw32.tar.bz2.
+#
+# User tweakables
+# Note: you normally don't need to set any of these, the script
+# will try to figure them out for itself. If the heuristics don't
+# work for whatever reason, you can override them using environment
+# variables, e.g.
+# mingw_top=<whatever> make binary-dist
+#
+# - mingw_top -- location of mingw distribution tree (usually c:/mingw)
+# - perl_dir -- location of non-cygwin perl.exe
+# - gcc_lib -- c:/mingw/lib/gcc/mingw32/3.4.2, or equivalent
+# - gcc_libexec -- c:/mingw/libexec/gcc/mingw32/3.4.2, or equivalent
+#
+
+#Directory where a (cygwin-free) perl binary resides.
+if [ "${perl_dir}" == "" ]; then
+ for i in c:/ghc/*; do
+ if [ -e $i/perl.exe ]; then
+ perl_dir=$i
+ echo "Found perl.exe in $i"
+ break
+ fi
+ done
+ if [ "${perl_dir}" == "" ]; then
+ echo "Can't find perl.exe; please set \$perl_dir"
+ exit 1
+ fi
+fi
+
+if [ "${mingw_top}" == "" ]; then
+ if [ -d c:/mingw ]; then
+ mingw_top=c:/mingw
+ echo "Found mingw in $mingw_top"
+ else
+ echo "Can't find mingw; please set \$mingw_top"
+ exit 1
+ fi
+fi
+
+# The gcc-lib directory of the mingw tree you want to
+# include with the binary dist.
+if [ "x${gcc_lib}" == "x" ]; then
+ if [ -d "${mingw_top}/lib/gcc-lib/mingw32" ]; then
+ mingw_gcc_lib=${mingw_top}/lib/gcc-lib/mingw32
+ else
+ mingw_gcc_lib=${mingw_top}/lib/gcc/mingw32
+ fi
+ for i in `ls -r ${mingw_gcc_lib}`; do
+ if [ -d "${mingw_gcc_lib}/$i" ]; then
+ gcc_lib=${mingw_gcc_lib}/$i
+ echo "Found gcc lib in $gcc_lib"
+ break
+ fi
+ done
+ if [ "${gcc_lib}" == "" ]; then
+ echo "Can't find gcc lib files; please set \$gcc_lib"
+ exit 1
+ fi
+fi
+
+# The gcc-lib directory of the mingw tree you want to
+# include with the binary dist.
+if [ "x${gcc_libexec}" == "x" ]; then
+ if [ -d "${mingw_top}/libexec/gcc-lib/mingw32" ]; then
+ mingw_gcc_libexec=${mingw_top}/libexec/gcc-lib/mingw32
+ else
+ mingw_gcc_libexec=${mingw_top}/libexec/gcc/mingw32
+ fi
+ for i in `ls -r ${mingw_gcc_libexec}`; do
+ if [ -d "${mingw_gcc_libexec}/$i" ]; then
+ gcc_libexec=${mingw_gcc_libexec}/$i
+ echo "Found gcc libexec in $gcc_libexec"
+ break
+ fi
+ done
+ if [ "${gcc_libexec}" == "" ]; then
+ echo "Can't find gcc libexec files; please set \$gcc_libexec"
+ exit 1
+ fi
+fi
+
+#
+# The mingw include, lib, and bin directories; all derived
+# from ${mingw_top}.
+#
+if [ "x${mingw_include}" == "x" ]; then
+ export mingw_include=$mingw_top/include
+fi
+if [ "x${mingw_lib}" == "x" ]; then
+ export mingw_lib=$mingw_top/lib
+fi
+if [ "x${mingw_bin}" == "x" ]; then
+ export mingw_bin=$mingw_top/bin
+fi
+
+# Check that we're in an OK place before starting to re-org
+# the directory tree..
+if ! [ -d bin/i386-unknown-mingw32 ] ; then
+ echo "Doesn't look as if I'm in the toplevel directory of a mingw tree"
+ echo "Usage: cd ghc-<version> ; ../distrib/prep-bin-dist-mingw"
+ exit 1;
+fi;