<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta name="robots" content="index,nofollow">



<title>SelfCompiling - MLton Standard ML Compiler (SML Compiler)</title>
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="all" href="common.css">
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="screen" href="screen.css">
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="print" href="print.css">


<link rel="Start" href="Home">


</head>

<body lang="en" dir="ltr">

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-833377-1";
urchinTracker();
</script>
<table bgcolor = lightblue cellspacing = 0 style = "border: 0px;" width = 100%>
  <tr>
    <td style = "
		border: 0px;
		color: darkblue; 
		font-size: 150%;
		text-align: left;">
      <a class = mltona href="Home">MLton MLTONWIKIVERSION</a>
    <td style = "
		border: 0px;
		font-size: 150%;
		text-align: center;
		width: 50%;">
      SelfCompiling
    <td style = "
		border: 0px;
		text-align: right;">
      <table cellspacing = 0 style = "border: 0px">
        <tr style = "vertical-align: middle;">
      </table>
  <tr style = "background-color: white;">
    <td colspan = 3
	style = "
		border: 0px;
		font-size:70%;
		text-align: right;">
      <a href = "Home">Home</a>
      &nbsp;<a href = "Index">Index</a>
      &nbsp;
</table>
<div id="content" lang="en" dir="ltr">
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. <h2 id="head-1de0682946bc93df2efbe121609cf7219fc17ca4">Compiling with MLton</h2>
<p>
To compile with MLton, you need the binary versions of <tt>mlton</tt>, <tt>mllex</tt>, and <tt>mlyacc</tt> 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't go back too far.  To build MLton, run <tt>make</tt> 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>
<p>
First, the <tt>Makefile</tt> calls <tt>mllex</tt> and <tt>mlyacc</tt> to build the lexer and parser, and then calls <tt>mlton</tt> to compile itself. When making MLton using another version the <tt>Makefile</tt> automatically uses <tt>mlton-stubs.cm</tt>, which will put in enough stubs to emulate the <tt>MLton</tt> structure.  Once MLton is built, the <tt>Makefile</tt> will rebuild MLton with itself, this time using <tt>mlton.cm</tt> and the real <tt>MLton</tt> structure 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>
<p>
Compiling MLton requires at least 512M of actual RAM, and 1G is preferable.  If your machine has less than 512M, 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 <tt>Out&nbsp;of&nbsp;memory</tt> message, or self-compilation may become extremely slow.  The only fix is to make sure that enough memory is available. 
</p>
<h3 id="head-4db8807336771db69984fb33e2ecb89b2b778d76">Possible Errors</h3>

    <ul>

    <li>
<p>
 If you have errors running <tt>latex</tt>, you can skip building the  documentation by using <tt>make&nbsp;all-no-docs</tt>. 
</p>
</li>
    <li class="gap">
<p>
 The C compiler may not be able to find the <a href="GnuMP">GnuMP</a> header file,  <tt>gmp.h</tt> leading to an error like the following. 
<pre> platform/darwin.h:26:36: /usr/local/include/gmp.h: No such file or directory</pre> The solution is to install (or build) the GnuMP on your machine.  If  you install it at a different location, put the new path in  <tt>runtime/platform/</tt><em>&lt;os&gt;</em><tt>.h</tt>. 
</p>
</li>
    <li class="gap">
<p>
 The following error indicates that a binary version of MLton could  not be found in your path.  
<pre>.../upgrade-basis: mlton: command not found
Error: cannot upgrade basis because the compiler doesn't work
make[3]: *** [upgrade-basis.sml] Error 1
</pre> You need to have <tt>mlton</tt> in your path to build MLton from  source. 
</p>
<p>
 During the build process, there are various times that the <tt>Makefile</tt>s  look for a <tt>mlton</tt> in your path and in <tt>src/build/bin</tt>.  It  is OK if the latter doesn't exist when the build starts; it is the  target being built.  While not finding <tt>build/bin/mlton</tt> also results   in <tt>mlton:&nbsp;command&nbsp;not&nbsp;found</tt> error messages, such errors are benign  and will not abort the build.  Failure to find a <tt>mlton</tt> in your path  will abort the build. 
</p>
</li>
    <li class="gap">
<p>
 Mac OS X executables do not seem to like static libraries to have a different path location at runtime compared to when the executable was built.  For example, the binary package for Mac OS X unpacks to <tt>/usr</tt>.  If you try to install it in <tt>/usr/local</tt> you may get the following errors:  
<pre>/usr/bin/ld: table of contents for archive:
/usr/local/lib/mlton/self/libmlton.a is out of date;
rerun ranlib(1) (can't load from it)
</pre> Although running <tt>ranlib</tt> seems like the right thing to do, it  doesn't actually resolve the problem.  Best bet is to install in  <tt>/usr</tt> and then either live with this location, or build MLton  yourself and install in <tt>/usr/local</tt>. 
</p>
</li>

    </ul>


<h2 id="head-0df153093cbf2253d0cd4f9678b2c577464c35e0">Compiling with SML/NJ</h2>
<p>
To compile with SML/NJ, run <tt>make&nbsp;nj-mlton</tt> from within the root directory of the sources.  You must use a recent version of SML/NJ. First, the <tt>Makefile</tt> calls <tt>mllex</tt> and <tt>mlyacc</tt> to build the lexer and parser.  Then, it calls SML/NJ with the appropriate <tt>sources.cm</tt> file.  Building with SML/NJ takes some time (roughly 10 minutes on a 1.6GHz machine).  Unless you are doing compiler development and need rapid recompilation, we recommend compiling with MLton. 
</p>
</div>



<p>
<hr>
Last edited on 2005-12-02 01:44:46 by <span title="ppp-71-139-183-221.dsl.snfc21.pacbell.net"><a href="StephenWeeks">StephenWeeks</a></span>.
</body></html>
