[m-rev.] for review: cross-compiling with mingw

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Jan 3 02:03:22 AEDT 2012



Hi,

On Mon, 19 Dec 2011, Peter Wang wrote:

> Branches: main
>
> Let Mercury be built with a MinGW cross-compiler.
>
> tools/configure_mingw_cross:
> 	Add shell script to prepare for cross-compilation.
>
> README.MinGW-cross:
> 	Document how to use the shell script.
>
> configure.in:
> Mmake.common.in:
> 	Set a new variable CROSS_COMPILING.
>
> 	Set FULLARCH and BUILD_C_PROGS_FOR_BUILD_SYSTEM variables
> 	to be passed to the Boehm GC build system.
>
> 	Use $host-ar for AR when cross-compiling.
>
> m4/mercury.m4:
> 	Determine gcc version with gcc -dumpversion instead of building
> 	a program and running it.
>
> 	Don't run test for mercury_cv_cc_type if set explicitly.
>
> Mmake.workspace:
> 	Use the default c2init and mkinit when cross-compiling.
> 	The copies in the util directory would not be usable then.
>
> boehm_gc/Mmakefile:
> 	Pass configured values of AR, RANLIB down to sub-make.
>
> boehm_gc/Makefile.direct:
> boehm_gc/build_atomic_ops.sh:
> 	Use configured value from Mmake.common for HOSTCC.
>
> 	Pass --host when configuring libatomic_ops.
>
> util/Mmakefile:
> 	Make tools with .exe suffixes on Windows.
>
> Mmakefile:
> 	Use the bootstrap compiler to build libgrades when cross-compiling.
>
> 	Conform to changed target names in the util directory.
>
> compiler/Mmakefile:
> deep_profiler/Mmakefile:
> profiler/Mmakefile:
> slice/Mmakefile:
> 	Conform to changed target names in the util directory.
>
> Makefile:
> 	Clean .exe files on Windows.

...

> diff --git a/Mmakefile b/Mmakefile
> index 74b4ba2..d639190 100644
> --- a/Mmakefile
> +++ b/Mmakefile
> @@ -230,7 +230,7 @@ all: 	$(GENERATED_DOCS) mercury-compiler.spec util_no_rt $(SUBDIRS)
>
> .PHONY: util_no_rt
> util_no_rt: scripts
> -	+cd util && $(SUBDIR_MMAKE) mfiltercc
> +	+cd util && $(SUBDIR_MMAKE) mfiltercc$(EXT_FOR_EXE)
>
> .PHONY: util
> util: 	scripts runtime
> @@ -644,12 +644,18 @@ install_deep_profiler: deep_profiler
> # LIBGRADE_SUFFIXES = .m .int3 .date3 .int2 .int .date .opt .optdate \
> #	.trans_opt .trans_opt_date .d .mh .mih .c_date  .c .o .pic_o
>
> +ifeq ($(CROSS_COMPILING),yes)
> +OVERRIDE_MC_FOR_LIBGRADE =
> +else
> +OVERRIDE_MC_FOR_LIBGRADE = MC=mmc
> +endif
> +
> .PHONY: install_grades
> -install_grades: install_main
> +install_grades:  # install_main

Is commenting out the dependency on install_main there intentional?

...

> diff --git a/README.MinGW-cross b/README.MinGW-cross
> new file mode 100644
> index 0000000..a4c26e2
> --- /dev/null
> +++ b/README.MinGW-cross
> @@ -0,0 +1,69 @@
> +-----------------------------------------------------------------------------
> +
> +COMPILING MERCURY WITH A MINGW CROSS-COMPILER
> +
> +You can cross-compile Mercury on Linux with a MinGW cross-compiler.  After
> +copying and adjusting some paths, the Mercury installation should be usable
> +on Windows.  Alternatively, when combined with a native Mercury compiler,
> +it could be used to cross-compile Mercury applications for Windows.

I suggest adding a pointer to this file from README.MS-Windows and in that
file mention this as an alternative way of compiling Mercury for Windows.

> +-----------------------------------------------------------------------------
> +
> +PREREQUISITES
> +
> +We assume you are on Linux.  You will need a native Mercury installation
> +installed in the normal way.  Unless you know what you are doing, we
> +recommend that the native Mercury version matches the version of Mercury
> +you intend to cross-compile, or at least are very close.

It seems simpler to just require the same version; I suspect anything else
is just asking for trouble.

> +Obviously you need a MinGW cross-compiler.
> +I used <http://mingw-cross-env.nongnu.org/>

Most Linux distributions also have a package for it, e.g. gcc-mingw32 and
friends on Debian.

> +-----------------------------------------------------------------------------
> +
> +INSTALLATION
> +
> +Ensure that the MinGW cross-compiler i686-pc-mingw-gcc (or whatever) is on your
> +PATH.

Change this to:

    Ensure that the MinGW cross-compiler, i686-pc-mingw-gcc (the name may vary),
    is in your PATH.

> In a fresh Mercury directory, run this script instead of configure:

I suggest:

   In a fresh copy of the Mercury souce tree, run the following in place of the
   configure script

> +
> +    tools/configure_mingw_cross
> +
> +If your MinGW uses a host triplet other than "i686-pc-mingw32" then you must
> +pass that using the --host= option.  You may pass other options through to
> +configure as well, e.g.
> +
> +    tools/configure_mingw_cross \
> +        --host=i686-pc-mingw32 \
> +        --prefix=/usr/local/mercury-mingw
> +
> +Then install Mercury as usual:
> +
> +    mmake install PARALLEL=-j6 LIBGRADES=...

Specifying which library grades to install like that results in the library
grades not being set properly in Mercury.config and Mmake.vars (e.g the value
of LIBGRADES in the latter).

(Also, don't you only need to use PARALLEL=-jN when invoking make not mmake?)

> +-----------------------------------------------------------------------------
> +
> +USING THE CROSS-COMPILER ON LINUX
> +
> +You can substitute the Windows version of the Mercury compiler binary
> +(mercury_compile.exe) with a Linux version.  Again, this should be from
> +the same or similar version of Mercury.
> +
> +The 'mmc' shell script will have been set up to look for a binary named
> +'mercury_compile' so you just need to place the Linux binary into the bin
> +directory, e.g.
> +
> +    % ln -s /usr/local/mercury/bin/mercury_compile /usr/local/mercury-mingw/bin
> +
> +Now you can run the 'mmc' script from the cross-compiled installation:
> +
> +    % /usr/local/mercury-mingw/bin/mmc -m hello --cross-compiling
> +    Making Mercury/int3s/hello.int3
> +    Making Mercury/ints/hello.int
> +    Making Mercury/cs/hello.c
> +    Making Mercury/os/hello.o
> +    Making hello.exe
> +
> +You should definitely pass `--cross-compiling' if mercury_compile was
> +compiled for 64-bit Linux.

I suggest you recommend adding it to the Mercury.config file for the Windows
Mercury.

...

> #-----------------------------------------------------------------------------#
>
> diff --git a/tools/configure_mingw_cross b/tools/configure_mingw_cross
> new file mode 100755
> index 0000000..4aed07c
> --- /dev/null
> +++ b/tools/configure_mingw_cross
> @@ -0,0 +1,85 @@
> +#!/bin/sh -e
> +# This script prepares the Mercury directory for a MinGW cross-compiler.

I suggest:

    This script prepares the Mercury source tree for building a MinGW cross-compiler.

> +# Please see README.MinGW-cross for details.

...

That looks fine otherwise.

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list