Merged in RELEASE_11.
[oota-llvm.git] / docs / CFEBuildInstrs.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5   <link rel="stylesheet" href="llvm.css" type="text/css" media="screen" />
6   <title>Bootstrapping the LLVM C/C++ Front-End</title>
7 </head>
8 <body>
9
10 <div class="doc_title">
11   Bootstrapping the LLVM C/C++ Front-End
12 </div>
13
14 <ol>
15   <li><a href="#cautionarynote">A Cautionary Note</a>
16   <li><a href="#instructions">Instructions</a>
17   <li><a href="#license">License Information</a>
18 </ol>
19
20 <div class="doc_text">    
21   <p><b>Written by Brian R. Gaeke</b></p>
22 </div>
23
24 <!-- *********************************************************************** -->
25 <div class="doc_section">
26   <a name="cautionarynote">A Cautionary Note</a>
27 </div>
28 <!-- *********************************************************************** -->
29
30 <div class="doc_text">
31 <p>This document is intended to explain the process of building the
32 LLVM C/C++ front-end, based on GCC 3.4, from its source code. You
33 would have to do this, for example, if you are porting LLVM to a new
34 architecture or operating system.</p>
35
36 <p><b>NOTE:</b> This is currently a somewhat fragile, error-prone
37 process, and you should <b>only</b> try to do it if:</p>
38
39 <ol>
40   <li>you really, really, really can't use the binaries we distribute</li>
41   <li>you need GCC to fix some of the header files on your system</li>
42   <li>you are an elite GCC hacker.</li>
43 </ol>
44
45 <p>We welcome patches to help make this process simpler.</p>
46 </div>
47
48 <!-- *********************************************************************** -->
49 <div class="doc_section">
50   <a name="instructions">Instructions</a>
51 </div>
52 <!-- *********************************************************************** -->
53
54 <div class="doc_text">
55 <p>
56 <ol>
57 <li><p>Configure and build the LLVM libraries and tools using:</p>
58 <pre>
59  % cd llvm
60  % ./configure [options...]
61  % gmake tools-only
62 </pre>
63     <p>The use of the non-default target "tools-only" means that the
64     LLVM tools and libraries will build, and the binaries will be
65     deposited in llvm/tools/Debug, but the runtime (bytecode)
66     libraries will not build.</p></li>
67
68 <li><p>Add the directory containing the tools to your PATH.</p>
69 <pre>
70  % set path = ( `cd llvm/tools/Debug &amp;&amp; pwd` $path )
71 </pre></li>
72
73 <li><p>Unpack the C/C++ front-end source into cfrontend/src.</p></li>
74
75 <li><p>Edit src/configure.  Change the first line (starting w/ #!) to
76        contain the correct full pathname of sh.</p></li>
77
78 <li><p>Make "build" and "install" directories as siblings of the "src"
79        tree.</p>
80 <pre>
81  % pwd
82  /usr/local/example/cfrontend/src
83  % cd ..
84  % mkdir build install
85  % set CFEINSTALL = `pwd`/install
86 </pre></li>
87
88 <li><p>Configure, build, and install the C front-end:</p>
89
90 <p>
91 <b>Linux/x86:</b>
92 </p>
93
94 <pre>
95  % cd build
96  % ../src/configure --prefix=$CFEINSTALL --disable-threads --disable-nls --disable-shared \
97    --enable-languages=c,c++
98  % gmake all-gcc
99  % setenv LLVM_LIB_SEARCH_PATH `pwd`/gcc 
100  % gmake all; gmake install
101 </pre>
102
103 <p>
104 <b>Solaris/Sparc:</b>
105 </p>
106
107 <p>
108 For Solaris/Sparc, LLVM only supports SparcV9.  Therefore, the configure
109 command line should like something like this:
110 </p>
111
112 <pre>
113  % cd build
114  % ../src/configure --prefix=$CFEINSTALL --disable-threads --disable-nls --disable-shared \
115    --enable-languages=c,c++ --host=sparcv9-sun-solaris2.8
116  % gmake all-gcc
117  % setenv LLVM_LIB_SEARCH_PATH `pwd`/gcc 
118  % gmake all
119 </pre>
120
121 <p>
122 At this point, libstdc++ may fail to build because of wchar errors (look for
123 errors that reference <tt>vfwscanf</tt> or <tt>wcstof</tt>).  If that happens,
124 edit <tt>sparcv9-sun-solaris2.8/libstdc++-v3/config.h</tt> and comment out the
125 line that defines <tt>_GLIBCXX_USE_WCHAR_T</tt>.
126 </p>
127
128 <p>
129 Then, continue as below:
130 </p>
131
132 <pre>
133  % gmake all
134  % gmake install
135 </pre>
136
137  <p><b>Common Problem:</b> You may get error messages regarding the fact
138  that LLVM does not support inline assembly. Here are two common
139  fixes:</p>
140
141  <ul>
142   <li><p><b>Fix 1:</b> If you have system header files that include
143    inline assembly, you may have to modify them to remove the inline
144    assembly, and install the modified versions in
145    <code>$CFEINSTALL/<i>target-triplet</i>/sys-include</code>.</p></li>
146
147   <li><b>Fix 2:</b> If you are building the C++ front-end on a CPU we
148    haven't tried yet, you will probably have to edit the appropriate
149    version of atomicity.h under
150    <code>src/libstdc++-v3/config/cpu/<i>name-of-cpu</i>/atomicity.h</code>
151    and apply a patch so that it does not use inline assembly.</p></li>
152  </ul>
153
154  <p><b>Porting to a new architecture:</b> If you are porting the new front-end
155  to a new architecture, or compiling in a different configuration that we have
156  previously, there are probably several changes you will have to make to the GCC
157  target to get it to work correctly.  These include:<p>
158
159  <ul>
160   <li>Often targets include special or assembler linker flags which
161       <tt>gccas</tt>/<tt>gccld</tt> does not understand.  In general, these can
162       just be removed.</li>
163   <li>LLVM currently does not support any floating point values other than 
164       32-bit and 64-bit IEEE floating point.  The primary effect of this is
165       that you may have to map "long double" onto "double".</li>
166   <li>The profiling hooks in GCC do not apply at all to the LLVM front-end.
167       These may need to be disabled.</li>
168   <li>No inline assembly for position independent code.  At the LLVM level,
169       everything is position independent.</li>
170   <li>We handle <tt>.init</tt> and <tt>.fini</tt> differently.</li>
171   <li>You may have to disable multilib support in your target.  Using multilib
172       support causes the GCC compiler driver to add a lot of "<tt>-L</tt>"
173       options to the link line, which do not relate to LLVM and confuse
174       <tt>gccld</tt>.  To disable multilibs, delete any
175       <tt>MULTILIB_OPTIONS</tt> lines from your target files.</li>
176   <li>Did we mention that we don't support inline assembly?  You'll probably
177       have to add some fixinclude hacks to disable it in the system
178       headers.</li>
179  </ul>
180 </li>
181
182 <li><p>Go back into the LLVM source tree proper. Edit Makefile.config
183 to redefine <code>LLVMGCCDIR</code> to the full pathname of the
184 <code>$CFEINSTALL</code> directory, which is the directory you just
185 installed the C front-end into. (The ./configure script is likely to
186 have set this to a directory which does not exist on your system.)</p></li>
187
188 <li><p>If you edited header files during the C/C++ front-end build as
189 described in "Fix 1" above, you must now copy those header files from
190 <code>$CFEINSTALL/<i>target-triplet</i>/sys-include</code> to
191 <code>$CFEINSTALL/lib/gcc/<i>target-triplet</i>/3.4-llvm/include</code>.
192 (This should be the "include" directory in the same directory as the
193 libgcc.a library, which you can find by running
194 <code>$CFEINSTALL/bin/gcc --print-libgcc-file-name</code>.)</p></li>
195
196 <li><p>Build and install the runtime (bytecode) libraries by running:</p>
197 <pre>
198  % gmake -C runtime
199  % mkdir $CFEINSTALL/bytecode-libs
200  % gmake -C runtime install
201  % setenv LLVM_LIB_SEARCH_PATH $CFEINSTALL/bytecode-libs
202 </pre></li>
203
204 <li><p>Test the newly-installed C frontend by one or more of the
205 following means:</p>
206  <ul>
207   <li> compiling and running a "hello, LLVM" program in C and C++.</li>
208   <li> running the tests under <tt>test/Programs</tt> using <code>gmake -C
209    test/Programs</code></li>
210  </ul>
211   </p>
212 </li>
213 </ol>
214 </div>
215
216 <!-- *********************************************************************** -->
217 <div class="doc_section">
218   <a name="license">License Information</a>
219 </div>
220
221 <div class="doc_text">
222 <p>
223 The LLVM GCC frontend is licensed to you under the GNU General Public License
224 and the GNU Lesser General Public License.  Please see the files COPYING and
225 COPYING.LIB for more details.
226 </p>
227
228 <p>
229 The software also has the following additional copyrights:
230 </p>
231
232 <pre>
233 Copyright (c) 1994
234 Hewlett-Packard Company
235
236 Permission to use, copy, modify, distribute and sell this software
237 and its documentation for any purpose is hereby granted without fee,
238 provided that the above copyright notice appear in all copies and
239 that both that copyright notice and this permission notice appear
240 in supporting documentation.  Hewlett-Packard Company makes no
241 representations about the suitability of this software for any
242 purpose.  It is provided "as is" without express or implied warranty.
243
244 Copyright (c) 1996, 1997, 1998, 1999
245 Silicon Graphics Computer Systems, Inc.
246
247 Permission to use, copy, modify, distribute and sell this software
248 and its documentation for any purpose is hereby granted without fee,
249 provided that the above copyright notice appear in all copies and
250 that both that copyright notice and this permission notice appear
251 in supporting documentation.  Silicon Graphics makes no
252 representations about the suitability of this software for any
253 purpose.  It is provided "as is" without express or implied warranty.
254 </pre>
255 </div>
256
257 <!-- *********************************************************************** -->
258 <!-- *********************************************************************** -->
259
260 <hr>
261 <div class="doc_footer">
262   <address>Brian Gaeke</address>
263   <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a>
264   <br>
265   Last modified: $Date$
266 </div>
267
268 </body>
269 </html>