Hardcore Processing - homepage
MLTON AS A CROSSCOMPILER FROM LINUX TO WINDOWS
Introduction
This document has two purposes:
- It decribes how to install the Linux to Windows
cross-compiler version of Stephen T. Weeks'
Standard ML compiler MLton.
- It describes how I have patched the '1999-7-12' release of
MLton into this cross-compiler distribution.
Installing the cross-compiler
First of all you need to install the following:
- The SML/NJ compiler. I recommend SML/NJ version 110.0.6
but see the last section of this document for details.
- A native gcc compiler for Linux.
- The Mingw32 cross-compiler version of gcc.
- My WinMain library.
- And optionally Sam Lantinga's SDL library if you need to use that.
To download and install the MLton crosscompiler, do the following:
- Download MLton_ANOQ20000712.tar.gz.
- Unpack with these commands:
gzip -d MLton_ANOQ20000712.tar.gz
tar -xvf MLton_ANOQ20000712.tar
- Make a second copy of the upacked directory with this command:
cp -r MLton_ANOQ20000712/ MLton_ANOQ20000712_ToWin32
- If you haven't already got a Linux native version of MLton
installed, you should now compile one with these commands:
cd MLton_ANOQ20000712/src
make
cd ../..
If you already have a Linux native version of MLton installed that you want
to keep you can remove the directory 'MLton_ANOQ20000712'.
- Now you should build another Linux native version of MLton with these
commands:
cd MLton_ANOQ20000712_ToWin32/src
make
cd ../..
- Now edit the file 'MLton_ANOQ20000712_ToWin32/bin/mlton'
and make sure that the line 'mlton=...' points to your (first) native
Linux version of the MLton compiler. It is currently set to the file
'root/../MLton_ANOQ20000712/lib/mlton' which should be OK if
you built the (first) native compiler as described above.
In the line 'args=...' you should also remove the
'-lm' option, since you cannot link with this when crosscompiling.
- Edit the file 'MLton_ANOQ20000712_ToWin32/include/mlton-lib.h'.
You need to set the include paths to WinMain, SDL and the crosscompiler
version of SDL to where they are installed on your computer.
- Now execute these commands:
cd MLton_ANOQ20000712_ToWin32/src
make prepareWin32
- Activate your gcc crosscompiler by setting the appropriate paths.
- You can now
build the actual MLton crosscompiler with this command (hopefully using
the crosscompiler version of gcc):
make target=win32
The makefile will stop with an error when it tries to compile
MLton itself - but this is OK since you only need
the crosscompiled versions of the runtime libraries.
Your new crosscompiler is now the file 'MLton_ANOQ20000712_ToWin32/bin/mlton'.
Brand new compiler flags for MLton
This brand new MLton crosscompiler some brand new compiler
flag that you can set.
To compile ordinary Win32 applications you
should problably set the flags something like this:
-D_WIN32 -L/usr/local/cross-tools/lib -L<WhereeverItIsInstalled>/WinMain/srcC/ -lmingw32 -lwinmain -luser32 -lgdi32 -lwinmm -ldxguid
To compile SDL applications you should problably set the flags something like this (besides linking with SDLFuncs.o from SDL::ML):
-D_WIN32 -DUSE_SDL -L/usr/local/cross-tools/lib -lmingw32 -lSDLmain -lSDL -luser32 -lgdi32 -lwinmm -ldxguid -mwindows
Now you might want to check out how to
use my SDL bindings for ML - SDL::ML.
Patching the mlton-1999-7-12 sourcecode manually
This section describes which files were modified in the relase compared
to the official 1999-7-12 release of MLton. However it is recommended
that you use the distribution above. Some of these changes are
bugfixes or additions to MLton:
- Remove the 'lib/libmlton.a' and 'lib/libgmp.a' files so that
that they're recompiled. Later, applications
will be linked with these files.
- Replace the Makefile under 'src/' with this one:
Makefile.src (renamed to Makefile of course).
- Replace the following files under 'src/runtime/'
with these: gc.c, mlton-lib.c, mlton-posix.c,
Makefile, my-lib.c.
- Replace the following files under 'include/'
with these: gc.h, mlton-lib.h, mlton-posix.h
and my-lib.h.
- (ADDITION) Replace build-basis under 'basis-library'.
- (ADDITION) Replace top-level.sml under 'basis-library/top-level'.
- (BUGFIX) Replace real.sml under 'basis-library/real'.
- (BUGFIX) Replace text-io.sml under 'basis-library/io'.
- (ADDITION) Add the following files under 'basis-library/io':
bin-io.sig and bin-io.sml.
- (BUGFIX) Replace the following files under 'basis-library/posix':
file-sys.sig and primitive.sml.
- (BUGFIX) Replace abstract-value.fun under 'src/closure-convert'.
- Activate your gcc Linux to Windows crosscompiler by setting the
appropriate path. I have used the binary available here with great success:
http://www.devolution.com/~slouken/SDL/Xmingw32/.
- Now go to 'src/' and type 'make' (hopefully using
the gcc Linux to Windows crosscompiler).
- It might work now, and if so - we're happy. However I had problems
with gmp. If compilation stops with an error related to gmp, then
do the following last 3 steps.
- Add an empty 'ml-win32' file in 'src/runtime/gmp-2.0.2/config'.
- In the file 'src/runtime/gmp-2.0.2/configure.in/', add a
line like the one with *-*-linux*) but with *win32*) instead.
- Go to 'src/' again and type 'make' again.
If all went well you now have some working runtime libraries
ready to be linked with when crosscompiling.
However you should edit the script 'bin/mlton' a little:
- The line 'mlton=...' should point to your native Linux version
of the MLton compiler - the file 'lib/mlton'. Just write the
full path to your native MLton compiler.
- In the line 'args=...' you should remove the '-lm' option,
since you cannot link with this when crosscompiling.
Hopefully you're all set.
A note for using MLton's cmcat and MLKit at the same time
To use MLTon's cmcat tool (for concatenating an SML/NJ/CM project
into one single sourcefile suitable for compilation with MLton)
you will also need SML/NJ working version 110.9.1 or later.
Notice that this may conflict if you're also using MLKit for
typechecking your code,
since MLKit does NOT compile with SML/NJ version 110.9.1, where as
SML/NJ version 110.0.3 and SML/NJ version 110.0.6
works fine for MLKit. And to run either MLKit
or cmcat you need an SML/NJ runtime of a compatible version, so
you may soon find yourself continuously swapping between 2 versions of SML/NJ.
However if you change line 153 of the cmcat source code from
'[file] => ((cmcat{sources = mkAbsolute{path =file,
relativeTo = getDir()}'
to '[file] => ((cmcat{sources = mkAbsolute (file, getDir())'
It should compile with SML/NJ version 110.0.6 so that
you can use the same runtime for both MLKit and cmcat.