Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / localhost / CrossCompiling
CommitLineData
7f918cf1
CE
1<!DOCTYPE html>\r
2<html lang="en">\r
3<head>\r
4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\r
5<meta name="generator" content="AsciiDoc 8.6.9">\r
6<title>CrossCompiling</title>\r
7<link rel="stylesheet" href="./asciidoc.css" type="text/css">\r
8<link rel="stylesheet" href="./pygments.css" type="text/css">\r
9\r
10\r
11<script type="text/javascript" src="./asciidoc.js"></script>\r
12<script type="text/javascript">\r
13/*<![CDATA[*/\r
14asciidoc.install();\r
15/*]]>*/\r
16</script>\r
17<link rel="stylesheet" href="./mlton.css" type="text/css">\r
18</head>\r
19<body class="article">\r
20<div id="banner">\r
21<div id="banner-home">\r
22<a href="./Home">MLton 20180207</a>\r
23</div>\r
24</div>\r
25<div id="header">\r
26<h1>CrossCompiling</h1>\r
27</div>\r
28<div id="content">\r
29<div id="preamble">\r
30<div class="sectionbody">\r
31<div class="paragraph"><p>MLton&#8217;s <span class="monospaced">-target</span> flag directs MLton to cross compile an application\r
32for another platform. By default, MLton is only able to compile for\r
33the machine it is running on. In order to use MLton as a cross\r
34compiler, you need to do two things.</p></div>\r
35<div class="olist arabic"><ol class="arabic">\r
36<li>\r
37<p>\r
38Install the GCC cross-compiler tools on the host so that GCC can\r
39compile to the target.\r
40</p>\r
41</li>\r
42<li>\r
43<p>\r
44Cross compile the MLton runtime system to build the runtime\r
45libraries for the target.\r
46</p>\r
47</li>\r
48</ol></div>\r
49<div class="paragraph"><p>To make the terminology clear, we refer to the <em>host</em> as the machine\r
50MLton is running on and the <em>target</em> as the machine that MLton is\r
51compiling for.</p></div>\r
52<div class="paragraph"><p>To build a GCC cross-compiler toolset on the host, you can use the\r
53script <span class="monospaced">bin/build-cross-gcc</span>, available in the MLton sources, as a\r
54template. The value of the <span class="monospaced">target</span> variable in that script is\r
55important, since that is what you will pass to MLton&#8217;s <span class="monospaced">-target</span> flag.\r
56Once you have the toolset built, you should be able to test it by\r
57cross compiling a simple hello world program on your host machine.</p></div>\r
58<div class="listingblock">\r
59<div class="content monospaced">\r
60<pre>% gcc -b i386-pc-cygwin -o hello-world hello-world.c</pre>\r
61</div></div>\r
62<div class="paragraph"><p>You should now be able to run <span class="monospaced">hello-world</span> on the target machine, in\r
63this case, a Cygwin machine.</p></div>\r
64<div class="paragraph"><p>Next, you must cross compile the MLton runtime system and inform MLton\r
65of the availability of the new target. The script <span class="monospaced">bin/add-cross</span>\r
66from the MLton sources will help you do this. Please read the\r
67comments at the top of the script. Here is a sample run adding a\r
68Solaris cross compiler.</p></div>\r
69<div class="listingblock">\r
70<div class="content monospaced">\r
71<pre>% add-cross sparc-sun-solaris sun blade\r
72Making runtime.\r
73Building print-constants executable.\r
74Running print-constants on blade.</pre>\r
75</div></div>\r
76<div class="paragraph"><p>Running <span class="monospaced">add-cross</span> uses <span class="monospaced">ssh</span> to compile the runtime on the target\r
77machine and to create <span class="monospaced">print-constants</span>, which prints out all of the\r
78constants that MLton needs in order to implement the\r
79<a href="BasisLibrary">Basis Library</a>. The script runs <span class="monospaced">print-constants</span> on\r
80the target machine (<span class="monospaced">blade</span> in this case), and saves the output.</p></div>\r
81<div class="paragraph"><p>Once you have done all this, you should be able to cross compile SML\r
82applications. For example,</p></div>\r
83<div class="listingblock">\r
84<div class="content monospaced">\r
85<pre>mlton -target i386-pc-cygwin hello-world.sml</pre>\r
86</div></div>\r
87<div class="paragraph"><p>will create <span class="monospaced">hello-world</span>, which you should be able to run from a\r
88Cygwin shell on your Windows machine.</p></div>\r
89</div>\r
90</div>\r
91<div class="sect1">\r
92<h2 id="_cross_compiling_alternatives">Cross-compiling alternatives</h2>\r
93<div class="sectionbody">\r
94<div class="paragraph"><p>Building and maintaining cross-compiling <span class="monospaced">gcc</span>'s is complex. You may\r
95find it simpler to use <span class="monospaced">mlton -keep g</span> to generate the files on the\r
96host, then copy the files to the target, and then use <span class="monospaced">gcc</span> or <span class="monospaced">mlton</span>\r
97on the target to compile the files.</p></div>\r
98</div>\r
99</div>\r
100</div>\r
101<div id="footnotes"><hr></div>\r
102<div id="footer">\r
103<div id="footer-text">\r
104</div>\r
105<div id="footer-badges">\r
106</div>\r
107</div>\r
108</body>\r
109</html>\r