1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>Creating an LLVM Project</title>
7 <link rel="stylesheet" href="llvm.css" type="text/css">
11 <h1>Creating an LLVM Project</h1>
14 <li><a href="#overview">Overview</a></li>
15 <li><a href="#create">Create a project from the Sample Project</a></li>
16 <li><a href="#source">Source tree layout</a></li>
17 <li><a href="#makefiles">Writing LLVM-style Makefiles</a>
19 <li><a href="#reqVars">Required Variables</a></li>
20 <li><a href="#varsBuildDir">Variables for Building Subdirectories</a></li>
21 <li><a href="#varsBuildLib">Variables for Building Libraries</a></li>
22 <li><a href="#varsBuildProg">Variables for Building Programs</a></li>
23 <li><a href="#miscVars">Miscellaneous Variables</a></li>
25 <li><a href="#objcode">Placement of object code</a></li>
26 <li><a href="#help">Further help</a></li>
29 <div class="doc_author">
30 <p>Written by John Criswell</p>
33 <!-- *********************************************************************** -->
34 <h2><a name="overview">Overview</a></h2>
35 <!-- *********************************************************************** -->
39 <p>The LLVM build system is designed to facilitate the building of third party
40 projects that use LLVM header files, libraries, and tools. In order to use
41 these facilities, a Makefile from a project must do the following things:</p>
44 <li>Set <tt>make</tt> variables. There are several variables that a Makefile
45 needs to set to use the LLVM build system:
47 <li><tt>PROJECT_NAME</tt> - The name by which your project is known.</li>
48 <li><tt>LLVM_SRC_ROOT</tt> - The root of the LLVM source tree.</li>
49 <li><tt>LLVM_OBJ_ROOT</tt> - The root of the LLVM object tree.</li>
50 <li><tt>PROJ_SRC_ROOT</tt> - The root of the project's source tree.</li>
51 <li><tt>PROJ_OBJ_ROOT</tt> - The root of the project's object tree.</li>
52 <li><tt>PROJ_INSTALL_ROOT</tt> - The root installation directory.</li>
53 <li><tt>LEVEL</tt> - The relative path from the current directory to the
54 project's root ($PROJ_OBJ_ROOT).</li>
56 <li>Include <tt>Makefile.config</tt> from <tt>$(LLVM_OBJ_ROOT)</tt>.</li>
57 <li>Include <tt>Makefile.rules</tt> from <tt>$(LLVM_SRC_ROOT)</tt>.</li>
60 <p>There are two ways that you can set all of these variables:</p>
62 <li>You can write your own Makefiles which hard-code these values.</li>
63 <li>You can use the pre-made LLVM sample project. This sample project
64 includes Makefiles, a configure script that can be used to configure the
65 location of LLVM, and the ability to support multiple object directories
66 from a single source directory.</li>
69 <p>This document assumes that you will base your project on the LLVM sample
70 project found in <tt>llvm/projects/sample</tt>. If you want to devise your own
71 build system, studying the sample project and LLVM Makefiles will probably
72 provide enough information on how to write your own Makefiles.</p>
76 <!-- *********************************************************************** -->
78 <a name="create">Create a Project from the Sample Project</a>
80 <!-- *********************************************************************** -->
84 <p>Follow these simple steps to start your project:</p>
87 <li>Copy the <tt>llvm/projects/sample</tt> directory to any place of your
88 choosing. You can place it anywhere you like. Rename the directory to match
89 the name of your project.</li>
92 If you downloaded LLVM using Subversion, remove all the directories named .svn
93 (and all the files therein) from your project's new source tree. This will
94 keep Subversion from thinking that your project is inside
95 <tt>llvm/trunk/projects/sample</tt>.</li>
97 <li>Add your source code and Makefiles to your source tree.</li>
99 <li>If you want your project to be configured with the <tt>configure</tt> script
100 then you need to edit <tt>autoconf/configure.ac</tt> as follows:
102 <li><b>AC_INIT</b>. Place the name of your project, its version number and
103 a contact email address for your project as the arguments to this macro</li>
104 <li><b>AC_CONFIG_AUX_DIR</b>. If your project isn't in the
105 <tt>llvm/projects</tt> directory then you might need to adjust this so that
106 it specifies a relative path to the <tt>llvm/autoconf</tt> directory.</li>
107 <li><b>LLVM_CONFIG_PROJECT</b>. Just leave this alone.</li>
108 <li><b>AC_CONFIG_SRCDIR</b>. Specify a path to a file name that identifies
109 your project; or just leave it at <tt>Makefile.common.in</tt></li>
110 <li><b>AC_CONFIG_FILES</b>. Do not change.</li>
111 <li><b>AC_CONFIG_MAKEFILE</b>. Use one of these macros for each Makefile
112 that your project uses. This macro arranges for your makefiles to be copied
113 from the source directory, unmodified, to the build directory.</li>
117 <li>After updating <tt>autoconf/configure.ac</tt>, regenerate the
118 configure script with these commands:
120 <div class="doc_code">
121 <p><tt>% cd autoconf<br>
122 % ./AutoRegen.sh</tt></p>
125 <p>You must be using Autoconf version 2.59 or later and your aclocal version
126 should be 1.9 or later.</p></li>
128 <li>Run <tt>configure</tt> in the directory in which you want to place
129 object code. Use the following options to tell your project where it
133 <dt><tt>--with-llvmsrc=<directory></tt></dt>
134 <dd>Tell your project where the LLVM source tree is located.</dd>
135 <dt><br><tt>--with-llvmobj=<directory></tt></dt>
136 <dd>Tell your project where the LLVM object tree is located.</dd>
137 <dt><br><tt>--prefix=<directory></tt></dt>
138 <dd>Tell your project where it should get installed.</dd>
142 <p>That's it! Now all you have to do is type <tt>gmake</tt> (or <tt>make</tt>
143 if your on a GNU/Linux system) in the root of your object directory, and your
144 project should build.</p>
148 <!-- *********************************************************************** -->
150 <a name="source">Source Tree Layout</a>
152 <!-- *********************************************************************** -->
156 <p>In order to use the LLVM build system, you will want to organize your
157 source code so that it can benefit from the build system's features.
158 Mainly, you want your source tree layout to look similar to the LLVM
159 source tree layout. The best way to do this is to just copy the
160 project tree from <tt>llvm/projects/sample</tt> and modify it to meet
161 your needs, but you can certainly add to it if you want.</p>
163 <p>Underneath your top level directory, you should have the following
169 This subdirectory should contain all of your library source
170 code. For each library that you build, you will have one
171 directory in <b>lib</b> that will contain that library's source
175 Libraries can be object files, archives, or dynamic libraries.
176 The <b>lib</b> directory is just a convenient place for libraries
177 as it places them all in a directory from which they can be linked
182 This subdirectory should contain any header files that are
183 global to your project. By global, we mean that they are used
184 by more than one library or executable of your project.
186 By placing your header files in <b>include</b>, they will be
187 found automatically by the LLVM build system. For example, if
188 you have a file <b>include/jazz/note.h</b>, then your source
189 files can include it simply with <b>#include "jazz/note.h"</b>.
193 This subdirectory should contain all of your source
194 code for executables. For each program that you build, you
195 will have one directory in <b>tools</b> that will contain that
196 program's source code.
201 This subdirectory should contain tests that verify that your code
202 works correctly. Automated tests are especially useful.
204 Currently, the LLVM build system provides basic support for tests.
205 The LLVM system provides the following:
208 LLVM provides a tcl procedure that is used by Dejagnu to run
209 tests. It can be found in <tt>llvm/lib/llvm-dg.exp</tt>. This
210 test procedure uses RUN lines in the actual test case to determine
211 how to run the test. See the <a
212 href="TestingGuide.html">TestingGuide</a> for more details. You
213 can easily write Makefile support similar to the Makefiles in
214 <tt>llvm/test</tt> to use Dejagnu to run your project's tests.<br></li>
216 LLVM contains an optional package called <tt>llvm-test</tt>
217 which provides benchmarks and programs that are known to compile with the
218 LLVM GCC front ends. You can use these
219 programs to test your code, gather statistics information, and
220 compare it to the current LLVM performance statistics.
221 <br>Currently, there is no way to hook your tests directly into the
222 <tt>llvm/test</tt> testing harness. You will simply
223 need to find a way to use the source provided within that directory
228 <p>Typically, you will want to build your <b>lib</b> directory first followed by
229 your <b>tools</b> directory.</p>
233 <!-- *********************************************************************** -->
235 <a name="makefiles">Writing LLVM Style Makefiles</a>
237 <!-- *********************************************************************** -->
241 <p>The LLVM build system provides a convenient way to build libraries and
242 executables. Most of your project Makefiles will only need to define a few
243 variables. Below is a list of the variables one can set and what they can
246 <!-- ======================================================================= -->
248 <a name="reqVars">Required Variables</a>
256 This variable is the relative path from this Makefile to the
257 top directory of your project's source code. For example, if
258 your source code is in <tt>/tmp/src</tt>, then the Makefile in
259 <tt>/tmp/src/jump/high</tt> would set <tt>LEVEL</tt> to <tt>"../.."</tt>.
264 <!-- ======================================================================= -->
266 <a name="varsBuildDir">Variables for Building Subdirectories</a>
274 This is a space separated list of subdirectories that should be
275 built. They will be built, one at a time, in the order
281 This is a list of directories that can be built in parallel.
282 These will be built after the directories in DIRS have been
288 This is a list of directories that can be built if they exist,
289 but will not cause an error if they do not exist. They are
290 built serially in the order in which they are listed.
295 <!-- ======================================================================= -->
297 <a name="varsBuildLib">Variables for Building Libraries</a>
305 This variable contains the base name of the library that will
306 be built. For example, to build a library named
307 <tt>libsample.a</tt>, LIBRARYNAME should be set to
313 By default, a library is a <tt>.o</tt> file that is linked
314 directly into a program. To build an archive (also known as
315 a static library), set the BUILD_ARCHIVE variable.
320 If SHARED_LIBRARY is defined in your Makefile, a shared
321 (or dynamic) library will be built.
326 <!-- ======================================================================= -->
328 <a name="varsBuildProg">Variables for Building Programs</a>
336 This variable contains the name of the program that will
337 be built. For example, to build an executable named
338 <tt>sample</tt>, TOOLNAME should be set to <tt>sample</tt>.
343 This variable holds a space separated list of libraries that should
344 be linked into the program. These libraries must be libraries that
345 come from your <b>lib</b> directory. The libraries must be
346 specified without their "lib" prefix. For example, to link
347 libsample.a, you would set USEDLIBS to
350 Note that this works only for statically linked libraries.
355 This variable holds a space separated list of libraries that should
356 be linked into the program. These libraries must be LLVM libraries.
357 The libraries must be specified without their "lib" prefix. For
358 example, to link with a driver that performs an IR transformation
359 you might set LLVMLIBS to this minimal set of libraries
360 <tt>LLVMSupport.a LLVMCore.a LLVMBitReader.a LLVMAsmParser.a LLVMAnalysis.a LLVMTransformUtils.a LLVMScalarOpts.a LLVMTarget.a</tt>.
362 Note that this works only for statically linked libraries. LLVM is
363 split into a large number of static libraries, and the list of libraries you
364 require may be much longer than the list above. To see a full list
366 <tt>llvm-config --libs all</tt>.
367 Using LINK_COMPONENTS as described below, obviates the need to set LLVMLIBS.
371 <dd>This variable holds a space separated list of components that
372 the LLVM Makefiles pass to the <tt>llvm-config</tt> tool to generate
373 a link line for the program. For example, to link with all LLVM
375 <tt>LINK_COMPONENTS = all</tt>.
380 To link dynamic libraries, add <tt>-l<library base name></tt> to
381 the LIBS variable. The LLVM build system will look in the same places
382 for dynamic libraries as it does for static libraries.
384 For example, to link <tt>libsample.so</tt>, you would have the
385 following line in your <tt>Makefile</tt>:
391 Note that LIBS must occur in the Makefile after the inclusion of Makefile.common.
397 <!-- ======================================================================= -->
399 <a name="miscVars">Miscellaneous Variables</a>
407 This variable contains a space separated list of extra source
408 files that need to be built. It is useful for including the
409 output of Lex and Yacc programs.
415 This variable can be used to add options to the C and C++
416 compiler, respectively. It is typically used to add options
417 that tell the compiler the location of additional directories
418 to search for header files.
420 It is highly suggested that you append to CFLAGS and CPPFLAGS as
421 opposed to overwriting them. The master Makefiles may already
422 have useful options in them that you may not want to overwrite.
430 <!-- *********************************************************************** -->
432 <a name="objcode">Placement of Object Code</a>
434 <!-- *********************************************************************** -->
438 <p>The final location of built libraries and executables will depend upon
439 whether you do a Debug, Release, or Profile build.</p>
444 All libraries (static and dynamic) will be stored in
445 <tt>PROJ_OBJ_ROOT/<type>/lib</tt>, where type is <tt>Debug</tt>,
446 <tt>Release</tt>, or <tt>Profile</tt> for a debug, optimized, or
447 profiled build, respectively.<p>
450 <dd>All executables will be stored in
451 <tt>PROJ_OBJ_ROOT/<type>/bin</tt>, where type is <tt>Debug</tt>,
452 <tt>Release</tt>, or <tt>Profile</tt> for a debug, optimized, or profiled
458 <!-- *********************************************************************** -->
460 <a name="help">Further Help</a>
462 <!-- *********************************************************************** -->
466 <p>If you have any questions or need any help creating an LLVM project,
467 the LLVM team would be more than happy to help. You can always post your
469 href="http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev">LLVM Developers
470 Mailing List</a>.</p>
474 <!-- *********************************************************************** -->
477 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
478 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
479 <a href="http://validator.w3.org/check/referer"><img
480 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
482 <a href="mailto:criswell@uiuc.edu">John Criswell</a><br>
483 <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a>
485 Last modified: $Date$