<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="AsciiDoc 8.6.10">
<title>SelfCompiling</title>
<link rel="stylesheet" href="./asciidoc.css" type="text/css">
<link rel="stylesheet" href="./pygments.css" type="text/css">


<script type="text/javascript" src="./asciidoc.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
asciidoc.install();
/*]]>*/
</script>
<link rel="stylesheet" href="./mlton.css" type="text/css">
</head>
<body class="article">
<div id="banner">
<div id="banner-home">
<a href="./Home">MLton 20201002</a>
</div>
</div>
<div id="header">
<h1>SelfCompiling</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>If you want to compile MLton, you must first get the <a href="Sources">Sources</a>. You
can compile with either MLton or SML/NJ, but we strongly recommend
using MLton, since it generates a much faster and more robust
executable.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_compiling_with_mlton">Compiling with MLton</h2>
<div class="sectionbody">
<div class="paragraph"><p>To compile with MLton, you need the binary versions of <span class="monospaced">mlton</span>,
<span class="monospaced">mllex</span>, and <span class="monospaced">mlyacc</span> that come with the MLton binary package.  To be
safe, you should use the same version of MLton that you are building.
However, older versions may work, as long as they don&#8217;t go back too
far.  To build MLton, run <span class="monospaced">make</span> from within the root directory of the
sources.  This will build MLton first with the already installed
binary version of MLton and will then rebuild MLton with itself.</p></div>
<div class="paragraph"><p>First, the <span class="monospaced">Makefile</span> calls <span class="monospaced">mllex</span> and <span class="monospaced">mlyacc</span> to build the lexer
and parser, and then calls <span class="monospaced">mlton</span> to compile itself.  When making
MLton using another version the <span class="monospaced">Makefile</span> automatically uses
<span class="monospaced">mlton-stubs.mlb</span>, which will put in enough stubs to emulate the
<span class="monospaced">structure MLton</span>.  Once MLton is built, the <span class="monospaced">Makefile</span> will rebuild
MLton with itself, this time using <span class="monospaced">mlton.mlb</span> and the real
<span class="monospaced">structure MLton</span> from the <a href="BasisLibrary">Basis Library</a>.  This second round
of compilation is essential in order to achieve a fast and robust
MLton.</p></div>
<div class="paragraph"><p>Compiling MLton requires at least 1GB of RAM for 32-bit platforms (2GB is
preferable) and at least 2GB RAM for 64-bit platforms (4GB is preferable).
If your machine has less RAM, self-compilation will
likely fail, or at least take a very long time due to paging.  Even if
you have enough memory, there simply may not be enough available, due
to memory consumed by other processes.  In this case, you may see an
<span class="monospaced">Out of memory</span> message, or self-compilation may become extremely
slow.  The only fix is to make sure that enough memory is available.</p></div>
<div class="sect2">
<h3 id="_possible_errors">Possible Errors</h3>
<div class="ulist"><ul>
<li>
<p>
The C compiler may not be able to find the <a href="GMP">GMP</a> header file,
<span class="monospaced">gmp.h</span> leading to an error like the following.
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>  cenv.h:49:18: fatal error: gmp.h: No such file or directory</pre>
</div></div>
<div class="paragraph"><p>The solution is to install (or build) <a href="GMP">GMP</a> on your machine.  If you
install it at a location not on the default seach path, then run
<span class="monospaced">make WITH_GMP_INC_DIR=<em>/path/to/gmp/include</em> WITH_GMP_LIB_DIR=<em>/path/to/gmp/lib</em></span>.</p></div>
</li>
<li>
<p>
The following errors indicates that a binary version of MLton could
not be found in your path.
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>/bin/sh: mlton: command not found</pre>
</div></div>
<div class="listingblock">
<div class="content monospaced">
<pre>make[2]: mlton: Command not found</pre>
</div></div>
<div class="paragraph"><p>You need to have <span class="monospaced">mlton</span> in your path to build MLton from source.</p></div>
<div class="paragraph"><p>During the build process, there are various times that the <span class="monospaced">Makefile</span>-s
look for a <span class="monospaced">mlton</span> in your path and in <span class="monospaced">src/build/bin</span>.  It is OK if
the latter doesn&#8217;t exist when the build starts; it is the target being
built.  Failure to find a <span class="monospaced">mlton</span> in your path will abort the build.</p></div>
</li>
</ul></div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_compiling_with_sml_nj">Compiling with SML/NJ</h2>
<div class="sectionbody">
<div class="paragraph"><p>To compile with SML/NJ, run <span class="monospaced">make bootstrap-smlnj</span> from within the
root directory of the sources.  You must use a recent version of
SML/NJ.  First, the <span class="monospaced">Makefile</span> calls <span class="monospaced">ml-lex</span> and <span class="monospaced">ml-yacc</span> to build
the lexer and parser.  Then, it calls SML/NJ with the appropriate
<span class="monospaced">sources.cm</span> file.  Once MLton is built with SML/NJ, the <span class="monospaced">Makefile</span>
will rebuild MLton with this SML/NJ built MLton and then will rebuild
MLton with the MLton built MLton.  Building with SML/NJ takes
significant time (particularly during the "<span class="monospaced">parseAndElaborate</span>" phase
when the SML/NJ built MLton is compiling MLton).  Unless you are doing
compiler development and need rapid recompilation, we recommend
compiling with MLton.</p></div>
</div>
</div>
</div>
<div id="footnotes"><hr></div>
<div id="footer">
<div id="footer-text">
</div>
<div id="footer-badges">
</div>
</div>
</body>
</html>
