blob: f8aaad812e88f0119fd671ff2081e9e9c3d8784b [file] [log] [blame]
John Criswellf2413ae2003-07-03 15:37:52 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3 <head>
4 <title>Creating an LLVM Project</title>
5 </head>
6
7 <body bgcolor=white>
8
9 <center><h1>Creating an LLVM Project<br></h1></center>
10
11 <!--===============================================================-->
12 <h2><a name="a">Overview</a><hr></h2>
13 <!--===============================================================-->
14
John Criswell7a4b96d2003-10-16 19:53:53 +000015 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:
18
19 <ol>
20 <li>Set environment variables.
21 <p>
22 There are several environment variables that a Makefile needs to set to
23 use the LLVM build system:
24 <dl compact>
25 <dt>LLVM_SRC_ROOT
26 <dd>
27 The root of the LLVM source tree.
28 <p>
29
30 <dt>LLVM_OBJ_ROOT
31 <dd>
32 The root of the LLVM object tree.
33 <p>
34
35 <dt>BUILD_SRC_ROOT
36 <dd>
37 The root of the project's source tree.
38 <p>
39
40 <dt>BUILD_OBJ_ROOT
41 <dd>
42 The root of the project's object tree.
43 <p>
44
45 <dt>BUILD_SRC_DIR
46 <dd>
47 The directory containing the current source to be compiled.
48 <p>
49
50 <dt>BUILD_OBJ_DIR
51 <dd>
52 The directory where the current source will place the new object
53 files. This should always be the current directory.
54 <p>
55
56 <dt>LEVEL
57 <dd>
58 The relative path from the current directory to the root of the
59 object tree.
60 <p>
61 </dl>
62
63 <li>Include the LLVM Makefile.config from $(LLVM_OBJ_ROOT).
64 <p>
65
66 <li>Include the LLVM Makefile.rules from $(LLVM_SRC_ROOT).
67 </ol>
68
69 There are two ways that you can set all of these variables:
70 <ol>
71 <li>
72 You can write your own Makefiles which hard-code these values.
73
74 <li>
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.
79 </ol>
80
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
85 Makefiles.
86 <p>
87
88 <!--===============================================================-->
89 <h2><a name="a">Create a Project from the Sample Project</a><hr></h2>
90 <!--===============================================================-->
91
92 Follow these simple steps to start your project:
John Criswellf2413ae2003-07-03 15:37:52 +000093
94 <ol>
95 <li>
96 Copy the <tt>llvm/projects/sample</tt> directory to any place
John Criswell7a4b96d2003-10-16 19:53:53 +000097 of your choosing. You can place it anywhere you like. Rename the
98 directory to match the name of your project.
John Criswellf2413ae2003-07-03 15:37:52 +000099 <p>
100
101 <li>
John Criswell7a4b96d2003-10-16 19:53:53 +0000102 Add your source code and Makefiles to your source tree.
John Criswellf2413ae2003-07-03 15:37:52 +0000103 <p>
104
105 <li>
John Criswell7a4b96d2003-10-16 19:53:53 +0000106 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.
112
113 <p>
114 After updating <tt>autoconf/configure.ac</tt>, regenerate the
115 configure script with these commands:
116 <p>
117 <tt>
118 cd autoconf<br>
119 autoconf -o ../configure
120 </tt>
121
122 <p>
123
124 You must be using Autoconf version 2.57 or higher.
John Criswellf2413ae2003-07-03 15:37:52 +0000125 <p>
126
127 <li>
John Criswell7a4b96d2003-10-16 19:53:53 +0000128 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
130 can find LLVM:
131
132 <dl compact>
133 <dt><tt>--with-llvmsrc=&lt;directory&gt;</tt>
134 <dd>
135 Tell your project where the LLVM source tree is located.
136 <p>
137 <dt><tt>--with-llvmobj=&lt;directory&gt;</tt>
138 <dd>
139 Tell your project where the LLVM object tree is located.
140 </dl>
John Criswellf2413ae2003-07-03 15:37:52 +0000141 </ol>
142
John Criswell7a4b96d2003-10-16 19:53:53 +0000143 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.
145
John Criswellf2413ae2003-07-03 15:37:52 +0000146 <!--===============================================================-->
147 <h2><a name="Source Tree Layout">Source Tree Layout</a><hr></h2>
148 <!--===============================================================-->
149
John Criswell7a4b96d2003-10-16 19:53:53 +0000150 In order to use the LLVM build system, you will want to organize your
John Criswellf2413ae2003-07-03 15:37:52 +0000151 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.
156
157 Underneath your top level directory, you should have the following
158 directories:
159
160 <dl compact>
161 <dt><b>lib</b>
162 <dd>
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
166 code.
167
168 <p>
169 Libraries can be object files, archives, or dynamic libraries.
John Criswell7a4b96d2003-10-16 19:53:53 +0000170 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
John Criswellc7b6ce42003-10-15 16:52:57 +0000172 later.
John Criswellf2413ae2003-07-03 15:37:52 +0000173
174 <dt><b>include</b>
175 <dd>
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.
179 <p>
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>.
184
185 <dt><b>tools</b>
186 <dd>
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.
191 </dl>
192
193 Typically, you will want to build your <b>lib</b> directory first
194 followed by your <b>tools</b> directory.
195
196 <!--===============================================================-->
John Criswell7a4b96d2003-10-16 19:53:53 +0000197 <h2><a name="Makefile Variables">Writing LLVM Style Makefiles</a><hr></h2>
John Criswellf2413ae2003-07-03 15:37:52 +0000198 <!--===============================================================-->
John Criswell7a4b96d2003-10-16 19:53:53 +0000199 The LLVM build system provides a convenient way to build libraries and
200 executables. Most of your project Makefiles will only need to define a few
201 variables. Below is a list of the variables one can set and what they can
202 do:
John Criswellf2413ae2003-07-03 15:37:52 +0000203
204 <h3> Required Variables </h3>
205 <dl compact>
206 <dt>LEVEL
207 <dd>
208 This variable is the relative path from this Makefile to the
209 top directory of your project's source code. For example, if
210 your source code is in /tmp/src, then the Makefile in
211 /tmp/src/jump/high would set LEVEL to "../..".
212 </dl>
213
214 <h3> Variables for Building Subdirectories</h3>
215 <dl compact>
216 <dt>DIRS
217 <dd>
218 This is a space separated list of subdirectories that should be
219 built. They will be built, one at a time, in the order
220 specified.
221 <p>
222
223 <dt>PARALLEL_DIRS
224 <dd>
225 This is a list of directories that can be built in parallel.
226 These will be built after the directories in DIRS have been
227 built.
228 <p>
229
230 <dt>OPTIONAL_DIRS
231 <dd>
232 This is a list of directories that can be built if they exist,
233 but will not cause an error if they do not exist. They are
234 built serially in the order in which they are listed.
235 </dl>
236
237 <h3> Variables for Building Libraries</h3>
238 <dl compact>
239 <dt>LIBRARYNAME
240 <dd>
241 This variable contains the base name of the library that will
242 be built. For example, to build a library named
243 <tt>libsample.a</tt>, LIBRARYNAME should be set to
244 <tt>sample</tt>.
245 <p>
246
247 <dt>BUILD_ARCHIVE
248 <dd>
249 By default, a library is a <tt>.o</tt> file that is linked
John Criswell7a4b96d2003-10-16 19:53:53 +0000250 directly into a program. To build an archive (also known as
251 a static library), set the BUILD_ARCHIVE variable.
John Criswellf2413ae2003-07-03 15:37:52 +0000252 <p>
253
254 <dt>SHARED_LIBRARY
255 <dd>
John Criswell7a4b96d2003-10-16 19:53:53 +0000256 If SHARED_LIBRARY is defined in your Makefile, a shared
257 (or dynamic) library will be built.
John Criswellf2413ae2003-07-03 15:37:52 +0000258 </dl>
259
260 <h3> Variables for Building Programs</h3>
261 <dl compact>
262 <dt>TOOLNAME
263 <dd>
264 This variable contains the name of the program that will
265 be built. For example, to build an executable named
266 <tt>sample</tt>, TOOLNAME should be set to <tt>sample</tt>.
267 <p>
268
269 <dt>USEDLIBS
270 <dd>
271 This variable holds a space separated list of libraries that
272 should be linked into the program. These libraries must either
273 be LLVM libraries or libraries that come from your <b>lib</b>
274 directory. The libraries must be specified by their base name.
275 For example, to link libsample.a, you would set USEDLIBS to
276 <tt>sample</tt>.
277 <p>
278 </dl>
279
280 <h3> Miscellaneous Variables</h3>
281 <dl compact>
282 <dt>ExtraSource
283 <dd>
284 This variable contains a space separated list of extra source
John Criswell7a4b96d2003-10-16 19:53:53 +0000285 files that need to be built. It is useful for including the
John Criswellf2413ae2003-07-03 15:37:52 +0000286 output of Lex and Yacc programs.
287 <p>
288
289 <dt>CFLAGS
290 <dt>CPPFLAGS
291 <dd>
292 This variable can be used to add options to the C and C++
293 compiler, respectively. It is typically used to add options
294 that tell the compiler the location of additional directories
295 to search for header files.
296 <p>
John Criswell7a4b96d2003-10-16 19:53:53 +0000297 It is highly suggested that you append to CFLAGS and CPPFLAGS as
John Criswellf2413ae2003-07-03 15:37:52 +0000298 opposed to overwriting them. The master Makefiles may already
299 have useful options in them that you may not want to overwrite.
300 <p>
301 </dl>
302
John Criswell7a4b96d2003-10-16 19:53:53 +0000303 <!--===============================================================-->
304 <h2><a name="objcode">Placement of Object Code</a><hr></h2>
305 <!--===============================================================-->
306
307 The final location of built libraries and executables will depend upon
308 whether you do a Debug, Release, or Profile build.
309
310 <dl compact>
311 <dt>Libraries
312 <dd>
313 All libraries (static and dynamic) will be stored in
314 BUILD_OBJ_ROOT/lib/&lt;type&gt;, where type is <tt>Debug</tt>,
315 <tt>Release</tt>, or <tt>Profile</tt> for a debug, optimized, or
316 profiled build, respectively.
317 <p>
318
319 <dt>Executables
320 <dd>
321 All executables will be stored in BUILD_OBJ_ROOT/lib/&lt;type&gt;,
322 where type is <tt>Debug</tt>, <tt>Release</tt>, or <tt>Profile</tt> for
323 a debug, optimized, or profiled build, respectively.
324 </dl>
325
326 <!--===============================================================-->
327 <h2><a name="help">Further Help</a><hr></h2>
328 <!--===============================================================-->
329
330 If you have any questions or need any help creating an LLVM project,
331 the LLVM team would be more than happy to help. You can always post your
332 questions to the LLVM Developers Mailing List (<a
333 href="mailto:llvmdev.cs.uiuc.edu">llvmdev@cs.uiuc.edu</a>).
334
335<hr>
John Criswell610373f2003-10-16 20:01:04 +0000336Written by <a href="mailto:criswell@uiuc.edu">John Criswell</a>.
John Criswellf2413ae2003-07-03 15:37:52 +0000337</body>
338</html>