docs: Add initial docs on LLVMBuild organization.
[oota-llvm.git] / docs / LLVMBuild.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5   <title>LLVMBuild Documentation</title>
6   <link rel="stylesheet" href="llvm.css" type="text/css">
7 </head>
8 <body>
9
10 <h1>LLVMBuild Guide</h1>
11
12 <ol>
13   <li><a href="#introduction">Introduction</a></li>
14   <li><a href="#projectorg">Project Organization</a></li>
15   <li><a href="#buildintegration">Build Integration</a></li>
16   <li><a href="#componentoverview">Component Overview</a></li>
17   <li><a href="#formatreference">Format Reference</a></li>
18 </ol>
19
20 <!-- *********************************************************************** -->
21 <h2><a name="introduction">Introduction</a></h2>
22 <!-- *********************************************************************** -->
23
24 <div>
25   <p>This document describes the <tt>LLVMBuild</tt> organization and files which
26   we use to describe parts of the LLVM ecosystem. For description of specific
27   LLVMBuild related tools, please see the command guide.</p>
28
29   <p>LLVM is designed to be a modular set of libraries which can be flexibly
30   mixed together in order to build a variety of tools, like compilers, JITs,
31   custom code generators, optimization passes, interpreters, and so on. Related
32   projects in the LLVM system like Clang and LLDB also tend to follow this
33   philosophy.</p>
34
35   <p>In order to support this usage style, LLVM has a fairly strict structure as
36   to how the source code and various components are organized. The
37   <tt>LLVMBuild.txt</tt> files are the explicit specification of that structure,
38   and are used by the build systems and other tools in order to develop the LLVM
39   project.</p>
40 </div>
41
42 <!-- *********************************************************************** -->
43 <h2><a name="projectorg">Project Organization</a></h2>
44 <!-- *********************************************************************** -->
45
46 <!-- FIXME: We should probably have an explicit top level project object. Good
47 place to hang project level data, name, etc. Also useful for serving as the
48 $ROOT of project trees for things which can be checked out separately. -->
49
50 <div>
51   <p>The source code for LLVM projects using the LLVMBuild system (LLVM, Clang,
52   and LLDB) is organized into <em>components</em>, which define the separate
53   pieces of functionality that make up the project. These projects may consist
54   of many libraries, associated tools, build tools, or other utility tools (for
55   example, testing tools).</p>
56
57   <p>For the most part, the project contents are organized around defining one
58   main component per each subdirectory. Each such directory contains
59   an <tt>LLVMBuild.txt</tt> which contains the component definitions.</p>
60
61   <p>The component descriptions for the project as a whole are automatically
62   gathered by the LLVMBuild tools. The tools automatically traverse the source
63   directory structure to find all of the component description files. NOTE: For
64   performance/sanity reasons, we only traverse into subdirectories when the
65   parent itself contains an <tt>LLVMBuild.txt</tt> description file.</p>
66 </div>
67
68 <!-- *********************************************************************** -->
69 <h2><a name="buildintegration">Build Integration</a></h2>
70 <!-- *********************************************************************** -->
71
72 <div>
73   <p>The LLVMBuild files themselves are just a declarative way to describe the
74   project structure. The actual building of the LLVM project is handled by
75   another build system (currently we support
76   both <a href="MakefileGuide.html">Makefiles</a>
77   and <a href="CMake.html">CMake</a>.</p>
78
79   <p>The build system implementation will load the relevant contents of the
80   LLVMBuild files and use that to drive the actual project build. Typically, the
81   build system will only need to load this information at "configure" time, and
82   use it to generative native information. Build systems will also handle
83   automatically reconfiguring their information when the contents of
84   the <i>LLVMBuild.txt</i> files change.</p>
85
86   <p>Developers generally are not expected to need to be aware of the details of
87   how the LLVMBuild system is integrated into their build. Ideally, LLVM
88   developers who are not working on the build system would only ever need to
89   modify the contents of the <i>LLVMBuild.txt</i> description files (although we
90   have not reached this goal yet).</p>
91 </div>
92
93 <!-- *********************************************************************** -->
94 <h2><a name="componentoverview">Component Overview</a></h2>
95 <!-- *********************************************************************** -->
96
97 <div>
98   <p>As mentioned earlier, LLVM projects are organized into
99   logical <em>components</em>. Every component is typically grouped into it's
100   own subdirectory. Generally, a component is organized around a coherent group
101   of sources which have some kind of clear API separation from other parts of
102   the code.</p>
103
104   <p>LLVM primarily uses the following types of components:</p>
105   <ul>
106     <li><em>Libraries</em> - Library components define a distinct API which can
107     be independently linked into LLVM client applications. Libraries typically
108     have private and public header files, and may specify a link of required
109     libraries that they build on top of.</li>
110
111     <li><em>Build Tools</em> - Build tools are applications which are designed
112     to be run as part of the build process (typically to generate other source
113     files). Currently, LLVM uses one main build tool
114     called <a href="TableGenFundamentals.html">TableGen</a> to generate a
115     variety of source files.</li>
116
117     <li><em>Tools</em> - Command line applications which are built using the
118     LLVM component libraries. Most LLVM tools are small and are primarily
119     frontends to the library interfaces.</li>
120
121 <!-- FIXME: We also need shared libraries as a first class component, but this
122      is not yet implemented. -->
123   </ul>
124
125   <p>Components are described using <em>LLVMBuild.txt</em> files in the
126   directories that define the component. See
127   the <a href="#formatreference">Format Reference</a> section for information on
128   the exact format of these files.</p>
129 </div>
130
131 <!-- *********************************************************************** -->
132 <h2><a name="formatref">LLVMBuild Format Reference</a></h2>
133 <!-- *********************************************************************** -->
134
135 <div>
136   <p>LLVMBuild files are written in a simple variant of the INI or configuration
137   file format (<a href="http://en.wikipedia.org/wiki/INI_file">Wikipedia
138   entry</a>). The format defines a list of sections each of which may contain
139   some number of properties. A simple example of the file format is below:</p>
140   <div class="doc_code">
141   <pre>
142 <i>; Comments start with a semi-colon.</i>
143
144 <i>; Sections are declared using square brackets.</i>
145 [component 0]
146
147 <i>; Properties are declared using '=' and are contained in the previous section.
148 ;
149 ; We support simple scalar values and list values, where items are separated by
150 ; spaces. There is no support for quoting, and so property values may not contain
151 ; spaces.</i>
152 property_name = property_value
153 list_property_name = value_1 value_2 <em>...</em> value_n
154 </pre>
155   </div>
156
157   <p>LLVMBuild files are expected to define a strict set of section and
158   properties. An typical component description file for a library
159   component would look typically look like the following example:</p>
160   <div class="doc_code">
161   <pre>
162 [component_0]
163 type = Library
164 name = Linker
165 parent = Libraries
166 required_libraries = Archive BitReader Core Support TransformUtils
167 </pre>
168   </div class="doc_code">
169
170   <p>A full description of the exact sections and properties which are allowed
171  follows.</p>
172
173   <p>Each file may define multiple components. Each component is described by a
174   section who name starts with "component". The remainder of the section name is
175   ignored, but each section name must be unique. Typically components are just
176   number in order for files with multiple components ("component_0",
177   "component_1", and so on).<p>
178
179   <p><b>Section names not matches this format are currently
180   unused and are disallowed.</b></p>
181
182   <p>Every component is defined by the properties in the section. The exact list
183   of properties that are allowed depends on the component
184   type. Components <b>may not</b> define any properties other than those
185   expected by the component type.</p>
186
187   <p>Every component must define the following properties:</p>
188   <ul>
189     <li><i>type</i> <b>[required]</b>
190       <p>The type of the component. Supported component types are
191       detailed below. Most components will define additional properties which
192       may be required or optional.</p></li>
193
194     <li><i>name</i> <b>[required]</b>
195       <p>The name of the component. Names are required to be unique
196       across the entire project.</p></li>
197
198     <li><i>parent</i> <b>[required]</b>
199       <p>The name of the logical parent of the component. Components are
200       organized into a logical tree to make it easier to navigate and organize
201       groups of components. The parent's have no semantics as far as the project
202       build is concerned, however. Typically, the parent will be the main
203       component of the parent directory.</p>
204
205       <!-- FIXME: Should we make the parent optional, and default to parent
206       directories component? -->
207
208       <p>Components may reference the root pseudo component using '$ROOT' to
209       indicate they should logically be grouped at the top-level.</p>
210     </li>
211   </ul>
212
213   <p>Components may define the following properties:</p>
214   <ul>
215     <li><i>dependencies</i> <b>[optional]</b>
216       <p>If specified, a list of names of components which <i>must</i> be built
217       prior to this one. This should only be exactly those components which
218       produce some tool or source code required for building the
219       component.</p>
220
221       <p><em>NOTE:</em> Group and LibraryGroup components have no semantics for
222       the actual build, and are not allowed to specify dependencies.</p></li>
223   </ul>
224
225   <p>The following section lists the available component types, as well as the
226   properties which are associated with that component.</p>
227
228   <ul>
229     <li><i>type = Group</i>
230       <p>Group components exist purely to allow additional arbitrary structuring
231       of the logical components tree. For example, one might define a
232       "Libraries" group to hold all of the root library components.</p>
233
234       <p>Group components have no additionally properties.</p>
235     </li>
236
237     <li><i>type = Library</i>
238       <p>Library components define an individual library which should be built
239       from the source code in the component directory.</p>
240
241       <p>Components with this type use the following properties:</p>
242       <ul>
243         <li><i>library_name</i> <b>[optional]</b>
244           <p>If given, the name to use for the actual library file on disk. If
245           not given, the name is derived from the component name
246           itself.</p></li>
247
248         <li><i>required_libraries</i> <b>[optional]</b>
249           <p>If given, a list of the names of Library or LibraryGroup components
250           which must also be linked in whenever this library is used. That is,
251           the link time dependencies for this component. When tools are built,
252           the build system will include the transitive closer of
253           all <i>required_libraries</i> for the components the tool needs.</p></li>
254
255         <li><i>add_to_library_groups</i> <b>[optional]</b>
256           <p>If given, a list of the names of LibraryGroup components which this
257           component is also part of. This allows nesting groups of
258           components. For example, the <i>X86</i> target might define a library
259           group for all of the <i>X86</i> components. That library group might
260           then be included in the <i>all-targets</i> library group.</p></li>
261       </ul>
262     </li>
263
264     <li><i>type = LibraryGroup</i>
265       <p>LibraryGroup components are a mechanism to allow easy definition of
266       useful sets of related components. In particular, we use them to easily
267       specify things like "all targets", or "all assembly printers".</p>
268
269       <p>Components with this type use the following properties:</p>
270       <ul>
271         <li><i>required_libraries</i> <b>[optional]</b>
272           <p>See the Library type for a description of this property.</p></li>
273
274         <li><i>add_to_library_groups</i> <b>[optional]</b>
275           <p>See the Library type for a description of this property.</p></li>
276       </ul>
277     </li>
278
279     <li><i>type = Tool</i>
280       <p>Tool components define standalone command line tools which should be
281       built from the source code in the component directory and linked.</p>
282
283       <p>Components with this type use the following properties:</p>
284       <ul>
285         <li><i>required_libraries</i> <b>[optional]</b>
286
287           <p>If given, a list of the names of Library or LibraryGroup components
288           which this tool is required to be linked with. <b>NOTE:</b> The values
289           should be the component names, which may not always match up with the
290           actual library names on disk.</p>
291
292           <p>Build systems are expected to properly include all of the libraries
293           required by the linked components (i.e., the transitive closer
294           of <em>required_libraries</em>).</p>
295
296           <p>Build systems are also expected to understand that those library
297           components must be built prior to linking -- they do not also need to
298           be listed under <i>dependencies</i>.</p></li>
299       </ul>
300     </li>
301
302     <li><i>type = BuildTool</i>
303       <p>BuildTool components are like Tool components, except that the tool is
304       supposed to be built for the platform where the build is running (instead
305       of that platform being targetted). Build systems are expected to handle
306       the fact that required libraries may need to be built for multiple
307       platforms in order to be able to link this tool.</p>
308
309       <p>BuildTool components currently use the exact same properties as Tool
310       components, the type distinction is only used to differentiate what the
311       tool is built for.</p>
312     </li>
313   </ul>
314 </div>
315
316 <!-- *********************************************************************** -->
317 <hr>
318 <address>
319   <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
320   src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
321   <a href="http://validator.w3.org/check/referer"><img
322   src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
323
324   <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br>
325   Last modified: $Date$
326 </address>
327 </body>
328 </html>