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 In order to set up a new project that uses the LLVM build system,
16 libraries, and header files, follow these steps:
20 Copy the <tt>llvm/projects/sample</tt> directory to any place
21 of your choosing. You can place it anywhere you like, although
22 someplace underneath your home directory would work best.
26 Edit the <tt>Makefile.config</tt> and <tt>Makefile.common</tt>
27 files so that the LLVM_SRC_ROOT variable equals the absolute
28 pathname of the LLVM source tree and LLVM_OBJ_ROOT equals the
29 pathname of where LLVM was built.
33 For example, if the LLVM source tree is in
34 <tt>/usr/home/joe/src/llvm</tt>, and you configured it with
35 <tt>--with-objroot=/tmp</tt> when his home directory is
36 <tt>/usr/home/joe</tt>, then
37 LLVM_SRC_ROOT=<tt>/usr/home/joe/src/llvm</tt> and
38 LLVM_OBJ_ROOT=<tt>/tmp/src/llvm</tt>.
42 Add your source code to the source tree.
46 Modify the various Makefiles to contain the names of the
47 objects that you want to build.
50 <!--===============================================================-->
51 <h2><a name="Source Tree Layout">Source Tree Layout</a><hr></h2>
52 <!--===============================================================-->
54 In order to use the LLVM build system, you will want to lay out your
55 source code so that it can benefit from the build system's features.
56 Mainly, you want your source tree layout to look similar to the LLVM
57 source tree layout. The best way to do this is to just copy the
58 project tree from <tt>llvm/projects/sample</tt> and modify it to meet
59 your needs, but you can certainly add to it if you want.
61 Underneath your top level directory, you should have the following
67 This subdirectory should contain all of your library source
68 code. For each library that you build, you will have one
69 directory in <b>lib</b> that will contain that library's source
73 Libraries can be object files, archives, or dynamic libraries.
74 The <b>lib</b> directory is just a good place for these as it
75 places them all in a directory from which they can be linked
80 This subdirectory should contain any header files that are
81 global to your project. By global, we mean that they are used
82 by more than one library or executable of your project.
84 By placing your header files in <b>include</b>, they will be
85 found automatically by the LLVM build system. For example, if
86 you have a file <b>include/jazz/note.h</b>, then your source
87 files can include it simply with <b>#include "jazz/note.h"</b>.
91 This subdirectory should contain all of your source
92 code for executables. For each program that you build, you
93 will have one directory in <b>tools</b> that will contain that
94 program's source code.
97 Typically, you will want to build your <b>lib</b> directory first
98 followed by your <b>tools</b> directory.
100 <!--===============================================================-->
101 <h2><a name="Makefile Variables">Makefile Variables</a><hr></h2>
102 <!--===============================================================-->
103 The LLVM build system provides several variables which you may
106 <h3> Required Variables </h3>
110 This variable is the relative path from this Makefile to the
111 top directory of your project's source code. For example, if
112 your source code is in /tmp/src, then the Makefile in
113 /tmp/src/jump/high would set LEVEL to "../..".
116 <h3> Variables for Building Subdirectories</h3>
120 This is a space separated list of subdirectories that should be
121 built. They will be built, one at a time, in the order
127 This is a list of directories that can be built in parallel.
128 These will be built after the directories in DIRS have been
134 This is a list of directories that can be built if they exist,
135 but will not cause an error if they do not exist. They are
136 built serially in the order in which they are listed.
139 <h3> Variables for Building Libraries</h3>
143 This variable contains the base name of the library that will
144 be built. For example, to build a library named
145 <tt>libsample.a</tt>, LIBRARYNAME should be set to
151 By default, a library is a <tt>.o</tt> file that is linked
152 directly into a program. However, if you set the BUILD_ARCHIVE
153 variable, an archive library (sometimes known as a static
154 library) will be built instead.
159 If SHARED_LIBRARY is defined in your Makefile, then the
160 Makefiles will generate a shared (or dynamic) library.
163 <h3> Variables for Building Programs</h3>
167 This variable contains the name of the program that will
168 be built. For example, to build an executable named
169 <tt>sample</tt>, TOOLNAME should be set to <tt>sample</tt>.
174 This variable holds a space separated list of libraries that
175 should be linked into the program. These libraries must either
176 be LLVM libraries or libraries that come from your <b>lib</b>
177 directory. The libraries must be specified by their base name.
178 For example, to link libsample.a, you would set USEDLIBS to
183 <h3> Miscellaneous Variables</h3>
187 This variable contains a space separated list of extra source
188 files that needs to be built. It is useful for including the
189 output of Lex and Yacc programs.
195 This variable can be used to add options to the C and C++
196 compiler, respectively. It is typically used to add options
197 that tell the compiler the location of additional directories
198 to search for header files.
200 It is highly suggested that you append to these variable as
201 opposed to overwriting them. The master Makefiles may already
202 have useful options in them that you may not want to overwrite.
206 <!--===============================================================-->
207 <h2><a name="Caveats">Caveats</a><hr></h2>
208 <!--===============================================================-->
210 Some caveats and known issues:
213 The projects system currently uses the $HOME environment
214 variable in determining where object files should go. If $HOME
215 is not set, then your path relative to the root directory may
216 be used to determine where your object files go. It is
217 therefore advised that your source directory reside underneath