[m-rev.] for review: Support cross-compiling for Linux/Aarch64.
Julien Fischer
jfischer at opturion.com
Tue May 4 01:15:50 AEST 2021
Hi Peter,
On Mon, 3 May 2021, Peter Wang wrote:
> 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)
Linux AArch64, unless this has been tested on other operating systems.
> +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
I would leave -j8 out of it and add the mmake depend step.
...
> ## 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."
s/tree/source tree/
That looks fine otherwise.
Julien.
More information about the reviews
mailing list