1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <title>Creating an LLVM Project</title>
9 <center><h1>Creating an LLVM Project<br></h1></center>
11 <!--===============================================================-->
12 <h2><a name="a">Overview</a><hr></h2>
13 <!--===============================================================-->
15 The LLVM build system is designed to facilitate the building of third party
16 projects that use LLVM header files, libraries, and tools. In order to use
17 these facilities, a Makefile from a project must do the following things:
20 <li>Set environment variables.
22 There are several environment variables that a Makefile needs to set to
23 use the LLVM build system:
27 The root of the LLVM source tree.
32 The root of the LLVM object tree.
37 The root of the project's source tree.
42 The root of the project's object tree.
47 The directory containing the current source to be compiled.
52 The directory where the current source will place the new object
53 files. This should always be the current directory.
58 The relative path from the current directory to the root of the
63 <li>Include the LLVM Makefile.config from $(LLVM_OBJ_ROOT).
66 <li>Include the LLVM Makefile.rules from $(LLVM_SRC_ROOT).
69 There are two ways that you can set all of these variables:
72 You can write your own Makefiles which hard-code these values.
75 You can use the pre-made LLVM sample project. This sample project
76 includes Makefiles, a configure script that can be used to configure
77 the location of LLVM, and the ability to support multiple object
78 directories from a single source directory.
81 This document assumes that you will base your project off of the LLVM
82 sample project found in <tt>llvm/projects/sample</tt>. If you want to
83 devise your own build system, studying the sample project and LLVM
84 Makefiles will probably provide enough information on how to write your own
88 <!--===============================================================-->
89 <h2><a name="a">Create a Project from the Sample Project</a><hr></h2>
90 <!--===============================================================-->
92 Follow these simple steps to start your project:
96 Copy the <tt>llvm/projects/sample</tt> directory to any place
97 of your choosing. You can place it anywhere you like. Rename the
98 directory to match the name of your project.
102 Add your source code and Makefiles to your source tree.
106 If you want your Makefiles to be configured by the
107 <tt>configure</tt> script, or if you want to support multiple
108 object directories, add your Makefiles to the <tt>configure</tt>
109 script by adding them into the <tt>autoconf/configure.ac</tt> file.
110 The macro <tt>AC_CONFIG_MAKEFILE</tt> will copy a file, unmodified,
111 from the source directory to the object directory.
114 After updating <tt>autoconf/configure.ac</tt>, regenerate the
115 configure script with these commands:
119 autoconf -o ../configure
124 You must be using Autoconf version 2.57 or higher.
128 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>
135 Tell your project where the LLVM source tree is located.
137 <dt><tt>--with-llvmobj=<directory></tt>
139 Tell your project where the LLVM object tree is located.
143 That's it! Now all you have to do is type <tt>gmake</tt> in the root of
144 your object directory, and your project should build.
146 <!--===============================================================-->
147 <h2><a name="Source Tree Layout">Source Tree Layout</a><hr></h2>
148 <!--===============================================================-->
150 In order to use the LLVM build system, you will want to organize your
151 source code so that it can benefit from the build system's features.
152 Mainly, you want your source tree layout to look similar to the LLVM
153 source tree layout. The best way to do this is to just copy the
154 project tree from <tt>llvm/projects/sample</tt> and modify it to meet
155 your needs, but you can certainly add to it if you want.
157 Underneath your top level directory, you should have the following
163 This subdirectory should contain all of your library source
164 code. For each library that you build, you will have one
165 directory in <b>lib</b> that will contain that library's source
169 Libraries can be object files, archives, or dynamic libraries.
170 The <b>lib</b> directory is just a convenient place for libraries
171 as it places them all in a directory from which they can be linked
176 This subdirectory should contain any header files that are
177 global to your project. By global, we mean that they are used
178 by more than one library or executable of your project.
180 By placing your header files in <b>include</b>, they will be
181 found automatically by the LLVM build system. For example, if
182 you have a file <b>include/jazz/note.h</b>, then your source
183 files can include it simply with <b>#include "jazz/note.h"</b>.
187 This subdirectory should contain all of your source
188 code for executables. For each program that you build, you
189 will have one directory in <b>tools</b> that will contain that
190 program's source code.
195 This subdirectory should contain tests that verify that your code
196 works correctly. Automated tests are especially useful.
198 Currently, the LLVM build system provides little support for tests,
199 although some exists. Expanded support for tests will hopefully
200 occur in the future. In the meantime, the LLVM system does provide the
204 LLVM provides several QMTest test classes that can be used to
205 create tests. They can be found in
206 <tt>llvm/test/QMTest/llvm.py</tt>. These test classes perform a
207 variety of functions, including code optimization tests, assembly
208 tests, and code analysis tests. The Makefile in
209 <tt>llvm/test</tt> provides the QMTest context needed by LLVM test
214 The LLVM source tree provides benchmarks and programs which are
215 known to compile with the LLVM GCC front ends. You can use these
216 programs to test your code, gather statistics information, and
217 compare it to the current LLVM performance statistics. These
218 programs are found in the <tt>llvm/test/Programs</tt> directory.
220 Currently, there is no way to hook your tests directly into the
221 <tt>llvm/test/Programs</tt> testing harness. You will simply
222 need to find a way to use the source provided within that directory
227 Typically, you will want to build your <b>lib</b> directory first
228 followed by your <b>tools</b> directory.
230 <!--===============================================================-->
231 <h2><a name="Makefile Variables">Writing LLVM Style Makefiles</a><hr></h2>
232 <!--===============================================================-->
233 The LLVM build system provides a convenient way to build libraries and
234 executables. Most of your project Makefiles will only need to define a few
235 variables. Below is a list of the variables one can set and what they can
238 <h3> Required Variables </h3>
242 This variable is the relative path from this Makefile to the
243 top directory of your project's source code. For example, if
244 your source code is in /tmp/src, then the Makefile in
245 /tmp/src/jump/high would set LEVEL to "../..".
248 <h3> Variables for Building Subdirectories</h3>
252 This is a space separated list of subdirectories that should be
253 built. They will be built, one at a time, in the order
259 This is a list of directories that can be built in parallel.
260 These will be built after the directories in DIRS have been
266 This is a list of directories that can be built if they exist,
267 but will not cause an error if they do not exist. They are
268 built serially in the order in which they are listed.
271 <h3> Variables for Building Libraries</h3>
275 This variable contains the base name of the library that will
276 be built. For example, to build a library named
277 <tt>libsample.a</tt>, LIBRARYNAME should be set to
283 By default, a library is a <tt>.o</tt> file that is linked
284 directly into a program. To build an archive (also known as
285 a static library), set the BUILD_ARCHIVE variable.
290 If SHARED_LIBRARY is defined in your Makefile, a shared
291 (or dynamic) library will be built.
294 <h3> Variables for Building Programs</h3>
298 This variable contains the name of the program that will
299 be built. For example, to build an executable named
300 <tt>sample</tt>, TOOLNAME should be set to <tt>sample</tt>.
305 This variable holds a space separated list of libraries that
306 should be linked into the program. These libraries must either
307 be LLVM libraries or libraries that come from your <b>lib</b>
308 directory. The libraries must be specified by their base name.
309 For example, to link libsample.a, you would set USEDLIBS to
312 Note that this works only for statically linked libraries.
317 To link dynamic libraries, add <tt>-l<library base name></tt> to
318 the LIBS variable. The LLVM build system will look in the same places
319 for dynamic libraries as it does for static libraries.
321 For example, to link <tt>libsample.so</tt>, you would have the
322 following line in your <tt>Makefile</tt>:
329 <h3> Miscellaneous Variables</h3>
333 This variable contains a space separated list of extra source
334 files that need to be built. It is useful for including the
335 output of Lex and Yacc programs.
341 This variable can be used to add options to the C and C++
342 compiler, respectively. It is typically used to add options
343 that tell the compiler the location of additional directories
344 to search for header files.
346 It is highly suggested that you append to CFLAGS and CPPFLAGS as
347 opposed to overwriting them. The master Makefiles may already
348 have useful options in them that you may not want to overwrite.
352 <!--===============================================================-->
353 <h2><a name="objcode">Placement of Object Code</a><hr></h2>
354 <!--===============================================================-->
356 The final location of built libraries and executables will depend upon
357 whether you do a Debug, Release, or Profile build.
362 All libraries (static and dynamic) will be stored in
363 BUILD_OBJ_ROOT/lib/<type>, where type is <tt>Debug</tt>,
364 <tt>Release</tt>, or <tt>Profile</tt> for a debug, optimized, or
365 profiled build, respectively.
370 All executables will be stored in BUILD_OBJ_ROOT/lib/<type>,
371 where type is <tt>Debug</tt>, <tt>Release</tt>, or <tt>Profile</tt> for
372 a debug, optimized, or profiled build, respectively.
375 <!--===============================================================-->
376 <h2><a name="help">Further Help</a><hr></h2>
377 <!--===============================================================-->
379 If you have any questions or need any help creating an LLVM project,
380 the LLVM team would be more than happy to help. You can always post your
382 href="http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev">LLVM Developers
386 <address><a href="mailto:criswell@uiuc.edu">John Criswell</a></address><br>
387 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
388 Last modified: $Date$