1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5 <title>LLVM Makefile Guide</title>
6 <link rel="stylesheet" href="llvm.css" type="text/css">
10 <div class="doc_title">LLVM Makefile Guide</div>
13 <li><a href="#introduction">Introduction</a></li>
14 <li><a href="#general">General Concepts</a>
16 <li><a href="#projects">Projects</a></li>
17 <li><a href="#Makefile">Makefile</a></li>
18 <li><a href="#Makefile.common">Makefile.common</a></li>
19 <li><a href="#Makefile.config">Makefile.config</a></li>
20 <li><a href="#Makefile.rules">Makefile.rules</a></li>
21 <li><a href="#Comments">Comments</a></li>
24 <li><a href="#targets">Targets Supported</a>
26 <li><a href="#all">all</a></li>
27 <li><a href="#all-local">all-local</a></li>
28 <li><a href="#check">check</a></li>
29 <li><a href="#check-local">check-local</a></li>
30 <li><a href="#clean">clean</a></li>
31 <li><a href="#clean-local">clean-local</a></li>
32 <li><a href="#dist">dist</a></li>
33 <li><a href="#dist-check">dist-check</a></li>
34 <li><a href="#dist-clean">dist-clean</a></li>
35 <li><a href="#install">install</a></li>
36 <li><a href="#printvars">printvars</a></li>
37 <li><a href="#tags">tags</a></li>
38 <li><a href="#uninstall">uninstall</a></li>
41 <li><a href="#variables">Using Variables</a>
43 <li><a href="#setvars">Control Variables</a></li>
44 <li><a href="#overvars">Override Variables</a></li>
45 <li><a href="#getvars">Readable Variables</a></li>
50 <div class="doc_author">
51 <p>Written by <a href="mailto:reid@x10sys.com">Reid Spencer</a></p>
54 <div class="doc_warning"><p>WARNING: This document is a work in progress!</p></div>
56 <!-- *********************************************************************** -->
57 <div class="doc_section"><a name="introduction">Introduction </a></div>
58 <!-- *********************************************************************** -->
60 <div class="doc_text">
61 <p>This document provides <em>usage</em> information about the LLVM makefile
62 system. While loosely patterned after the BSD makefile system, LLVM has taken
63 a departure from BSD in order to implement additional features needed by LLVM.
65 <p>Although makefile systems such as automake were attempted at one point, it
66 has become clear that the variations required by LLVM from any Makefile norm
67 are too many to strictly use a more limited tool. Consequently, LLVM requires
68 simply GNU Make 3.79, a widely portably makefile processor. LLVM unabashedly
69 makes heavy use of the features of GNU Make so the dependency on GNU Make is
70 firm. If you're not familiar with <tt>make</tt>, it is recommended that you
71 read the <a href="http://www.gnu.org/software/make/manual/make.html">
72 GNU Makefile Manual</a>.</p>
73 <p>While this document is rightly part of the
74 <a href="ProgrammersManual.html">LLVM Programmer's Manual</a>, it is treated
75 separately here because of the volume of content and because it is often an
76 early source of bewilderment for new developers.</p>
79 <!-- *********************************************************************** -->
80 <div class="doc_section"><a name="general">General Concepts</a></div>
81 <!-- *********************************************************************** -->
83 <div class="doc_text">
84 <p>The LLVM makefile system is the component of LLVM that is responsible for
85 building the software, testing it, generating distributions, rpms and other
86 packages, installing and uninstalling, etc.</p>
89 <!-- ======================================================================= -->
90 <div class="doc_subsection"><a name="projects">Projects</a></div>
91 <div class="doc_text">
92 <p>The LLVM Makefile System is quite generous. It not only builds its own
93 software, but it can build yours too. Built into the system is knowledge of
94 the <tt>llvm/projects</tt> directory. Any directory under <tt>projects</tt>
95 that has both a <tt>configure</tt> script and a <tt>Makefile</tt> is assumed
96 to be a project that uses the LLVM Makefile system. This allows your project
97 to get up and running quickly by utilizing the built-in features that are used
101 <!-- ======================================================================= -->
102 <div class="doc_subsection"><a name="Makefile">Makefile</a></div>
103 <div class="doc_text">
104 <p>Each directory to participate in the build needs to have a file named
105 <tt>Makefile</tt>. This is the file first read by <tt>make</tt>. It has three
108 <li><a href="setvars">Settable Variables</a> - Required that must be set
110 <li><a href="Makefile.common">include <tt>$(LEVEL)/Makefile.common</tt></a>
111 - include the LLVM Makefile system.
112 <li><a href="overvars">Overridable Variables</a> - Override variables set by
113 the LLVM Makefile system.
117 <!-- ======================================================================= -->
118 <div class="doc_subsection"><a name="Makefile.common">Makefile.common</a></div>
119 <div class="doc_text">
120 <p>Every project must have a <tt>Makefile.common</tt> file at its top source
121 directory. This file serves three purposes:</p>
123 <li>It includes the project's configuration makefile to obtain values
124 determined by the <tt>configure</tt> script. This is done by including the
125 <a href="Makefile.config"><tt>$(LEVEL)/Makefile.config</tt></a> file.</li>
126 <li>It specifies any other (static) values that are needed throughout the
127 project. Only values that are used in all or a large proportion of the
128 project's directories should be placed here.</li>
129 <li>It include's the standard rules for the LLVM Makefile system,
130 <a href="Makefile.rules"><tt>$(LLVM_SRC_ROOT)/Makefile.rules</tt></a>.
131 This file is the "guts" of the LLVM Makefile system.</li>
135 <!-- ======================================================================= -->
136 <div class="doc_subsection"><a name="Makefile.config">Makefile.config</a></div>
137 <div class="doc_text">
138 <p>Every project must have a <tt>Makefile.config</tt> at the top of its
139 <em>build</em> directory. This file is <b>generated</b> by the
140 <tt>configure</tt> script from the pattern provided by the
141 <tt>Makefile.config.in</tt> file located at the top of the project's
142 <em>source</em> directory. The contents of this file depend largely on what
143 configuration items the project uses, however most projects can get what they
144 need by just relying on LLVM's configuration found in
145 <tt>$(LLVM_OBJ_ROOT)/Makefile.config</tt>.
148 <!-- ======================================================================= -->
149 <div class="doc_subsection"><a name="Makefile.rules">Makefile.rules</a></div>
150 <div class="doc_text">
151 <p>This file, located at <tt>$(LLVM_SRC_ROOT)/Makefile.rules</tt> is the heart
152 of the LLVM Makefile System. It provides all the logic, dependencies, and
153 rules for building the targets supported by the system. What it does largely
154 depends on the values of <tt>make</tt> <a href="variables">variables</a> that
155 have been set <em>before</em> <tt>Makefile.rules</tt> is included.
158 <!-- ======================================================================= -->
159 <div class="doc_subsection"><a name="Comments">Comments</a></div>
160 <div class="doc_text">
161 <p>User Makefiles need not have comments in them unless the construction is
162 unusual or it doesn't strictly follow the rules and patterns of the LLVM
163 makefile system. Makefile comments are invoked with the pound (#) character.
164 The # character and any text following it, to the end of the line, are ignored
165 by <tt>make</tt>.</p>
168 <!-- *********************************************************************** -->
169 <div class="doc_section"><a name="targets">Targets Supported</a></div>
170 <!-- *********************************************************************** -->
172 <div class="doc_text">
173 <p>This section describes each of the targets that can be built using the LLVM
174 Makefile system. Any target can be invoked from any directory but not all are
175 applicable to a given directory (e.g. "dist" and "install" will always operate
176 as if invoked from the top level directory).</p>
178 <table style="text-align:left">
179 <tr><th>Target Name</th><th>Implied Targets</th><th>Target Description</th></tr>
180 <tr><td><a href="#all"><tt>all</tt></a></td><td></td>
181 <td>Compile the software recursively. Default target.
183 <tr><td><a href="#all-local"><tt>all-local</tt></a></td><td></td>
184 <td>Compile the software in the local directory only.
186 <tr><td><a href="#check"><tt>check</tt></a></td><td>all</td>
187 <td>Test the software recursively.
189 <tr><td><a href="#check-local"><tt>check-local</tt></a></td><td>all-local</td>
190 <td>Test the software in the local directory only.
192 <tr><td><a href="#clean"><tt>clean</tt></a></td><td></td>
193 <td>Remove built objects recursively.
195 <tr><td><a href="#clean-local"><tt>clean-local</tt></a></td><td></td>
196 <td>Remove built objects from the local directory only.
198 <tr><td><a href="#dist"><tt>dist</tt></a></td><td>all</td>
199 <td>Prepare a source distribution tarball.
201 <tr><td><a href="#dist-check"><tt>dist-check</tt></a></td><td>all check</td>
202 <td>Prepare a source distribution tarball and check that it builds.
204 <tr><td><a href="#dist-clean"><tt>dist-clean</tt></a></td><td>clean</td>
205 <td>Clean source distribution tarball temporary files.
207 <tr><td><a href="#install"><tt>install</tt></a></td><td>all</td>
208 <td>Copy built objects to installation directory.
210 <tr><td><a href="#tags"><tt>tags</tt></a></td><td></td>
211 <td>Make C and C++ tags files for emacs and vi.
213 <tr><td><a href="#uninstall"><tt>uninstall</tt></a></td><td></td>
214 <td>Remove built objects from installation directory.
219 <!-- ======================================================================= -->
220 <div class="doc_subsection"><a name="all">all (default)</a></div>
221 <div class="doc_text">
222 <p>When you invoke <tt>make</tt> with no arguments, you are implicitly
223 instructing it to seek the "all" target (goal). This target is used for
224 building the software recursively and will do different things in different
225 directories. For example, in a <tt>lib</tt> directory, the "all" target will
226 compile source files and generate libraries. But, in a <tt>tools</tt>
227 directory, it will link libraries and generate executables.</p>
230 <!-- ======================================================================= -->
231 <div class="doc_subsection"><a name="all-local">all-local</a></div>
232 <div class="doc_text">
233 <p>This target is the same as <a href="#all">all</a> but it operates only on
234 the current directory instead of recursively.</p>
237 <!-- ======================================================================= -->
238 <div class="doc_subsection"><a name="check">check</a></div>
239 <div class="doc_text">
240 <p>This target is used to perform any functional, unit or sanity tests as the
241 software is being built. The <tt>check</tt> target depends on the
242 <a href="#all"><tt>all</tt></a> target so the software is built in each
243 directory first and then the "check" is applied.</p>
244 <p>The definition of "check" is pretty general. It depends on the value of the
245 <a href="#TESTS"><tt>TESTS</tt></a> variable. This variable should be set to a
246 list of executables to run in order to test the software. If they all return
247 0 then the check succeeds, otherwise not. The programs run can be anything but
248 they should either be local to the directory or in your path.</p>
250 <div class="doc_warning"><p>Not implemented yet!</p></div>
252 <!-- ======================================================================= -->
253 <div class="doc_subsection"><a name="check-local">check-local</a></div>
254 <div class="doc_text">
255 <p>This target does the same thing as <tt>check</tt> but only for the current
256 (local) directory.</p>
258 <div class="doc_warning"><p>Not implemented yet!</p></div>
260 <!-- ======================================================================= -->
261 <div class="doc_subsection"><a name="clean">clean</a></div>
262 <div class="doc_text">
263 <p>This target cleans the build directory, recursively removing all things
264 that the Makefile builds. Despite once or twice attempting to remove /*, the
265 cleaning rules have been made guarded so they shouldn't go awry.</p>
268 <!-- ======================================================================= -->
269 <div class="doc_subsection"><a name="clean-local">clean-local</a></div>
270 <div class="doc_text">
271 <p>This target does the same thing as <tt>clean</tt> but only for the current
272 (local) directory.</p>
275 <!-- ======================================================================= -->
276 <div class="doc_subsection"><a name="dist">dist</a></div>
277 <div class="doc_text">
278 <p>This target builds a distribution tarball. It first builds the entire
279 project using the <tt>all</tt> target and then tars up the necessary files and
280 compresses it. The generated tarball is sufficient for a casual source
281 distribution, but probably not for a release (see <tt>dist-check</tt>).</p>
283 <div class="doc_warning"><p>Not implemented yet!</p></div>
285 <!-- ======================================================================= -->
286 <div class="doc_subsection"><a name="dist-check">dist-check</a></div>
287 <div class="doc_text">
288 <p>This target does the same thing as the <tt>dist</tt> target but also checks
289 the distribution tarball. The check is made by unpacking the tarball to a new
290 directory, configuring it, building it, installing it, and then verifying that
291 the installation results are correct (by comparing to the original build).
292 This target can take a long time to run but should be done before a release
293 goes out to make sure that the distributed tarball can actually be built into
294 a working release.</p>
296 <div class="doc_warning"><p>Not implemented yet!</p></div>
298 <!-- ======================================================================= -->
299 <div class="doc_subsection"><a name="dist-clean">dist-clean</a></div>
300 <div class="doc_text">
301 <p>This is a special form of the <tt>clean</tt> clean target. It performs a
302 normal <tt>clean</tt> but also removes things pertaining to building the
305 <div class="doc_warning"><p>Not implemented yet!</p></div>
307 <!-- ======================================================================= -->
308 <div class="doc_subsection"><a name="install">install</a></div>
309 <div class="doc_text">
310 <p>This target finalizes shared objects and executables and copies all
311 libraries, headers and executables to the directory given with the
312 <tt>--prefix</tt> option to <tt>configure</tt>. When completed, the prefix
313 directory will have everything needed to <b>use</b> LLVM. </p>
316 <!-- ======================================================================= -->
317 <div class="doc_subsection"><a name="printvars">printvars</a></div>
318 <div class="doc_text">
319 <p>This utility target just causes LLVM to print out some of its variables so
320 that you can double check how things are set. </p>
323 <!-- ======================================================================= -->
324 <div class="doc_subsection"><a name="tags">tags</a></div>
325 <div class="doc_text">
326 <p>This target will generate a <tt>TAGS</tt> file in the top-level source
327 directory. It is meant for use with emacs, XEmacs, or ViM. The TAGS file
328 provides an index of symbol definitions so that the editor can jump you to the
329 definition quickly. </p>
332 <!-- ======================================================================= -->
333 <div class="doc_subsection"><a name="uninstall">uninstall</a></div>
334 <div class="doc_text">
335 <p>This target is the opposite of the <tt>install</tt> target. It removes the
336 header, library and executable files from the installation directories. Note
337 that the directories themselves are not removed because it is not guaranteed
338 that LLVM is the only thing installing there (e.g. --prefix=/usr).</p>
341 <!-- *********************************************************************** -->
342 <div class="doc_section"><a name="variables">Variables</a></div>
343 <!-- *********************************************************************** -->
344 <div class="doc_text">
345 <p>Variables are used to tell the LLVM Makefile System what to do and to
346 obtain information from it. The sections below describe the three kinds of
350 <!-- ======================================================================= -->
351 <div class="doc_subsection"><a name="setvars">Control Variables</a></div>
352 <div class="doc_text">
353 <p>Variables listed in the table below should be set <em>before</em> the
354 inclusion of <a href="Makefile.common"><tt>$(LEVEL)/Makefile.common</tt></a>.
355 These variables provide input to the LLVM make system that tell it what to do
356 for the current directory.</p>
357 <table style="text-align:left">
358 <tr><th>Variable Name</th><th>Variable Description</th></tr>
360 <td><a href="#BUILD_ARCHIVE"><tt>BUILD_ARCHIVE</tt></a></td>
361 <td>If set to any value, causes an archive (.a) library to be built.</td>
362 </tr><tr><td><a href="#BUILT_SOURCES"><tt>BUILT_SOURCES</tt></a></td>
363 <td>Specifies a set of source files that are generated. These will be
364 built before any other target processing to ensure they are present.</td>
365 </tr><tr><td><a href="#BYTECODE_LIBRARY"><tt>BUILT_SOURCES</tt></a></td>
366 <td>If set to any value, causes a bytecode library (.bc) to be built.</td>
367 </tr><tr><td><a href="#CONFIG_FILES"><tt>BUILT_SOURCES</tt></a></td>
368 <td>Specifies a set of configuration files to be installed.</td>
369 </tr><tr><td><a href="#DIRS"><tt>DIRS</tt></a></td>
370 <td>Specifies a set of directories that should also be made using the
371 same goal. These directories will be built serially.</td>
372 </tr><tr><td><a href="#DONT_BUILD_RELINKED"><tt>DONT_BUILD_RELINKED</tt></a></td>
373 <td>If set to any value, causes a relinked library (.o) not to be built.</td>
374 </tr><tr><td><a href="#EXPORTED_SYMBOL_FILE"><tt>EXPORTED_SYMBOL_FILE</tt></a></td>
375 <td>Specifies the name of a single file that contains a list of the
376 symbols to be exported by the linker. One symbol per line.</td>
377 </tr><tr><td><a href="#LEVEL"><tt>LEVEL</tt></a></td>
378 <td>Specify the level of nesting from the top level. (Required)</td>
379 </tr><tr><td><a href="#LIBRARYNAME"><tt>LIBRARYNAME</tt></a></td>
380 <td>Specify the name of the library to be built. (Required For Libraries)</td>
381 </tr><tr><td><a href="#LLVMLIBS"><tt>LLVMLIBS</tt></a></td>
382 <td>Specify the set of libraries from the LLVM $(OBJDIR) that will be
383 linked into the tool or library.</td>
384 </tr><tr><td><a href="#EXPERIMENTAL_DIRS"><tt>EXPERIMENTAL_DIRS</tt></a></td>
385 <td>Specify a set of directories that should be built, but if they fail,
386 it should not cause the build to fail. Note that this should only be
387 used temporarily while code is being written.</td>
388 </tr><tr><td><a href="#OPTIONAL_DIRS"><tt>OPTIONAL_DIRS</tt></a></td>
389 <td>Specify a set of directories that may be built, if they exist, but its
390 not an error for them not to exist.</td>
391 </tr><tr><td><a href="#PARALLEL_DIRS"><tt>PARALLEL_DIRS</tt></a></td>
392 <td>Specify a set of directories to build recursively and in parallel if
393 the -j option was used with <tt>make</tt>.</td>
394 </tr><tr><td><a href="#SHARED_LIBRARY"><tt>SHARED_LIBRARY</tt></a></td>
395 <td>If set to any value, causes a shared library (.so) to be built.
397 </tr><tr><td><a href="#SOURCES"><tt>SOURCES</tt></a></td>
398 <td>Specifies the list of source files in the current directory to be
399 acted upon. Source files of any type may be specified (programs,
400 documentation, config files, etc.)</td>
401 </tr><tr><td><a href="#TARGET"><tt>TARGET</tt></a></td>
402 <td>Specifies the name of the LLVM code generation target that the
403 current directory builds.</td>
404 </tr><tr><td><a href="#TOOLNAME"><tt>TOOLNAME</tt></a></td>
405 <td>Specifies the name of the tool to build. (Required For Tools)</td>
406 </tr><tr><td><a href="#USEDLIBS"><tt>USEDLIBS</tt></a></td>
407 <td>Specifies the list of project libraries that will be linked into the
408 tool or library.</td>
413 <!-- ======================================================================= -->
414 <div class="doc_subsection"><a name="overvars">Overridable Variables</a></div>
415 <div class="doc_text">
416 <p>Variables listed in the table below can be used to override the default
417 values provided by the LLVM makefile system. These variables should be set
418 <em>after</em> the inclusion of <a
419 href="Makefile.common"><tt>$(LEVEL)/Makefile.common</tt></a>.</p>
420 <table style="text-align:left">
421 <tr><th>Variable Name</th><th>Variable Description</th></tr>
423 <td><a href="#C"><tt>C</tt></a></td>
424 <td>The name (and optional path) of the 'C' compiler (gcc normally).</td>
427 <td><a href="#CFLAGS"><tt>CFLAGS</tt></a></td>
428 <td>The set of options to be passed to the 'C' compiler on <em>every</em>
432 <td><a href="#CPP"><tt>CPP</tt></a></td>
433 <td>The name (and optional path) of the 'C' pre-processor (cpp normally).
437 <td><a href="#CXX"><tt>CXX</tt></a></td>
438 <td>The name (and optional path) of the C++ compiler (g++ normally).</td>
441 <td><a href="#LD"><tt>LD</tt></a></td>
442 <td>The name (and optional path) of the system linker (gcc normally).</td>
445 <td><a href="#LIBTOOL"><tt>LIBTOOL</tt></a></td>
446 <td>The name (and optional path) of the libtool tool (libtool normally).</td>
451 <!-- ======================================================================= -->
452 <div class="doc_subsection"><a name="getvars">Readable Variables</a></div>
453 <div class="doc_text">
454 <p>Variables listed in the table below can be used by the user's Makefile but
455 should not be changed. Changing the value will generally cause the build to go
456 wrong, so don't do it.</p>
457 <table style="text-align:left">
458 <tr><th>Variable Name</th><th>Variable Description</th></tr>
460 <td><a href="#BUILD_SRC_DIR"><tt>BUILD_SRC_DIR</tt></a></td>
461 <td>The project directory containing the directories source files.</td>
464 <td><a href="#BUILD_OBJ_DIR"><tt>BUILD_OBJ_DIR</tt></a></td>
465 <td>The project directory that will receive the object files.</td>
468 <td><a href="#CONFIGURATION"><tt>CONFIGURATION</tt></a></td>
469 <td>The name of the configuration being built.</td>
472 <td><a href="#DESTDIR"><tt>DESTDIR</tt></a></td>
473 <td>The top level directory into which files are installed.</td>
476 <td><a href="#LLVM_SRC_ROOT"><tt>LLVM_SRC_ROOT</tt></a></td>
477 <td>The top level directory of the LLVM source.</td>
480 <td><a href="#LLVM_OBJ_ROOT"><tt>LLVM_OBJ_ROOT</tt></a></td>
481 <td>The top level directory of the LLVM objects.</td>
484 <td><a href="#OBJDIR"><tt>OBJDIR</tt></a></td>
485 <td>The directory in which the project's object files should be placed.</td>
488 <td><a href="#LIBDIR"><tt>LIBDIR</tt></a></td>
489 <td>The directory in which the project's library files should be placed.</td>
492 <td><a href="#TOOLDIR"><tt>TOOLDIR</tt></a></td>
493 <td>The directory in which the project's executable tools should be
499 <!-- *********************************************************************** -->
502 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
503 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
504 <a href="http://validator.w3.org/check/referer"><img
505 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
507 <a href="mailto:rspencer@x10sys.com">Reid Spencer</a><br>
508 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
509 Last modified: $Date$