Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / localhost / SelfCompiling
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta name="generator" content="AsciiDoc 8.6.9">
6 <title>SelfCompiling</title>
7 <link rel="stylesheet" href="./asciidoc.css" type="text/css">
8 <link rel="stylesheet" href="./pygments.css" type="text/css">
9
10
11 <script type="text/javascript" src="./asciidoc.js"></script>
12 <script type="text/javascript">
13 /*<![CDATA[*/
14 asciidoc.install();
15 /*]]>*/
16 </script>
17 <link rel="stylesheet" href="./mlton.css" type="text/css">
18 </head>
19 <body class="article">
20 <div id="banner">
21 <div id="banner-home">
22 <a href="./Home">MLton 20180207</a>
23 </div>
24 </div>
25 <div id="header">
26 <h1>SelfCompiling</h1>
27 </div>
28 <div id="content">
29 <div id="preamble">
30 <div class="sectionbody">
31 <div class="paragraph"><p>If you want to compile MLton, you must first get the <a href="Sources">Sources</a>. You
32 can compile with either MLton or SML/NJ, but we strongly recommend
33 using MLton, since it generates a much faster and more robust
34 executable.</p></div>
35 </div>
36 </div>
37 <div class="sect1">
38 <h2 id="_compiling_with_mlton">Compiling with MLton</h2>
39 <div class="sectionbody">
40 <div class="paragraph"><p>To compile with MLton, you need the binary versions of <span class="monospaced">mlton</span>,
41 <span class="monospaced">mllex</span>, and <span class="monospaced">mlyacc</span> that come with the MLton binary package. To be
42 safe, you should use the same version of MLton that you are building.
43 However, older versions may work, as long as they don&#8217;t go back too
44 far. To build MLton, run <span class="monospaced">make</span> from within the root directory of the
45 sources. This will build MLton first with the already installed
46 binary version of MLton and will then rebuild MLton with itself.</p></div>
47 <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
48 and parser, and then calls <span class="monospaced">mlton</span> to compile itself. When making
49 MLton using another version the <span class="monospaced">Makefile</span> automatically uses
50 <span class="monospaced">mlton-stubs.mlb</span>, which will put in enough stubs to emulate the
51 <span class="monospaced">structure MLton</span>. Once MLton is built, the <span class="monospaced">Makefile</span> will rebuild
52 MLton with itself, this time using <span class="monospaced">mlton.mlb</span> and the real
53 <span class="monospaced">structure MLton</span> from the <a href="BasisLibrary">Basis Library</a>. This second round
54 of compilation is essential in order to achieve a fast and robust
55 MLton.</p></div>
56 <div class="paragraph"><p>Compiling MLton requires at least 1GB of RAM for 32-bit platforms (2GB is
57 preferable) and at least 2GB RAM for 64-bit platforms (4GB is preferable).
58 If your machine has less RAM, self-compilation will
59 likely fail, or at least take a very long time due to paging. Even if
60 you have enough memory, there simply may not be enough available, due
61 to memory consumed by other processes. In this case, you may see an
62 <span class="monospaced">Out of memory</span> message, or self-compilation may become extremely
63 slow. The only fix is to make sure that enough memory is available.</p></div>
64 <div class="sect2">
65 <h3 id="_possible_errors">Possible Errors</h3>
66 <div class="ulist"><ul>
67 <li>
68 <p>
69 The C compiler may not be able to find the <a href="GnuMP">GnuMP</a> header file,
70 <span class="monospaced">gmp.h</span> leading to an error like the following.
71 </p>
72 <div class="listingblock">
73 <div class="content monospaced">
74 <pre> cenv.h:49:18: fatal error: gmp.h: No such file or directory</pre>
75 </div></div>
76 <div class="paragraph"><p>The solution is to install (or build) GnuMP on your machine. If you
77 install it at a location not on the default seach path, then run
78 <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>
79 </li>
80 <li>
81 <p>
82 The following errors indicates that a binary version of MLton could
83 not be found in your path.
84 </p>
85 <div class="listingblock">
86 <div class="content monospaced">
87 <pre>/bin/sh: mlton: command not found</pre>
88 </div></div>
89 <div class="listingblock">
90 <div class="content monospaced">
91 <pre>make[2]: mlton: Command not found</pre>
92 </div></div>
93 <div class="paragraph"><p>You need to have <span class="monospaced">mlton</span> in your path to build MLton from source.</p></div>
94 <div class="paragraph"><p>During the build process, there are various times that the <span class="monospaced">Makefile</span>-s
95 look for a <span class="monospaced">mlton</span> in your path and in <span class="monospaced">src/build/bin</span>. It is OK if
96 the latter doesn&#8217;t exist when the build starts; it is the target being
97 built. Failure to find a <span class="monospaced">mlton</span> in your path will abort the build.</p></div>
98 </li>
99 </ul></div>
100 </div>
101 </div>
102 </div>
103 <div class="sect1">
104 <h2 id="_compiling_with_sml_nj">Compiling with SML/NJ</h2>
105 <div class="sectionbody">
106 <div class="paragraph"><p>To compile with SML/NJ, run <span class="monospaced">make bootstrap-smlnj</span> from within the
107 root directory of the sources. You must use a recent version of
108 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
109 the lexer and parser. Then, it calls SML/NJ with the appropriate
110 <span class="monospaced">sources.cm</span> file. Once MLton is built with SML/NJ, the <span class="monospaced">Makefile</span>
111 will rebuild MLton with this SML/NJ built MLton and then will rebuild
112 MLton with the MLton built MLton. Building with SML/NJ takes
113 significant time (particularly during the "<span class="monospaced">parseAndElaborate</span>" phase
114 when the SML/NJ built MLton is compiling MLton). Unless you are doing
115 compiler development and need rapid recompilation, we recommend
116 compiling with MLton.</p></div>
117 </div>
118 </div>
119 </div>
120 <div id="footnotes"><hr></div>
121 <div id="footer">
122 <div id="footer-text">
123 </div>
124 <div id="footer-badges">
125 </div>
126 </div>
127 </body>
128 </html>