PageRenderTime 34ms CodeModel.GetById 23ms app.highlight 7ms RepoModel.GetById 0ms app.codeStats 0ms

/3rd_party/llvm/docs/Projects.html

https://code.google.com/p/softart/
HTML | 489 lines | 390 code | 81 blank | 18 comment | 0 complexity | a64f09b7756116ddf30a9b7ad94e758e MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, JSON, MPL-2.0-no-copyleft-exception, GPL-2.0, GPL-3.0, LGPL-3.0, BSD-2-Clause
  1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2                      "http://www.w3.org/TR/html4/strict.dtd">
  3<html>
  4<head>
  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">
  8</head>
  9<body>
 10
 11<h1>Creating an LLVM Project</h1>
 12
 13<ol>
 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>
 18  <ol>
 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>
 24  </ol></li>
 25<li><a href="#objcode">Placement of object code</a></li>
 26<li><a href="#help">Further help</a></li>
 27</ol>
 28
 29<div class="doc_author">
 30  <p>Written by John Criswell</p>
 31</div>
 32
 33<!-- *********************************************************************** -->
 34<h2><a name="overview">Overview</a></h2>
 35<!-- *********************************************************************** -->
 36
 37<div>
 38
 39<p>The LLVM build system is designed to facilitate the building of third party
 40projects that use LLVM header files, libraries, and tools.  In order to use
 41these facilities, a Makefile from a project must do the following things:</p>
 42
 43<ol>
 44  <li>Set <tt>make</tt> variables. There are several variables that a Makefile
 45  needs to set to use the LLVM build system:
 46  <ul>
 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>
 55  </ul></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>
 58</ol>
 59
 60<p>There are two ways that you can set all of these variables:</p>
 61<ol>
 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>
 67</ol>
 68
 69<p>This document assumes that you will base your project on the LLVM sample
 70project found in <tt>llvm/projects/sample</tt>.  If you want to devise your own
 71build system, studying the sample project and LLVM Makefiles will probably
 72provide enough information on how to write your own Makefiles.</p>
 73
 74</div>
 75
 76<!-- *********************************************************************** -->
 77<h2>
 78  <a name="create">Create a Project from the Sample Project</a>
 79</h2>
 80<!-- *********************************************************************** -->
 81
 82<div>
 83
 84<p>Follow these simple steps to start your project:</p>
 85
 86<ol>
 87<li>Copy the <tt>llvm/projects/sample</tt> directory to any place of your
 88choosing.  You can place it anywhere you like.  Rename the directory to match
 89the name of your project.</li>
 90
 91<li>
 92If 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
 94keep Subversion from thinking that your project is inside
 95<tt>llvm/trunk/projects/sample</tt>.</li>
 96
 97<li>Add your source code and Makefiles to your source tree.</li>
 98
 99<li>If you want your project to be configured with the <tt>configure</tt> script
100then you need to edit <tt>autoconf/configure.ac</tt> as follows:
101  <ul>
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>
114  </ul>
115</li>
116
117<li>After updating <tt>autoconf/configure.ac</tt>, regenerate the
118configure script with these commands:
119
120<div class="doc_code">
121<p><tt>% cd autoconf<br>
122       % ./AutoRegen.sh</tt></p>
123</div>
124
125<p>You must be using Autoconf version 2.59 or later and your aclocal version
126should be 1.9 or later.</p></li>
127
128<li>Run <tt>configure</tt> in the directory in which you want to place
129object code.  Use the following options to tell your project where it
130can find LLVM:
131
132  <dl>
133    <dt><tt>--with-llvmsrc=&lt;directory&gt;</tt></dt>
134    <dd>Tell your project where the LLVM source tree is located.</dd>
135    <dt><br><tt>--with-llvmobj=&lt;directory&gt;</tt></dt>
136    <dd>Tell your project where the LLVM object tree is located.</dd>
137    <dt><br><tt>--prefix=&lt;directory&gt;</tt></dt>
138    <dd>Tell your project where it should get installed.</dd>
139  </dl>
140</ol>
141
142<p>That's it!  Now all you have to do is type <tt>gmake</tt> (or <tt>make</tt>
143if your on a GNU/Linux system) in the root of your object directory, and your
144project should build.</p>
145
146</div>
147
148<!-- *********************************************************************** -->
149<h2>
150  <a name="source">Source Tree Layout</a>
151</h2>
152<!-- *********************************************************************** -->
153
154<div>
155
156<p>In order to use the LLVM build system, you will want to organize your
157source code so that it can benefit from the build system's features.
158Mainly, you want your source tree layout to look similar to the LLVM
159source tree layout.  The best way to do this is to just copy the
160project tree from <tt>llvm/projects/sample</tt> and modify it to meet
161your needs, but you can certainly add to it if you want.</p>
162
163<p>Underneath your top level directory, you should have the following
164directories:</p>
165
166<dl>
167  <dt><b>lib</b>
168  <dd>
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
172  code.
173
174  <p>
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
178  later.
179
180  <dt><b>include</b>
181  <dd>
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.
185  <p>
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>.
190
191  <dt><b>tools</b>
192  <dd>
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.
197  <p>
198
199  <dt><b>test</b>
200  <dd>
201  This subdirectory should contain tests that verify that your code
202  works correctly.  Automated tests are especially useful.
203  <p>
204  Currently, the LLVM build system provides basic support for tests.
205  The LLVM system provides the following:
206  <ul>
207    <li>
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>
215    <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
224    on your own.
225  </ul>
226</dl>
227
228<p>Typically, you will want to build your <b>lib</b> directory first followed by
229your <b>tools</b> directory.</p>
230
231</div>
232
233<!-- *********************************************************************** -->
234<h2>
235  <a name="makefiles">Writing LLVM Style Makefiles</a>
236</h2>
237<!-- *********************************************************************** -->
238
239<div>
240
241<p>The LLVM build system provides a convenient way to build libraries and
242executables.  Most of your project Makefiles will only need to define a few
243variables.  Below is a list of the variables one can set and what they can
244do:</p>
245
246<!-- ======================================================================= -->
247<h3>
248  <a name="reqVars">Required Variables</a>
249</h3>
250
251<div>
252
253<dl>
254  <dt>LEVEL
255  <dd>
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>.
260</dl>
261
262</div>
263
264<!-- ======================================================================= -->
265<h3>
266  <a name="varsBuildDir">Variables for Building Subdirectories</a>
267</h3>
268
269<div>
270
271<dl>
272  <dt>DIRS
273  <dd>
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
276  specified.
277  <p>
278
279  <dt>PARALLEL_DIRS
280  <dd>
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
283  built.
284  <p>
285
286  <dt>OPTIONAL_DIRS
287  <dd>
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.
291</dl>
292
293</div>
294
295<!-- ======================================================================= -->
296<h3>
297  <a name="varsBuildLib">Variables for Building Libraries</a>
298</h3>
299
300<div>
301
302<dl>
303  <dt>LIBRARYNAME
304  <dd>
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
308  <tt>sample</tt>.
309  <p>
310
311  <dt>BUILD_ARCHIVE
312  <dd>
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.
316  <p>
317
318  <dt>SHARED_LIBRARY
319  <dd>
320  If SHARED_LIBRARY is defined in your Makefile, a shared
321  (or dynamic) library will be built.
322</dl>
323
324</div>
325
326<!-- ======================================================================= -->
327<h3>
328  <a name="varsBuildProg">Variables for Building Programs</a>
329</h3>
330
331<div>
332
333<dl>
334  <dt>TOOLNAME
335  <dd>
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>.
339  <p>
340
341  <dt>USEDLIBS
342  <dd>
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
348  <tt>sample.a</tt>.
349  <p>
350  Note that this works only for statically linked libraries.
351  <p>
352
353  <dt>LLVMLIBS
354  <dd>
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>.
361  <p>
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
365  of libraries use:
366  <tt>llvm-config --libs all</tt>.
367  Using LINK_COMPONENTS as described below, obviates the need to set LLVMLIBS.
368  <p>
369
370  <dt>LINK_COMPONENTS
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
374  libraries use
375  <tt>LINK_COMPONENTS = all</tt>.
376  <p>
377
378  <dt>LIBS
379  <dd>
380  To link dynamic libraries, add <tt>-l&lt;library base name&gt;</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.
383  <p>
384  For example, to link <tt>libsample.so</tt>, you would have the
385  following line in your <tt>Makefile</tt>:
386  <p>
387  <tt>
388  LIBS += -lsample
389  </tt>
390  <p>
391  Note that LIBS must occur in the Makefile after the inclusion of Makefile.common.
392  <p>
393</dl>
394
395</div>
396
397<!-- ======================================================================= -->
398<h3>
399  <a name="miscVars">Miscellaneous Variables</a>
400</h3>
401
402<div>
403
404<dl>
405  <dt>ExtraSource
406  <dd>
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.
410  <p>
411
412  <dt>CFLAGS
413  <dt>CPPFLAGS
414  <dd>
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.
419  <p>
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.
423  <p>
424</dl>
425
426</div>
427
428</div>
429
430<!-- *********************************************************************** -->
431<h2>
432  <a name="objcode">Placement of Object Code</a>
433</h2>
434<!-- *********************************************************************** -->
435
436<div>
437
438<p>The final location of built libraries and executables will depend upon
439whether you do a Debug, Release, or Profile build.</p>
440
441<dl>
442  <dt>Libraries
443  <dd>
444  All libraries (static and dynamic) will be stored in
445  <tt>PROJ_OBJ_ROOT/&lt;type&gt;/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>
448
449  <dt>Executables
450  <dd>All executables will be stored in
451  <tt>PROJ_OBJ_ROOT/&lt;type&gt;/bin</tt>, where type is <tt>Debug</tt>,
452  <tt>Release</tt>, or <tt>Profile</tt> for a debug, optimized, or profiled
453  build, respectively.
454</dl>
455
456</div>
457
458<!-- *********************************************************************** -->
459<h2>
460  <a name="help">Further Help</a>
461</h2>
462<!-- *********************************************************************** -->
463
464<div>
465
466<p>If you have any questions or need any help creating an LLVM project,
467the LLVM team would be more than happy to help.  You can always post your
468questions to the <a
469href="http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev">LLVM Developers
470Mailing List</a>.</p>
471
472</div>
473
474<!-- *********************************************************************** -->
475<hr>
476<address>
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>
481
482  <a href="mailto:criswell@uiuc.edu">John Criswell</a><br>
483  <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a>
484  <br>
485  Last modified: $Date: 2011-11-03 14:43:23 +0800 (Thu, 03 Nov 2011) $
486</address>
487
488</body>
489</html>