[m-rev.] for review: Add copy_mercury_binaries script.

Peter Wang novalazy at gmail.com
Mon May 3 14:35:05 AEST 2021


tools/copy_mercury_binaries:
    Add script to copy binaries from one Mercury installation
    to another.

README.cross:
    Explain the use of the script.

    Delete manual instructions.

diff --git a/README.cross b/README.cross
index 37a604906..a220ed1df 100644
--- a/README.cross
+++ b/README.cross
@@ -74,22 +74,18 @@ ADAPTING THE MERCURY INSTALLATION FOR USE ON THE HOST SYSTEM
 To use the cross-compiled Mercury installation on the host system,
 you need to copy executables from a native Mercury installation's `bin`
 directory to the cross-compiled Mercury installation's `bin` directory.
-The two Mercury versions should be of the same (or least similar) versions.
+This can be done using the `tools/copy_mercury_binaries` script,
+which is called like this:
 
-If the Mercury installation was built for a Windows target, the executables
-are easily identified: they will have a `.exe` extension. Simply supply a
-native substitute for each `.exe` file.
+    tools/copy_mercury_binaries SRC DEST
 
-Otherwise, use the `file` command to identify binaries for the target system
-and replace them with binaries for the host system. At a minimum, you must
-replace `mercury_compile`, `mkinit`, `mdemangle` and `mfiltercc`.
+where SRC is the path to the native Mercury installation,
+and DEST is the path to the cross-compiled Mercury installation.
+The versions of the two Mercury installations should be the same,
+or at least very similar.
 
-Do *not* overwrite any shell scripts in the `bin` directory, since they include
-hard-coded paths to the Mercury installation.
-
-Once you have provided native substitutes for the binary files, you can use the
-`mmc` script from the cross-compiled Mercury installation to compile Mercury
-programs for the target system, e.g.
+Once that is done, you can use the `mmc` script from the cross-compiled Mercury
+installation to compile Mercury programs for the target system, e.g.
 
     % /usr/local/mercury-x86_64-w64-mingw32/bin/mmc -m hello
     Making Mercury/int3s/hello.int3
diff --git a/tools/copy_mercury_binaries b/tools/copy_mercury_binaries
new file mode 100755
index 000000000..e2ac739c9
--- /dev/null
+++ b/tools/copy_mercury_binaries
@@ -0,0 +1,69 @@
+#!/bin/sh
+# vim: ft=sh ts=4 sw=4 et
+#---------------------------------------------------------------------------#
+# Copyright (C) 2021 The Mercury team.
+# This file may only be copied under the terms of the GNU General
+# Public License - see the file COPYING in the Mercury distribution.
+#---------------------------------------------------------------------------#
+#
+# This script copies the binaries from one Mercury installation to another.
+# Please see README.cross for details.
+#
+#---------------------------------------------------------------------------#
+
+set -eu
+
+if test $# != 2
+then
+    echo "usage: copy_mercury_binaries SRC DEST"
+    echo "where SRC and DEST are paths to Mercury installations."
+    exit 1
+fi
+
+srcdir=$1/bin
+destdir=$2/bin
+
+if ! test -f "$srcdir/mercury_compile"
+then
+    echo "Missing $srcdir/mercury_compile"
+    exit 1
+fi
+if ! test -d "$destdir"
+then
+    echo "$destdir is not a directory."
+    exit 1
+fi
+
+echo "Copying files from $srcdir to $destdir..."
+
+for file in \
+    info_to_mdb \
+    mcov \
+    mdemangle \
+    mdice \
+    mdprof_cgi \
+    mdprof_create_feedback \
+    mdprof_dump \
+    mdprof_report_feedback \
+    mdprof_test \
+    mercury_compile \
+    mercury_profile \
+    mfiltercc \
+    mfilterjavac \
+    mkinit \
+    mslice \
+    mtc_diff \
+    mtc_union
+do
+    # The deep profiler binaries are not always installed.
+    if test -f "$srcdir/$file"
+    then
+        # Make a backup just in case.
+        if test -e "$destdir/$file"
+        then
+            mv "$destdir/$file" "$destdir/$file.bak"
+        fi
+
+        cp -v "$srcdir/$file" "$destdir"
+    fi
+done
-- 
2.30.0



More information about the reviews mailing list