[mercury-users] Cross-compiling with mingw32

Michael Day mikeday at yeslogic.com
Fri Jan 21 19:03:16 AEDT 2005


Hi Elmar,

> can you provide mit actual information how to get an Linux->Windows
> Crosscompiler of mercury to work?

Sure, I'll just copy this to the mercury-users mailing list for archiving.

I assume that you have a mingw environment set up in some directory, say
/opt/mingw, with contents like this:

    /opt/mingw/bin/i586-mingw32-gcc
    /opt/mingw/bin/i586-mingw32-ld
    ...

if your setup is different then adjust the following instructions
accordingly; if you don't have mingw set up then that is another topic
(check http://mingw.sourceforge.net if you don't have it).

Step 1: Get a recent Mercury release of the day.

I have been having trouble building older versions of Mercury under mingw
for some reason, so get a fairly recent one: rotd-2004-01-11 has worked
for me.

Step 2: Unpack it and edit the configure script.

This is a hack which should probably be fixed properly. Any takers? :)
Open up the configure script and grep for these lines:

# Don't try to use mprotect() on gnu-win32, since it is broken
# (at least for version b18, anyway) and trying it can crash Win95.

There is a case statement there for gnu-win32; add an identical case for
mingw32 as well.

Grep for the first use of mercury_cv_word_type. Go up a little bit to the
beginning of the section, and paste in these definitions to hardcode all
of the appropriate sizes:

mercury_cv_word_type=int
mercury_cv_int_least32_type=int
mercury_cv_int_least16_type=short
mercury_cv_low_tag_bits=2
mercury_cv_bytes_per_word=4
mercury_cv_bits_per_word=32
mercury_cv_double_is_64_bit=yes
mercury_cv_is_littleender=yes
mercury_cv_gcc_labels=yes
mercury_cv_asm_labels=yes
mercury_cv_gcc_model_fast=yes
mercury_cv_gcc_model_reg=yes

Grep for where the RANLIB variable is set and add this:

AR=/opt/mingw/bin/i586-mingw32-ar

(otherwise scripts/Mercury.config will leave --create-archive-command set
to "ar", which is incorrect, and the configure script only picks up the
RANLIB environment variable, not AR).

Step 3: Run the configure script.

RANLIB=/opt/mingw/bin/i586-mingw32-ranlib \
./configure \
--prefix=/opt/mingw/mercury-2005-01-11 \
--with-cc=/opt/mingw/bin/i586-mingw32-gcc \
--host=i586-pc-mingw32 \
--enable-libgrades='hlc.gc asm_fast.gc'

(You may wish to use a different install prefix and you may wish to
install different grades).

Hopefully the configure will succeed.

Step 4: Hack the Boehm GC makefile.

Open up boehm_gc/Makefile and grep for HOSTCC, set it to just "gcc" so
that it uses the local host compiler not the cross-compiler.

(Otherwise make will fail in boehm_gc, as the if_mach and if_not_there
utilities will be built using the mingw gcc, when they need to be run
during the build).

Also inside boehm_gc/Makefile set AR and RANLIB to the mingw versions.

Step 5: Build some utilities.

make will fail when it needs to use mkinit or mdemangle if these are built
by the cross-compiler. Build these by hand by compiling them with gcc:

    $ cd util
    $ gcc -I ../runtime mkinit.c -o mkinit
    $ gcc -I ../runtime mdemangle.c -o mdemangle

Step 6: Build Mercury.

    $ make
    $ sudo make install

Be amazed if all this works without any intermediate errors :)

But when it does work, it's pretty cool.

Cheers,

Michael

-- 
YesLogic Prince prints XML!
http://yeslogic.com
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list