| 1 |
= SelfCompiling |
| 2 |
|
| 3 |
If you want to compile MLton, you must first get the <<Sources#>>. You |
| 4 |
can compile with either MLton or SML/NJ, but we strongly recommend |
| 5 |
using MLton, since it generates a much faster and more robust |
| 6 |
executable. |
| 7 |
|
| 8 |
== Compiling with MLton |
| 9 |
|
| 10 |
To compile with MLton, you need the binary versions of `mlton`, |
| 11 |
`mllex`, and `mlyacc` that come with the MLton binary package. To be |
| 12 |
safe, you should use the same version of MLton that you are building. |
| 13 |
However, older versions may work, as long as they don't go back too |
| 14 |
far. To build MLton, run `make` from within the root directory of the |
| 15 |
sources. This will build MLton first with the already installed |
| 16 |
binary version of MLton and will then rebuild MLton with itself. |
| 17 |
|
| 18 |
First, the `Makefile` calls `mllex` and `mlyacc` to build the lexer |
| 19 |
and parser, and then calls `mlton` to compile itself. When making |
| 20 |
MLton using another version the `Makefile` automatically uses |
| 21 |
`mlton-stubs.mlb`, which will put in enough stubs to emulate the |
| 22 |
`structure MLton`. Once MLton is built, the `Makefile` will rebuild |
| 23 |
MLton with itself, this time using `mlton.mlb` and the real |
| 24 |
`structure MLton` from the <<BasisLibrary#,Basis Library>>. This second round |
| 25 |
of compilation is essential in order to achieve a fast and robust |
| 26 |
MLton. |
| 27 |
|
| 28 |
Compiling MLton requires at least 1GB of RAM for 32-bit platforms (2GB is |
| 29 |
preferable) and at least 2GB RAM for 64-bit platforms (4GB is preferable). |
| 30 |
If your machine has less RAM, self-compilation will |
| 31 |
likely fail, or at least take a very long time due to paging. Even if |
| 32 |
you have enough memory, there simply may not be enough available, due |
| 33 |
to memory consumed by other processes. In this case, you may see an |
| 34 |
`Out of memory` message, or self-compilation may become extremely |
| 35 |
slow. The only fix is to make sure that enough memory is available. |
| 36 |
|
| 37 |
=== Possible Errors |
| 38 |
|
| 39 |
* The C compiler may not be able to find the <<GMP#>> header file, |
| 40 |
`gmp.h` leading to an error like the following. |
| 41 |
+ |
| 42 |
---- |
| 43 |
cenv.h:49:18: fatal error: gmp.h: No such file or directory |
| 44 |
---- |
| 45 |
+ |
| 46 |
The solution is to install (or build) <<GMP#>> on your machine. If you |
| 47 |
install it at a location not on the default seach path, then run |
| 48 |
``make WITH_GMP_INC_DIR=__/path/to/gmp/include__ WITH_GMP_LIB_DIR=__/path/to/gmp/lib__``. |
| 49 |
|
| 50 |
* The following errors indicates that a binary version of MLton could |
| 51 |
not be found in your path. |
| 52 |
+ |
| 53 |
---- |
| 54 |
/bin/sh: mlton: command not found |
| 55 |
---- |
| 56 |
+ |
| 57 |
---- |
| 58 |
make[2]: mlton: Command not found |
| 59 |
---- |
| 60 |
+ |
| 61 |
You need to have `mlton` in your path to build MLton from source. |
| 62 |
+ |
| 63 |
During the build process, there are various times that the `Makefile`-s |
| 64 |
look for a `mlton` in your path and in `src/build/bin`. It is OK if |
| 65 |
the latter doesn't exist when the build starts; it is the target being |
| 66 |
built. Failure to find a `mlton` in your path will abort the build. |
| 67 |
|
| 68 |
|
| 69 |
== Compiling with SML/NJ |
| 70 |
|
| 71 |
To compile with SML/NJ, run `make bootstrap-smlnj` from within the |
| 72 |
root directory of the sources. You must use a recent version of |
| 73 |
SML/NJ. First, the `Makefile` calls `ml-lex` and `ml-yacc` to build |
| 74 |
the lexer and parser. Then, it calls SML/NJ with the appropriate |
| 75 |
`sources.cm` file. Once MLton is built with SML/NJ, the `Makefile` |
| 76 |
will rebuild MLton with this SML/NJ built MLton and then will rebuild |
| 77 |
MLton with the MLton built MLton. Building with SML/NJ takes |
| 78 |
significant time (particularly during the `parseAndElaborate` phase |
| 79 |
when the SML/NJ built MLton is compiling MLton). Unless you are doing |
| 80 |
compiler development and need rapid recompilation, we recommend |
| 81 |
compiling with MLton. |