blob: ecdb35b54c6c4d6a5570ea69a493caf5dd10bdad [file] [log] [blame]
Misha Brukmanf6a04072004-05-12 20:57:43 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
John Criswellf2413ae2003-07-03 15:37:52 +00003<html>
Misha Brukmanf6a04072004-05-12 20:57:43 +00004<head>
5 <title>Creating an LLVM Project</title>
6 <link rel="stylesheet" href="llvm.css" type="text/css">
7</head>
8<body>
John Criswellf2413ae2003-07-03 15:37:52 +00009
Misha Brukmanf6a04072004-05-12 20:57:43 +000010<div class="doc_title">Creating an LLVM Project</div>
John Criswellf2413ae2003-07-03 15:37:52 +000011
Misha Brukmanf6a04072004-05-12 20:57:43 +000012<ol>
13<li><a href="#overview">Overview</a></li>
14<li><a href="#create">Create a project from the Sample Project</a></li>
15<li><a href="#source">Source tree layout</a></li>
16<li><a href="#makefiles">Writing LLVM-style Makefiles</a>
17 <ol>
18 <li><a href="#reqVars">Required Variables</a></li>
19 <li><a href="#varsBuildDir">Variables for Building Subdirectories</a></li>
20 <li><a href="#varsBuildLib">Variables for Building Libraries</a></li>
21 <li><a href="#varsBuildProg">Variables for Building Programs</a></li>
22 <li><a href="#miscVars">Miscellaneous Variables</a></li>
23 </ol></li>
24<li><a href="#objcode">Placement of object code</a></li>
25<li><a href="#help">Further help</a></li>
26</ol>
John Criswellf2413ae2003-07-03 15:37:52 +000027
Chris Lattner7911ce22004-05-23 21:07:27 +000028<div class="doc_author">
29 <p>Written by John Criswell</p>
30</div>
31
Misha Brukmanf6a04072004-05-12 20:57:43 +000032<!-- *********************************************************************** -->
33<div class="doc_section"><a name="overview">Overview</a></div>
34<!-- *********************************************************************** -->
John Criswellf2413ae2003-07-03 15:37:52 +000035
Misha Brukmanf6a04072004-05-12 20:57:43 +000036<div class="doc_text">
John Criswell7a4b96d2003-10-16 19:53:53 +000037
Misha Brukmanf6a04072004-05-12 20:57:43 +000038<p>The LLVM build system is designed to facilitate the building of third party
39projects that use LLVM header files, libraries, and tools. In order to use
40these facilities, a Makefile from a project must do the following things:</p>
John Criswell7a4b96d2003-10-16 19:53:53 +000041
Misha Brukmanf6a04072004-05-12 20:57:43 +000042<ol>
43<li>Set environment variables.There are several environment variables that a
44Makefile needs to set to use the LLVM build system:
John Criswell7a4b96d2003-10-16 19:53:53 +000045
Misha Brukmanf6a04072004-05-12 20:57:43 +000046<ul>
47 <li><tt>LLVM_SRC_ROOT</tt> - The root of the LLVM source tree.</li>
48 <li><tt>LLVM_OBJ_ROOT</tt> - The root of the LLVM object tree.</li>
49 <li><tt>BUILD_SRC_ROOT</tt> - The root of the project's source tree.</li>
50 <li><tt>BUILD_OBJ_ROOT</tt> - The root of the project's object tree.</li>
51 <li><tt>BUILD_SRC_DIR</tt> - The directory containing the current source to be
52 compiled.</li>
53 <li><tt>BUILD_OBJ_DIR</tt> - The directory where the current source will place
54 the new object files. This should always be the current directory.</li>
55 <li><tt>LEVEL</tt> - The relative path from the current directory to the root
56 of the object tree.</li>
57</ul></li>
58<li>Include <tt>Makefile.config</tt> from <tt>$(LLVM_OBJ_ROOT)</tt>.</li>
59<li>Include <tt>Makefile.rules</tt> from <tt>$(LLVM_SRC_ROOT)</tt>.</li>
60</ol>
John Criswell7a4b96d2003-10-16 19:53:53 +000061
Misha Brukmanf6a04072004-05-12 20:57:43 +000062<p>There are two ways that you can set all of these variables:</p>
John Criswell7a4b96d2003-10-16 19:53:53 +000063
Misha Brukmanf6a04072004-05-12 20:57:43 +000064<ol>
65<li>You can write your own Makefiles which hard-code these values.</li>
John Criswell7a4b96d2003-10-16 19:53:53 +000066
Misha Brukmanf6a04072004-05-12 20:57:43 +000067<li> You can use the pre-made LLVM sample project. This sample project includes
68Makefiles, a configure script that can be used to configure the location of
69LLVM, and the ability to support multiple object directories from a single
70source directory.</li>
71</ol>
John Criswell7a4b96d2003-10-16 19:53:53 +000072
Misha Brukmanf6a04072004-05-12 20:57:43 +000073<p>This document assumes that you will base your project off of the LLVM sample
74project found in <tt>llvm/projects/sample</tt>. If you want to devise your own
75build system, studying the sample project and LLVM Makefiles will probably
76provide enough information on how to write your own Makefiles.</p>
John Criswell7a4b96d2003-10-16 19:53:53 +000077
Misha Brukmanf6a04072004-05-12 20:57:43 +000078</div>
John Criswell7a4b96d2003-10-16 19:53:53 +000079
Misha Brukmanf6a04072004-05-12 20:57:43 +000080<!-- *********************************************************************** -->
81<div class="doc_section">
82 <a name="create">Create a Project from the Sample Project</a>
83</div>
84<!-- *********************************************************************** -->
John Criswell7a4b96d2003-10-16 19:53:53 +000085
Misha Brukmanf6a04072004-05-12 20:57:43 +000086<div class="doc_text">
John Criswell7a4b96d2003-10-16 19:53:53 +000087
Misha Brukmanf6a04072004-05-12 20:57:43 +000088<p>Follow these simple steps to start your project:</p>
John Criswell7a4b96d2003-10-16 19:53:53 +000089
Misha Brukmanf6a04072004-05-12 20:57:43 +000090<ol>
91<li>Copy the <tt>llvm/projects/sample</tt> directory to any place of your
92choosing. You can place it anywhere you like. Rename the directory to match
93the name of your project.</li>
John Criswell7a4b96d2003-10-16 19:53:53 +000094
Misha Brukmanf6a04072004-05-12 20:57:43 +000095<li>Add your source code and Makefiles to your source tree.</li>
John Criswell7a4b96d2003-10-16 19:53:53 +000096
Misha Brukmanf6a04072004-05-12 20:57:43 +000097<li>If you want your Makefiles to be configured by the <tt>configure</tt>
98script, or if you want to support multiple object directories, add your
99Makefiles to the <tt>configure</tt> script by adding them into the
100<tt>autoconf/configure.ac</tt> file. The macro <tt>AC_CONFIG_MAKEFILE</tt> will
101copy a file, unmodified, from the source directory to the object directory.</li>
John Criswellf2413ae2003-07-03 15:37:52 +0000102
Misha Brukmanf6a04072004-05-12 20:57:43 +0000103<li>After updating <tt>autoconf/configure.ac</tt>, regenerate the
104configure script with these commands:
John Criswellf2413ae2003-07-03 15:37:52 +0000105
Misha Brukmanf6a04072004-05-12 20:57:43 +0000106<div class="doc_code">
107<p><tt>% cd autoconf<br>
108 % autoconf -o ../configure</tt></p>
109</div>
John Criswellf2413ae2003-07-03 15:37:52 +0000110
Misha Brukmanf6a04072004-05-12 20:57:43 +0000111<p>You must be using Autoconf version 2.57 or higher.</p></li>
John Criswell7a4b96d2003-10-16 19:53:53 +0000112
Misha Brukmanf6a04072004-05-12 20:57:43 +0000113<li>Run <tt>configure</tt> in the directory in which you want to place
114object code. Use the following options to tell your project where it
115can find LLVM:
John Criswell7a4b96d2003-10-16 19:53:53 +0000116
Misha Brukmanf6a04072004-05-12 20:57:43 +0000117 <dl>
118 <dt><tt>--with-llvmsrc=&lt;directory&gt;</tt>
119 <dd>
120 Tell your project where the LLVM source tree is located.
121 <p>
122 <dt><tt>--with-llvmobj=&lt;directory&gt;</tt>
123 <dd>
124 Tell your project where the LLVM object tree is located.
125 </dl>
126</ol>
John Criswell7a4b96d2003-10-16 19:53:53 +0000127
Misha Brukmanf6a04072004-05-12 20:57:43 +0000128<p>That's it! Now all you have to do is type <tt>gmake</tt> in the root of
129your object directory, and your project should build.</p>
John Criswellf2413ae2003-07-03 15:37:52 +0000130
Misha Brukmanf6a04072004-05-12 20:57:43 +0000131</div>
John Criswell7a4b96d2003-10-16 19:53:53 +0000132
Misha Brukmanf6a04072004-05-12 20:57:43 +0000133<!-- *********************************************************************** -->
134<div class="doc_section">
135 <a name="source">Source Tree Layout</a>
136</div>
137<!-- *********************************************************************** -->
John Criswellf2413ae2003-07-03 15:37:52 +0000138
Misha Brukmanf6a04072004-05-12 20:57:43 +0000139<div class="doc_text">
John Criswell7a4b96d2003-10-16 19:53:53 +0000140
Misha Brukmanf6a04072004-05-12 20:57:43 +0000141<p>In order to use the LLVM build system, you will want to organize your
142source code so that it can benefit from the build system's features.
143Mainly, you want your source tree layout to look similar to the LLVM
144source tree layout. The best way to do this is to just copy the
145project tree from <tt>llvm/projects/sample</tt> and modify it to meet
146your needs, but you can certainly add to it if you want.</p>
John Criswellf2413ae2003-07-03 15:37:52 +0000147
Misha Brukmanf6a04072004-05-12 20:57:43 +0000148<p>Underneath your top level directory, you should have the following
149directories:</p>
John Criswellf2413ae2003-07-03 15:37:52 +0000150
Misha Brukmanf6a04072004-05-12 20:57:43 +0000151<dl>
152 <dt><b>lib</b>
153 <dd>
154 This subdirectory should contain all of your library source
155 code. For each library that you build, you will have one
156 directory in <b>lib</b> that will contain that library's source
157 code.
John Criswellf2413ae2003-07-03 15:37:52 +0000158
Misha Brukmanf6a04072004-05-12 20:57:43 +0000159 <p>
160 Libraries can be object files, archives, or dynamic libraries.
161 The <b>lib</b> directory is just a convenient place for libraries
162 as it places them all in a directory from which they can be linked
163 later.
John Criswellf2413ae2003-07-03 15:37:52 +0000164
Misha Brukmanf6a04072004-05-12 20:57:43 +0000165 <dt><b>include</b>
166 <dd>
167 This subdirectory should contain any header files that are
168 global to your project. By global, we mean that they are used
169 by more than one library or executable of your project.
170 <p>
171 By placing your header files in <b>include</b>, they will be
172 found automatically by the LLVM build system. For example, if
173 you have a file <b>include/jazz/note.h</b>, then your source
174 files can include it simply with <b>#include "jazz/note.h"</b>.
John Criswellf2413ae2003-07-03 15:37:52 +0000175
Misha Brukmanf6a04072004-05-12 20:57:43 +0000176 <dt><b>tools</b>
177 <dd>
178 This subdirectory should contain all of your source
179 code for executables. For each program that you build, you
180 will have one directory in <b>tools</b> that will contain that
181 program's source code.
182 <p>
John Criswellf2413ae2003-07-03 15:37:52 +0000183
Misha Brukmanf6a04072004-05-12 20:57:43 +0000184 <dt><b>test</b>
185 <dd>
186 This subdirectory should contain tests that verify that your code
187 works correctly. Automated tests are especially useful.
188 <p>
189 Currently, the LLVM build system provides little support for tests,
190 although some exists. Expanded support for tests will hopefully
191 occur in the future. In the meantime, the LLVM system does provide the
192 following:
193 <ul>
194 <li>
195 LLVM provides several QMTest test classes that can be used to
196 create tests. They can be found in
197 <tt>llvm/test/QMTest/llvm.py</tt>. These test classes perform a
198 variety of functions, including code optimization tests, assembly
199 tests, and code analysis tests. The Makefile in
200 <tt>llvm/test</tt> provides the QMTest context needed by LLVM test
201 classes.
202 <p>
John Criswell2b89a6a2003-10-21 19:35:06 +0000203
Misha Brukmanf6a04072004-05-12 20:57:43 +0000204 <li>
205 The LLVM source tree provides benchmarks and programs which are
206 known to compile with the LLVM GCC front ends. You can use these
207 programs to test your code, gather statistics information, and
208 compare it to the current LLVM performance statistics. These
209 programs are found in the <tt>llvm/test/Programs</tt> directory.
210 <p>
211 Currently, there is no way to hook your tests directly into the
212 <tt>llvm/test/Programs</tt> testing harness. You will simply
213 need to find a way to use the source provided within that directory
214 on your own.
215 </ul>
216</dl>
John Criswell2b89a6a2003-10-21 19:35:06 +0000217
Misha Brukmanf6a04072004-05-12 20:57:43 +0000218<p>Typically, you will want to build your <b>lib</b> directory first followed by
219your <b>tools</b> directory.</p>
John Criswellf2413ae2003-07-03 15:37:52 +0000220
Misha Brukmanf6a04072004-05-12 20:57:43 +0000221</div>
John Criswellf2413ae2003-07-03 15:37:52 +0000222
Misha Brukmanf6a04072004-05-12 20:57:43 +0000223<!-- *********************************************************************** -->
224<div class="doc_section">
225 <a name="makefiles">Writing LLVM Style Makefiles</a>
226</div>
227<!-- *********************************************************************** -->
John Criswellf2413ae2003-07-03 15:37:52 +0000228
Misha Brukmanf6a04072004-05-12 20:57:43 +0000229<div class="doc_text">
John Criswellf2413ae2003-07-03 15:37:52 +0000230
Misha Brukmanf6a04072004-05-12 20:57:43 +0000231<p>The LLVM build system provides a convenient way to build libraries and
232executables. Most of your project Makefiles will only need to define a few
233variables. Below is a list of the variables one can set and what they can
234do:</p>
John Criswellf2413ae2003-07-03 15:37:52 +0000235
Misha Brukmanf6a04072004-05-12 20:57:43 +0000236</div>
John Criswellf2413ae2003-07-03 15:37:52 +0000237
Misha Brukmanf6a04072004-05-12 20:57:43 +0000238<!-- ======================================================================= -->
239<div class="doc_subsection">
240 <a name="reqVars">Required Variables</a>
241</div>
John Criswellf2413ae2003-07-03 15:37:52 +0000242
Misha Brukmanf6a04072004-05-12 20:57:43 +0000243<div class="doc_text">
John Criswellf2413ae2003-07-03 15:37:52 +0000244
Misha Brukmanf6a04072004-05-12 20:57:43 +0000245<dl>
246 <dt>LEVEL
247 <dd>
248 This variable is the relative path from this Makefile to the
249 top directory of your project's source code. For example, if
250 your source code is in <tt>/tmp/src</tt>, then the Makefile in
251 <tt>/tmp/src/jump/high</tt> would set <tt>LEVEL</tt> to <tt>"../.."</tt>.
252</dl>
John Criswellf2413ae2003-07-03 15:37:52 +0000253
Misha Brukmanf6a04072004-05-12 20:57:43 +0000254</div>
John Criswellf2413ae2003-07-03 15:37:52 +0000255
Misha Brukmanf6a04072004-05-12 20:57:43 +0000256<!-- ======================================================================= -->
257<div class="doc_subsection">
258 <a name="varsBuildDir">Variables for Building Subdirectories</a>
259</div>
John Criswellf2413ae2003-07-03 15:37:52 +0000260
Misha Brukmanf6a04072004-05-12 20:57:43 +0000261<div class="doc_text">
John Criswell37c154a2003-10-17 21:50:38 +0000262
Misha Brukmanf6a04072004-05-12 20:57:43 +0000263<dl>
264 <dt>DIRS
265 <dd>
266 This is a space separated list of subdirectories that should be
267 built. They will be built, one at a time, in the order
268 specified.
269 <p>
John Criswellf2413ae2003-07-03 15:37:52 +0000270
Misha Brukmanf6a04072004-05-12 20:57:43 +0000271 <dt>PARALLEL_DIRS
272 <dd>
273 This is a list of directories that can be built in parallel.
274 These will be built after the directories in DIRS have been
275 built.
276 <p>
John Criswellf2413ae2003-07-03 15:37:52 +0000277
Misha Brukmanf6a04072004-05-12 20:57:43 +0000278 <dt>OPTIONAL_DIRS
279 <dd>
280 This is a list of directories that can be built if they exist,
281 but will not cause an error if they do not exist. They are
282 built serially in the order in which they are listed.
283</dl>
John Criswellf2413ae2003-07-03 15:37:52 +0000284
Misha Brukmanf6a04072004-05-12 20:57:43 +0000285</div>
John Criswell7a4b96d2003-10-16 19:53:53 +0000286
Misha Brukmanf6a04072004-05-12 20:57:43 +0000287<!-- ======================================================================= -->
288<div class="doc_subsection">
289 <a name="varsBuildLib">Variables for Building Libraries</a>
290</div>
John Criswell7a4b96d2003-10-16 19:53:53 +0000291
Misha Brukmanf6a04072004-05-12 20:57:43 +0000292<div class="doc_text">
John Criswell7a4b96d2003-10-16 19:53:53 +0000293
Misha Brukmanf6a04072004-05-12 20:57:43 +0000294<dl>
295 <dt>LIBRARYNAME
296 <dd>
297 This variable contains the base name of the library that will
298 be built. For example, to build a library named
299 <tt>libsample.a</tt>, LIBRARYNAME should be set to
300 <tt>sample</tt>.
301 <p>
John Criswell7a4b96d2003-10-16 19:53:53 +0000302
Misha Brukmanf6a04072004-05-12 20:57:43 +0000303 <dt>BUILD_ARCHIVE
304 <dd>
305 By default, a library is a <tt>.o</tt> file that is linked
306 directly into a program. To build an archive (also known as
307 a static library), set the BUILD_ARCHIVE variable.
308 <p>
John Criswell7a4b96d2003-10-16 19:53:53 +0000309
Misha Brukmanf6a04072004-05-12 20:57:43 +0000310 <dt>SHARED_LIBRARY
311 <dd>
312 If SHARED_LIBRARY is defined in your Makefile, a shared
313 (or dynamic) library will be built.
314</dl>
315
316</div>
317
318<!-- ======================================================================= -->
319<div class="doc_subsection">
320 <a name="varsBuildProg">Variables for Building Programs</a>
321</div>
322
323<div class="doc_text">
324
325<dl>
326 <dt>TOOLNAME
327 <dd>
328 This variable contains the name of the program that will
329 be built. For example, to build an executable named
330 <tt>sample</tt>, TOOLNAME should be set to <tt>sample</tt>.
331 <p>
332
333 <dt>USEDLIBS
334 <dd>
335 This variable holds a space separated list of libraries that
336 should be linked into the program. These libraries must either
337 be LLVM libraries or libraries that come from your <b>lib</b>
338 directory. The libraries must be specified by their base name.
339 For example, to link libsample.a, you would set USEDLIBS to
340 <tt>sample</tt>.
341 <p>
342 Note that this works only for statically linked libraries.
343 <p>
344
345 <dt>LIBS
346 <dd>
347 To link dynamic libraries, add <tt>-l&lt;library base name&gt;</tt> to
348 the LIBS variable. The LLVM build system will look in the same places
349 for dynamic libraries as it does for static libraries.
350 <p>
351 For example, to link <tt>libsample.so</tt>, you would have the
352 following line in your <tt>Makefile</tt>:
353 <p>
354 <tt>
355 LIBS += -lsample
356 </tt>
357</dl>
358
359</div>
360
361<!-- ======================================================================= -->
362<div class="doc_subsection">
363 <a name="miscVars">Miscellaneous Variables</a>
364</div>
365
366<div class="doc_text">
367
368<dl>
369 <dt>ExtraSource
370 <dd>
371 This variable contains a space separated list of extra source
372 files that need to be built. It is useful for including the
373 output of Lex and Yacc programs.
374 <p>
375
376 <dt>CFLAGS
377 <dt>CPPFLAGS
378 <dd>
379 This variable can be used to add options to the C and C++
380 compiler, respectively. It is typically used to add options
381 that tell the compiler the location of additional directories
382 to search for header files.
383 <p>
384 It is highly suggested that you append to CFLAGS and CPPFLAGS as
385 opposed to overwriting them. The master Makefiles may already
386 have useful options in them that you may not want to overwrite.
387 <p>
388</dl>
389
390</div>
391
392<!-- *********************************************************************** -->
393<div class="doc_section">
394 <a name="objcode">Placement of Object Code</a>
395</div>
396<!-- *********************************************************************** -->
397
398<div class="doc_text">
399
400<p>The final location of built libraries and executables will depend upon
401whether you do a Debug, Release, or Profile build.</p>
402
403<dl>
404 <dt>Libraries
405 <dd>
406 All libraries (static and dynamic) will be stored in
407 <tt>BUILD_OBJ_ROOT/lib/&lt;type&gt;</tt>, where type is <tt>Debug</tt>,
408 <tt>Release</tt>, or <tt>Profile</tt> for a debug, optimized, or
409 profiled build, respectively.<p>
410
411 <dt>Executables
412 <dd>All executables will be stored in
413 <tt>BUILD_OBJ_ROOT/tools/&lt;type&gt;</tt>, where type is <tt>Debug</tt>,
414 <tt>Release</tt>, or <tt>Profile</tt> for a debug, optimized, or profiled
415 build, respectively.
416</dl>
417
418</div>
419
420<!-- *********************************************************************** -->
421<div class="doc_section">
422 <a name="help">Further Help</a>
423</div>
424<!-- *********************************************************************** -->
425
426<div class="doc_text">
427
428<p>If you have any questions or need any help creating an LLVM project,
429the LLVM team would be more than happy to help. You can always post your
430questions to the <a
431href="http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev">LLVM Developers
432Mailing List</a>.</p>
433
434</div>
435
436<!-- *********************************************************************** -->
John Criswell7a4b96d2003-10-16 19:53:53 +0000437<hr>
Misha Brukmanf6a04072004-05-12 20:57:43 +0000438<address>
439 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
440 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
441 <a href="http://validator.w3.org/check/referer"><img
442 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
443
444 <a href="mailto:criswell@uiuc.edu">John Criswell</a><br>
445 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a>
446 <br>
447 Last modified: $Date$
448</address>
Misha Brukman733adcb2003-10-30 01:23:40 +0000449
John Criswellf2413ae2003-07-03 15:37:52 +0000450</body>
451</html>