Debian Codegraph @

doc/guide/src/CrossCompiling.adoc

raw
1 = CrossCompiling
2
3 MLton's `-target` flag directs MLton to cross compile a program for
4 another platform. By default, MLton is only able to compile for the
5 platform that it is running on. In order to use MLton as a cross
6 compiler, you need to do two things.
7
8 1. Build the MLton runtime system for the target using a remote
9 machine.
10
11 2. Install or build the appropriate cross-compiler toolchain on the
12 host so that the C compiler(s) can compile to the target.
13
14 To make the terminology clear, we refer to the _host_ as the machine
15 MLton is running on and the _target_ as the machine that MLton is
16 compiling for.
17
18 To build the MLton runtime system for the target, use the
19 `remote-add-cross` goal of the root `Makefile`; see comments in
20 the root `Makefile`. The `remote-add-cross` goal uses `ssh` to
21 build the runtime system on a remote machine. Building the runtime
22 system requires compiling and executing programs that determine
23 characteristics of the platform, which is why it isn't currently
24 feasible to build the runtime system on the host machine using a
25 cross-compiler toolchain.
26
27 Here is an example adding a `sparc-sun-solaris` cross-compile target
28 using the remote machine `blade`:
29 ----
30 % make CROSS_TARGET=sparc-sun-solaris REMOTE_MACHINE=blade remote-add-cross
31 ----
32
33 Once you have both the MLton runtime system and a cross-compiler
34 toolchain for the target, you should be able to cross compile SML
35 programs. For example,
36 ----
37 mlton -target sparc-sun-solaris hello-world.sml
38 ----
39 will create `hello-world`, which you should be able to run on a Sparc
40 Solaris machine.
41
42
43 == Cross-compiling alternatives
44
45 Building and maintaining a cross-compiler toolchain is complex. You
46 may find it simpler to use `mlton -keep g` to generate the files on
47 the host, then copy the files to the target, and then use `gcc` or
48 `mlton` on the target to compile the files.