| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | 
|  | 2 | "http://www.w3.org/TR/html4/strict.dtd"> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 3 | <html> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 4 | <head> | 
| NAKAMURA Takumi | b8004d9 | 2011-10-31 11:21:59 +0000 | [diff] [blame] | 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 6 | <title>Creating an LLVM Project</title> | 
|  | 7 | <link rel="stylesheet" href="llvm.css" type="text/css"> | 
|  | 8 | </head> | 
|  | 9 | <body> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 10 |  | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 11 | <h1>Creating an LLVM Project</h1> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 12 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 28 |  | 
| Chris Lattner | 020e1fc | 2004-05-23 21:07:27 +0000 | [diff] [blame] | 29 | <div class="doc_author"> | 
|  | 30 | <p>Written by John Criswell</p> | 
|  | 31 | </div> | 
|  | 32 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 33 | <!-- *********************************************************************** --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 34 | <h2><a name="overview">Overview</a></h2> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 35 | <!-- *********************************************************************** --> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 36 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 37 | <div> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 38 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 39 | <p>The LLVM build system is designed to facilitate the building of third party | 
|  | 40 | projects that use LLVM header files, libraries, and tools.  In order to use | 
|  | 41 | these facilities, a Makefile from a project must do the following things:</p> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 42 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 43 | <ol> | 
| Reid Spencer | 05a2e79 | 2005-01-16 02:21:18 +0000 | [diff] [blame] | 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> | 
| Andrew Trick | 621129f0 | 2011-06-03 02:16:53 +0000 | [diff] [blame] | 53 | <li><tt>LEVEL</tt> - The relative path from the current directory to the | 
| Reid Spencer | 05a2e79 | 2005-01-16 02:21:18 +0000 | [diff] [blame] | 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> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 58 | </ol> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 59 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 60 | <p>There are two ways that you can set all of these variables:</p> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 61 | <ol> | 
| Reid Spencer | 05a2e79 | 2005-01-16 02:21:18 +0000 | [diff] [blame] | 62 | <li>You can write your own Makefiles which hard-code these values.</li> | 
| Andrew Trick | 621129f0 | 2011-06-03 02:16:53 +0000 | [diff] [blame] | 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 | 
| Reid Spencer | 05a2e79 | 2005-01-16 02:21:18 +0000 | [diff] [blame] | 66 | from a single source directory.</li> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 67 | </ol> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 68 |  | 
| Reid Spencer | 05a2e79 | 2005-01-16 02:21:18 +0000 | [diff] [blame] | 69 | <p>This document assumes that you will base your project on the LLVM sample | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 70 | project found in <tt>llvm/projects/sample</tt>.  If you want to devise your own | 
|  | 71 | build system, studying the sample project and LLVM Makefiles will probably | 
|  | 72 | provide enough information on how to write your own Makefiles.</p> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 73 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 74 | </div> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 75 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 76 | <!-- *********************************************************************** --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 77 | <h2> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 78 | <a name="create">Create a Project from the Sample Project</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 79 | </h2> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 80 | <!-- *********************************************************************** --> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 81 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 82 | <div> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 83 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 84 | <p>Follow these simple steps to start your project:</p> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 85 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 86 | <ol> | 
|  | 87 | <li>Copy the <tt>llvm/projects/sample</tt> directory to any place of your | 
|  | 88 | choosing.  You can place it anywhere you like.  Rename the directory to match | 
|  | 89 | the name of your project.</li> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 90 |  | 
| John Criswell | 6140e5d | 2005-10-24 16:43:08 +0000 | [diff] [blame] | 91 | <li> | 
| Andrew Trick | 621129f0 | 2011-06-03 02:16:53 +0000 | [diff] [blame] | 92 | If 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 | 
|  | 94 | keep Subversion from thinking that your project is inside | 
| Reid Spencer | c7f87f2 | 2007-07-09 08:04:31 +0000 | [diff] [blame] | 95 | <tt>llvm/trunk/projects/sample</tt>.</li> | 
| John Criswell | 6140e5d | 2005-10-24 16:43:08 +0000 | [diff] [blame] | 96 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 97 | <li>Add your source code and Makefiles to your source tree.</li> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 98 |  | 
| Reid Spencer | da132f2 | 2005-02-28 00:40:29 +0000 | [diff] [blame] | 99 | <li>If you want your project to be configured with the <tt>configure</tt> script | 
|  | 100 | then 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> | 
| Chris Lattner | b96bf56 | 2006-03-16 16:14:59 +0000 | [diff] [blame] | 104 | <li><b>AC_CONFIG_AUX_DIR</b>. If your project isn't in the | 
| Reid Spencer | da132f2 | 2005-02-28 00:40:29 +0000 | [diff] [blame] | 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 | 
| Reid Spencer | dca24a1 | 2006-03-17 08:04:25 +0000 | [diff] [blame] | 109 | your project; or just leave it at <tt>Makefile.common.in</tt></li> | 
| Reid Spencer | da132f2 | 2005-02-28 00:40:29 +0000 | [diff] [blame] | 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> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 116 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 117 | <li>After updating <tt>autoconf/configure.ac</tt>, regenerate the | 
|  | 118 | configure script with these commands: | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 119 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 120 | <div class="doc_code"> | 
|  | 121 | <p><tt>% cd autoconf<br> | 
| Dan Gohman | 87bc800 | 2009-01-12 21:29:24 +0000 | [diff] [blame] | 122 | % ./AutoRegen.sh</tt></p> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 123 | </div> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 124 |  | 
| Misha Brukman | 952784f | 2009-08-13 20:08:52 +0000 | [diff] [blame] | 125 | <p>You must be using Autoconf version 2.59 or later and your aclocal version | 
|  | 126 | should be 1.9 or later.</p></li> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 127 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 128 | <li>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: | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 131 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 132 | <dl> | 
| Reid Spencer | da132f2 | 2005-02-28 00:40:29 +0000 | [diff] [blame] | 133 | <dt><tt>--with-llvmsrc=<directory></tt></dt> | 
|  | 134 | <dd>Tell your project where the LLVM source tree is located.</dd> | 
| Misha Brukman | 21a6370 | 2008-12-11 18:23:24 +0000 | [diff] [blame] | 135 | <dt><br><tt>--with-llvmobj=<directory></tt></dt> | 
| Reid Spencer | da132f2 | 2005-02-28 00:40:29 +0000 | [diff] [blame] | 136 | <dd>Tell your project where the LLVM object tree is located.</dd> | 
| Misha Brukman | 21a6370 | 2008-12-11 18:23:24 +0000 | [diff] [blame] | 137 | <dt><br><tt>--prefix=<directory></tt></dt> | 
| Reid Spencer | da132f2 | 2005-02-28 00:40:29 +0000 | [diff] [blame] | 138 | <dd>Tell your project where it should get installed.</dd> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 139 | </dl> | 
|  | 140 | </ol> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 141 |  | 
| Reid Spencer | da132f2 | 2005-02-28 00:40:29 +0000 | [diff] [blame] | 142 | <p>That's it!  Now all you have to do is type <tt>gmake</tt> (or <tt>make</tt> | 
| Andrew Trick | 621129f0 | 2011-06-03 02:16:53 +0000 | [diff] [blame] | 143 | if your on a GNU/Linux system) in the root of your object directory, and your | 
| Reid Spencer | da132f2 | 2005-02-28 00:40:29 +0000 | [diff] [blame] | 144 | project should build.</p> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 145 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 146 | </div> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 147 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 148 | <!-- *********************************************************************** --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 149 | <h2> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 150 | <a name="source">Source Tree Layout</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 151 | </h2> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 152 | <!-- *********************************************************************** --> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 153 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 154 | <div> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 155 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 156 | <p>In order to use the LLVM build system, you will want to organize your | 
|  | 157 | source code so that it can benefit from the build system's features. | 
|  | 158 | Mainly, you want your source tree layout to look similar to the LLVM | 
|  | 159 | source tree layout.  The best way to do this is to just copy the | 
|  | 160 | project tree from <tt>llvm/projects/sample</tt> and modify it to meet | 
|  | 161 | your needs, but you can certainly add to it if you want.</p> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 162 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 163 | <p>Underneath your top level directory, you should have the following | 
|  | 164 | directories:</p> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 165 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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. | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 173 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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. | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 179 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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>. | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 190 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 198 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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> | 
| Tanya Lattner | e6ebbd7 | 2004-12-08 17:25:46 +0000 | [diff] [blame] | 204 | Currently, the LLVM build system provides basic support for tests. | 
|  | 205 | The LLVM system provides the following: | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 206 | <ul> | 
|  | 207 | <li> | 
| Tanya Lattner | e6ebbd7 | 2004-12-08 17:25:46 +0000 | [diff] [blame] | 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 | 
| Andrew Trick | 621129f0 | 2011-06-03 02:16:53 +0000 | [diff] [blame] | 213 | can easily write Makefile support similar to the Makefiles in | 
| Misha Brukman | 21a6370 | 2008-12-11 18:23:24 +0000 | [diff] [blame] | 214 | <tt>llvm/test</tt> to use Dejagnu to run your project's tests.<br></li> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 215 | <li> | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 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 | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 219 | programs to test your code, gather statistics information, and | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 220 | compare it to the current LLVM performance statistics. | 
| Misha Brukman | 21a6370 | 2008-12-11 18:23:24 +0000 | [diff] [blame] | 221 | <br>Currently, there is no way to hook your tests directly into the | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 222 | <tt>llvm/test</tt> testing harness.  You will simply | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 223 | need to find a way to use the source provided within that directory | 
|  | 224 | on your own. | 
|  | 225 | </ul> | 
|  | 226 | </dl> | 
| John Criswell | b920fe7 | 2003-10-21 19:35:06 +0000 | [diff] [blame] | 227 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 228 | <p>Typically, you will want to build your <b>lib</b> directory first followed by | 
|  | 229 | your <b>tools</b> directory.</p> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 230 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 231 | </div> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 232 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 233 | <!-- *********************************************************************** --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 234 | <h2> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 235 | <a name="makefiles">Writing LLVM Style Makefiles</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 236 | </h2> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 237 | <!-- *********************************************************************** --> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 238 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 239 | <div> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 240 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 241 | <p>The LLVM build system provides a convenient way to build libraries and | 
|  | 242 | executables.  Most of your project Makefiles will only need to define a few | 
|  | 243 | variables.  Below is a list of the variables one can set and what they can | 
|  | 244 | do:</p> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 245 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 246 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 247 | <h3> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 248 | <a name="reqVars">Required Variables</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 249 | </h3> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 250 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 251 | <div> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 252 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 261 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 262 | </div> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 263 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 264 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 265 | <h3> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 266 | <a name="varsBuildDir">Variables for Building Subdirectories</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 267 | </h3> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 268 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 269 | <div> | 
| John Criswell | 91dbd8f | 2003-10-17 21:50:38 +0000 | [diff] [blame] | 270 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 278 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 285 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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> | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 292 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 293 | </div> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 294 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 295 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 296 | <h3> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 297 | <a name="varsBuildLib">Variables for Building Libraries</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 298 | </h3> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 299 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 300 | <div> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 301 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 310 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 317 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 327 | <h3> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 328 | <a name="varsBuildProg">Variables for Building Programs</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 329 | </h3> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 330 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 331 | <div> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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> | 
| Andrew Trick | c71224e | 2011-06-03 02:20:48 +0000 | [diff] [blame] | 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>. | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 349 | <p> | 
|  | 350 | Note that this works only for statically linked libraries. | 
|  | 351 | <p> | 
|  | 352 |  | 
| Andrew Trick | c71224e | 2011-06-03 02:20:48 +0000 | [diff] [blame] | 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 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 378 | <dt>LIBS | 
|  | 379 | <dd> | 
|  | 380 | To link dynamic libraries, add <tt>-l<library base name></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> | 
| Andrew Trick | c71224e | 2011-06-03 02:20:48 +0000 | [diff] [blame] | 390 | <p> | 
|  | 391 | Note that LIBS must occur in the Makefile after the inclusion of Makefile.common. | 
|  | 392 | <p> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 393 | </dl> | 
|  | 394 |  | 
|  | 395 | </div> | 
|  | 396 |  | 
|  | 397 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 398 | <h3> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 399 | <a name="miscVars">Miscellaneous Variables</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 400 | </h3> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 401 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 402 | <div> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 428 | </div> | 
|  | 429 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 430 | <!-- *********************************************************************** --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 431 | <h2> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 432 | <a name="objcode">Placement of Object Code</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 433 | </h2> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 434 | <!-- *********************************************************************** --> | 
|  | 435 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 436 | <div> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 437 |  | 
|  | 438 | <p>The final location of built libraries and executables will depend upon | 
|  | 439 | whether 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 | 
| Reid Spencer | 64cee42 | 2005-01-16 02:38:06 +0000 | [diff] [blame] | 445 | <tt>PROJ_OBJ_ROOT/<type>/lib</tt>, where type is <tt>Debug</tt>, | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 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 | 
| Reid Spencer | 64cee42 | 2005-01-16 02:38:06 +0000 | [diff] [blame] | 451 | <tt>PROJ_OBJ_ROOT/<type>/bin</tt>, where type is <tt>Debug</tt>, | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 452 | <tt>Release</tt>, or <tt>Profile</tt> for a debug, optimized, or profiled | 
|  | 453 | build, respectively. | 
|  | 454 | </dl> | 
|  | 455 |  | 
|  | 456 | </div> | 
|  | 457 |  | 
|  | 458 | <!-- *********************************************************************** --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 459 | <h2> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 460 | <a name="help">Further Help</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 461 | </h2> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 462 | <!-- *********************************************************************** --> | 
|  | 463 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 464 | <div> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 465 |  | 
|  | 466 | <p>If you have any questions or need any help creating an LLVM project, | 
|  | 467 | the LLVM team would be more than happy to help.  You can always post your | 
|  | 468 | questions to the <a | 
|  | 469 | href="http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev">LLVM Developers | 
|  | 470 | Mailing List</a>.</p> | 
|  | 471 |  | 
|  | 472 | </div> | 
| Andrew Trick | 621129f0 | 2011-06-03 02:16:53 +0000 | [diff] [blame] | 473 |  | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 474 | <!-- *********************************************************************** --> | 
| John Criswell | 5bd28dc | 2003-10-16 19:53:53 +0000 | [diff] [blame] | 475 | <hr> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 476 | <address> | 
|  | 477 | <a href="http://jigsaw.w3.org/css-validator/check/referer"><img | 
| Misha Brukman | 86242e1 | 2008-12-11 17:34:48 +0000 | [diff] [blame] | 478 | src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 479 | <a href="http://validator.w3.org/check/referer"><img | 
| Misha Brukman | 21a6370 | 2008-12-11 18:23:24 +0000 | [diff] [blame] | 480 | src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 481 |  | 
|  | 482 | <a href="mailto:criswell@uiuc.edu">John Criswell</a><br> | 
| NAKAMURA Takumi | ca46f5a | 2011-04-09 02:13:37 +0000 | [diff] [blame] | 483 | <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a> | 
| Misha Brukman | e15655b | 2004-05-12 20:57:43 +0000 | [diff] [blame] | 484 | <br> | 
|  | 485 | Last modified: $Date$ | 
|  | 486 | </address> | 
| Misha Brukman | d8c3ba3 | 2003-10-30 01:23:40 +0000 | [diff] [blame] | 487 |  | 
| John Criswell | 163110d | 2003-07-03 15:37:52 +0000 | [diff] [blame] | 488 | </body> | 
|  | 489 | </html> |