<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="AsciiDoc 8.6.8">
<title>CompilingWithSMLNJ</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 20130715</a>
</div>
</div>
<div id="header">
<h1>CompilingWithSMLNJ</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>You can compile MLton with <a href="SMLNJ">SML/NJ</a>, however the resulting
compiler will run much more slowly than MLton compiled by itself.  We
don&#8217;t recommend using SML/NJ as a means of
<a href="PortingMLton">porting MLton</a> to a new platform or bootstrapping on a
new platform.</p></div>
<div class="paragraph"><p>If you do want to build MLton with SML/NJ, it is best to have a binary
MLton package installed.  If you don&#8217;t, here are some issues you may
encounter when you run <span class="monospaced">make nj-mlton</span>.</p></div>
<div class="paragraph"><p>You will get (many copies of) the error message:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>/bin/sh: mlton: not found</pre>
</div></div>
<div class="paragraph"><p>The <span class="monospaced">Makefile</span> calls <span class="monospaced">mlton</span> to determine dependencies, and can
proceed in spite of this error.</p></div>
<div class="paragraph"><p>If you don&#8217;t have a <span class="monospaced">mlton</span> executable, you will get the error
message:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>Error: cannot upgrade basis because the compiler doesn't work</pre>
</div></div>
<div class="paragraph"><p>We use <span class="monospaced">upgrade-basis.sml</span> to work around basis library differences,
allowing a version of MLton written for a newer basis library to be
compiled by an older version of MLton.  The file isn&#8217;t necessary when
building with SML/NJ, but is listed in <span class="monospaced">$(SOURCES)</span>, so the <span class="monospaced">Makefile</span>
is attempting to build it.  Building <span class="monospaced">upgrade-basis.sml</span> requires the
old version of MLton to be around so that the right stubs can be
built.</p></div>
<div class="paragraph"><p>To work around this problem, do one of the following.</p></div>
<div class="ulist"><ul>
<li>
<p>
Manually tweak sources to remove <span class="monospaced">$(UP)</span> until you&#8217;re finished
building MLton with SML/NJ and have a working MLton.
</p>
</li>
<li>
<p>
Build <span class="monospaced">upgrade-basis.sml</span> on some other machine with a working MLton
and copy it over.
</p>
</li>
</ul></div>
<div class="paragraph"><p>If you don&#8217;t have an <span class="monospaced">mllex</span> executable, you will get the error
message:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>mllex: Command not found</pre>
</div></div>
<div class="paragraph"><p>Building MLton requires <span class="monospaced">mllex</span> and <span class="monospaced">mlyacc</span> executables, which are
distributed with a binary package of MLton.  The easiest solution is
to copy the front-end lexer/parser files from a different machine
(<span class="monospaced">ml.grm.sml</span>, <span class="monospaced">ml.grm.sig</span>, <span class="monospaced">ml.lex.sml</span>, <span class="monospaced">mlb.grm.sig</span>,
<span class="monospaced">mlb.grm.sml</span>).</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>
