[m-rev.] for review: Support cross-compiling for Linux/Aarch64.

Peter Wang novalazy at gmail.com
Mon May 3 13:02:59 AEST 2021


tools/configure_cross:
tools/configure_mingw_cross:
    Rename configure_mingw_cross to configure_cross.

    Support aarch64-linux-gnu as a target.

    Make the script recognise a --with-cc option.

README.cross:
    Rewrite instructions for building with a cross-compiler.

README.MinGW-cross:
    Delete old instructions.

.nocopyright:
README.MS-Windows
README.md:
    Replace references to README.MinGW-cross with README.cross.

NEWS:
    Announce change.

diff --git a/.nocopyright b/.nocopyright
index 85cb0266b..c51cff9d1 100644
--- a/.nocopyright
+++ b/.nocopyright
@@ -29,7 +29,6 @@ README.Linux-m68k
 README.Linux-PPC
 README.MacOS
 README.MinGW
-README.MinGW-cross
 README.MS-VisualC
 README.MS-Windows
 README.OSF1
@@ -38,3 +37,4 @@ README.Solaris
 README.ssdebug
 README.CSharp
 README.clang
+README.cross
diff --git a/NEWS b/NEWS
index 0d2a312c8..06a0e0029 100644
--- a/NEWS
+++ b/NEWS
@@ -436,6 +436,9 @@ Portability improvements
 
 * We have ported Mercury to Linux AArch64 (ARM64) systems.
 
+* The `tools/configure_mingw_cross` script has been replaced by
+  `tools/configure_cross`. It now supports aarch64-linux-gnu as a target.
+
 Changes to the Mercury debugger
 -------------------------------
 
diff --git a/README.MS-Windows b/README.MS-Windows
index 12961518e..f02bcdd85 100644
--- a/README.MS-Windows
+++ b/README.MS-Windows
@@ -40,7 +40,7 @@ Building Mercury for Windows on Linux
 -------------------------------------
 
 Alternatively, you can cross-compile Mercury on Linux with a MinGW
-cross-compiler.  See README.MinGW-cross.
+cross-compiler.  See README.cross.
 
 ------------------------
 Using Mercury on Windows
diff --git a/README.MinGW-cross b/README.MinGW-cross
deleted file mode 100644
[snip]
diff --git a/README.cross b/README.cross
new file mode 100644
index 000000000..37a604906
--- /dev/null
+++ b/README.cross
@@ -0,0 +1,101 @@
+-----------------------------------------------------------------------------
+
+COMPILING MERCURY WITH A CROSS-COMPILER
+
+You can build the Mercury system with a C cross-compiler so that the Mercury
+installation will run on a different platform from your host system.
+The following targets are currently supported:
+
+  * Windows 64-bit, using MinGW-w64
+  * Windows 32-bit, using MinGW-w64 or MinGW32
+  * AArch64 (ARM64)
+
+Furthermore, instead of transferring the Mercury installation to the target
+system and running it there, you can augment the cross-compiled installation
+with files from a native Mercury installation, allowing you to cross-compile
+Mercury programs for the target system on the host system.
+
+NOTE: At one stage, there were problems with the 'asm_fast*' grade on
+Windows 64-bit. The 'none*' and 'reg*' grades did appear to work correctly.
+This has not been checked recently. We suggest using the 'hlc' grades for
+production usage.
+
+-----------------------------------------------------------------------------
+
+INSTRUCTIONS
+
+ 1. Install Mercury for the host system as usual.
+
+ 2. Install a C cross-compiler.
+    On Debian/Ubuntu you might install one of these packages:
+
+      - gcc-mingw-w64-x86-64
+      - gcc-mingw-w64-i686
+      - gcc-aarch64-linux-gnu
+
+    Alternatively, you can use <http://mxe.cc/> to install a MinGW-w64
+    toolchain on Unix-like hosts.
+
+    Whatever the means, you should have the C cross-compiler in your PATH,
+    e.g. /usr/bin/x86_64-w64-mingw32-gcc.
+
+ 3. Unpack a fresh copy of the Mercury source tree.
+    Now, instead of running ./configure, run:
+
+        tools/configure_cross --host=HOST [--with-cc=PATH] \
+            <other configure arguments>
+
+    The `--host` option is required. HOST is the "host triplet" of your
+    cross-compiler, e.g. x86_64-w64-mingw32, i686-w64-mingw32, or
+    aarch64-linux-gnu-gcc.
+
+    The `--with-cc` option can be used to pass the path of your C
+    cross-compiler. It is required if your cross-compiler is not called
+    `HOST-gcc`, where HOST is the value of the `--host` option.
+
+    Those two options must be appear first. Any later options are passed
+    through to the configure script. A call to the `configure_cross` script
+    might look like:
+
+        tools/configure_cross \
+            --host=x86_64-w64-mingw32 \
+            --prefix=/usr/local/mercury-x86_64-w64-mingw32 \
+            --enable-libgrades=hlc.gc
+
+ 4. Now you can install Mercury as usual, e.g.
+
+        mmake -j8
+        mmake -j8 install
+
+-----------------------------------------------------------------------------
+
+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.
+
+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.
+
+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`.
+
+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.
+
+    % /usr/local/mercury-x86_64-w64-mingw32/bin/mmc -m hello
+    Making Mercury/int3s/hello.int3
+    Making Mercury/ints/hello.int
+    Making Mercury/cs/hello.c
+    Making Mercury/os/hello.o
+    Making hello.exe
+
+-----------------------------------------------------------------------------
diff --git a/README.md b/README.md
index f49ff89b4..85784ea49 100644
--- a/README.md
+++ b/README.md
@@ -52,7 +52,7 @@ Specific information is contained in individual README files:
 
   * Cross compilation
 
-      * [MinGW](README.MinGW-cross)
+      * [README.cross]
 
 ## Other information
 
diff --git a/tools/configure_cross b/tools/configure_cross
new file mode 100755
index 000000000..13b5d541d
--- /dev/null
+++ b/tools/configure_cross
@@ -0,0 +1,132 @@
+#!/bin/sh
+# vim: ft=sh ts=4 sw=4 et
+#---------------------------------------------------------------------------#
+# Copyright (C) 2012 The University of Melbourne.
+# Copyright (C) 2014, 2018, 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 prepares the Mercury source tree for building with a
+# C cross-compiler. Please see README.cross for details.
+#
+#---------------------------------------------------------------------------#
+
+set -eu
+
+host=
+hostcc=
+
+for arg
+do
+    case $arg in
+        --host=*)
+            host=${arg#--host=}
+            shift 1
+            ;;
+        --with-cc=*)
+            hostcc=${arg#--with-cc=}
+            shift 1
+            ;;
+        *)
+            break
+            ;;
+    esac
+done
+
+if test -z "$host"
+then
+    echo "You must pass --host=HOST, e.g. x86_64-w64-mingw32"
+    exit 1
+fi
+
+hostcc=${hostcc:-"${host}-gcc"}
+
+if command -v "$hostcc" >/dev/null
+then
+    true
+else
+    echo "You need $hostcc in your PATH."
+    exit 1
+fi
+
+if command -v mmc >/dev/null && mmc -v 2>&1 | grep -q Mercury
+then
+    true
+else
+    echo "You need a working native mmc in your PATH."
+    exit 2
+fi
+
+if test configure -ot configure.ac
+then
+    aclocal -I m4 && autoconf
+fi
+
+if ! test -f configure.ac
+then
+    echo "You need to run this script at the top of the Mercury tree."
+    exit 3
+fi
+
+# Set values which would otherwise be determined with AC_TRY_RUN.
+case $host in
+    i686-*-mingw32 | x86_64-*-mingw32)
+        # Taken from the config.cache file after running configure -C in msys.
+        mercury_cv_cc_type=gcc
+        mercury_cv_siginfo_t=no
+        mercury_cv_pc_access=no
+        mercury_cv_is_bigender=no
+        mercury_cv_is_littleender=yes
+        mercury_cv_normal_system_retval=no
+        mercury_cv_can_do_pending_io=no
+        mercury_cv_gcc_labels=yes
+        mercury_cv_asm_labels=yes
+        mercury_cv_gcc_model_fast=yes
+        mercury_cv_gcc_model_reg=yes
+        mercury_cv_cannot_use_structure_assignment=yes
+        ;;
+    aarch64-linux-gnu)
+        # Taken from the config.cache file after running configure -C
+        # in a Debian 10 arm64 environment.
+        mercury_cv_cc_type=gcc
+        mercury_cv_siginfo_t=yes
+        mercury_cv_pc_access=no
+        mercury_cv_is_bigender=no
+        mercury_cv_is_littleender=yes
+        mercury_cv_normal_system_retval=yes
+        mercury_cv_can_do_pending_io=yes
+        mercury_cv_gcc_labels=yes
+        mercury_cv_asm_labels=yes
+        mercury_cv_gcc_model_fast=yes
+        mercury_cv_gcc_model_reg=yes
+        mercury_cv_cannot_use_structure_assignment=no
+        ;;
+    *)
+        echo "unknown host: $host" >&2
+        exit 1
+        ;;
+esac
+
+mercury_cv_cc_type=$mercury_cv_cc_type \
+mercury_cv_siginfo_t=$mercury_cv_siginfo_t \
+mercury_cv_pc_access=$mercury_cv_pc_access \
+mercury_cv_is_bigender=$mercury_cv_is_bigender \
+mercury_cv_is_littleender=$mercury_cv_is_littleender \
+mercury_cv_normal_system_retval=$mercury_cv_normal_system_retval \
+mercury_cv_can_do_pending_io=$mercury_cv_can_do_pending_io \
+mercury_cv_gcc_labels=$mercury_cv_gcc_labels \
+mercury_cv_asm_labels=$mercury_cv_asm_labels \
+mercury_cv_gcc_model_fast=$mercury_cv_gcc_model_fast \
+mercury_cv_gcc_model_reg=$mercury_cv_gcc_model_reg \
+mercury_cv_cannot_use_structure_assignment=$mercury_cv_cannot_use_structure_assignment \
+sh configure "$@" \
+    --host="$host" \
+    --with-cc="$hostcc"
+
+echo
+echo "If you wish to run mmake in the subdirectories, you will need to set"
+echo "MMAKE_DIR=$(pwd)/scripts"
+echo
+
+exit
diff --git a/tools/configure_mingw_cross b/tools/configure_mingw_cross
deleted file mode 100755
[snip]


More information about the reviews mailing list