/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

  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. <h1>Creating an LLVM Project</h1>
  11. <ol>
  12. <li><a href="#overview">Overview</a></li>
  13. <li><a href="#create">Create a project from the Sample Project</a></li>
  14. <li><a href="#source">Source tree layout</a></li>
  15. <li><a href="#makefiles">Writing LLVM-style Makefiles</a>
  16. <ol>
  17. <li><a href="#reqVars">Required Variables</a></li>
  18. <li><a href="#varsBuildDir">Variables for Building Subdirectories</a></li>
  19. <li><a href="#varsBuildLib">Variables for Building Libraries</a></li>
  20. <li><a href="#varsBuildProg">Variables for Building Programs</a></li>
  21. <li><a href="#miscVars">Miscellaneous Variables</a></li>
  22. </ol></li>
  23. <li><a href="#objcode">Placement of object code</a></li>
  24. <li><a href="#help">Further help</a></li>
  25. </ol>
  26. <div class="doc_author">
  27. <p>Written by John Criswell</p>
  28. </div>
  29. <!-- *********************************************************************** -->
  30. <h2><a name="overview">Overview</a></h2>
  31. <!-- *********************************************************************** -->
  32. <div>
  33. <p>The LLVM build system is designed to facilitate the building of third party
  34. projects that use LLVM header files, libraries, and tools. In order to use
  35. these facilities, a Makefile from a project must do the following things:</p>
  36. <ol>
  37. <li>Set <tt>make</tt> variables. There are several variables that a Makefile
  38. needs to set to use the LLVM build system:
  39. <ul>
  40. <li><tt>PROJECT_NAME</tt> - The name by which your project is known.</li>
  41. <li><tt>LLVM_SRC_ROOT</tt> - The root of the LLVM source tree.</li>
  42. <li><tt>LLVM_OBJ_ROOT</tt> - The root of the LLVM object tree.</li>
  43. <li><tt>PROJ_SRC_ROOT</tt> - The root of the project's source tree.</li>
  44. <li><tt>PROJ_OBJ_ROOT</tt> - The root of the project's object tree.</li>
  45. <li><tt>PROJ_INSTALL_ROOT</tt> - The root installation directory.</li>
  46. <li><tt>LEVEL</tt> - The relative path from the current directory to the
  47. project's root ($PROJ_OBJ_ROOT).</li>
  48. </ul></li>
  49. <li>Include <tt>Makefile.config</tt> from <tt>$(LLVM_OBJ_ROOT)</tt>.</li>
  50. <li>Include <tt>Makefile.rules</tt> from <tt>$(LLVM_SRC_ROOT)</tt>.</li>
  51. </ol>
  52. <p>There are two ways that you can set all of these variables:</p>
  53. <ol>
  54. <li>You can write your own Makefiles which hard-code these values.</li>
  55. <li>You can use the pre-made LLVM sample project. This sample project
  56. includes Makefiles, a configure script that can be used to configure the
  57. location of LLVM, and the ability to support multiple object directories
  58. from a single source directory.</li>
  59. </ol>
  60. <p>This document assumes that you will base your project on the LLVM sample
  61. project found in <tt>llvm/projects/sample</tt>. If you want to devise your own
  62. build system, studying the sample project and LLVM Makefiles will probably
  63. provide enough information on how to write your own Makefiles.</p>
  64. </div>
  65. <!-- *********************************************************************** -->
  66. <h2>
  67. <a name="create">Create a Project from the Sample Project</a>
  68. </h2>
  69. <!-- *********************************************************************** -->
  70. <div>
  71. <p>Follow these simple steps to start your project:</p>
  72. <ol>
  73. <li>Copy the <tt>llvm/projects/sample</tt> directory to any place of your
  74. choosing. You can place it anywhere you like. Rename the directory to match
  75. the name of your project.</li>
  76. <li>
  77. If you downloaded LLVM using Subversion, remove all the directories named .svn
  78. (and all the files therein) from your project's new source tree. This will
  79. keep Subversion from thinking that your project is inside
  80. <tt>llvm/trunk/projects/sample</tt>.</li>
  81. <li>Add your source code and Makefiles to your source tree.</li>
  82. <li>If you want your project to be configured with the <tt>configure</tt> script
  83. then you need to edit <tt>autoconf/configure.ac</tt> as follows:
  84. <ul>
  85. <li><b>AC_INIT</b>. Place the name of your project, its version number and
  86. a contact email address for your project as the arguments to this macro</li>
  87. <li><b>AC_CONFIG_AUX_DIR</b>. If your project isn't in the
  88. <tt>llvm/projects</tt> directory then you might need to adjust this so that
  89. it specifies a relative path to the <tt>llvm/autoconf</tt> directory.</li>
  90. <li><b>LLVM_CONFIG_PROJECT</b>. Just leave this alone.</li>
  91. <li><b>AC_CONFIG_SRCDIR</b>. Specify a path to a file name that identifies
  92. your project; or just leave it at <tt>Makefile.common.in</tt></li>
  93. <li><b>AC_CONFIG_FILES</b>. Do not change.</li>
  94. <li><b>AC_CONFIG_MAKEFILE</b>. Use one of these macros for each Makefile
  95. that your project uses. This macro arranges for your makefiles to be copied
  96. from the source directory, unmodified, to the build directory.</li>
  97. </ul>
  98. </li>
  99. <li>After updating <tt>autoconf/configure.ac</tt>, regenerate the
  100. configure script with these commands:
  101. <div class="doc_code">
  102. <p><tt>% cd autoconf<br>
  103. % ./AutoRegen.sh</tt></p>
  104. </div>
  105. <p>You must be using Autoconf version 2.59 or later and your aclocal version
  106. should be 1.9 or later.</p></li>
  107. <li>Run <tt>configure</tt> in the directory in which you want to place
  108. object code. Use the following options to tell your project where it
  109. can find LLVM:
  110. <dl>
  111. <dt><tt>--with-llvmsrc=&lt;directory&gt;</tt></dt>
  112. <dd>Tell your project where the LLVM source tree is located.</dd>
  113. <dt><br><tt>--with-llvmobj=&lt;directory&gt;</tt></dt>
  114. <dd>Tell your project where the LLVM object tree is located.</dd>
  115. <dt><br><tt>--prefix=&lt;directory&gt;</tt></dt>
  116. <dd>Tell your project where it should get installed.</dd>
  117. </dl>
  118. </ol>
  119. <p>That's it! Now all you have to do is type <tt>gmake</tt> (or <tt>make</tt>
  120. if your on a GNU/Linux system) in the root of your object directory, and your
  121. project should build.</p>
  122. </div>
  123. <!-- *********************************************************************** -->
  124. <h2>
  125. <a name="source">Source Tree Layout</a>
  126. </h2>
  127. <!-- *********************************************************************** -->
  128. <div>
  129. <p>In order to use the LLVM build system, you will want to organize your
  130. source code so that it can benefit from the build system's features.
  131. Mainly, you want your source tree layout to look similar to the LLVM
  132. source tree layout. The best way to do this is to just copy the
  133. project tree from <tt>llvm/projects/sample</tt> and modify it to meet
  134. your needs, but you can certainly add to it if you want.</p>
  135. <p>Underneath your top level directory, you should have the following
  136. directories:</p>
  137. <dl>
  138. <dt><b>lib</b>
  139. <dd>
  140. This subdirectory should contain all of your library source
  141. code. For each library that you build, you will have one
  142. directory in <b>lib</b> that will contain that library's source
  143. code.
  144. <p>
  145. Libraries can be object files, archives, or dynamic libraries.
  146. The <b>lib</b> directory is just a convenient place for libraries
  147. as it places them all in a directory from which they can be linked
  148. later.
  149. <dt><b>include</b>
  150. <dd>
  151. This subdirectory should contain any header files that are
  152. global to your project. By global, we mean that they are used
  153. by more than one library or executable of your project.
  154. <p>
  155. By placing your header files in <b>include</b>, they will be
  156. found automatically by the LLVM build system. For example, if
  157. you have a file <b>include/jazz/note.h</b>, then your source
  158. files can include it simply with <b>#include "jazz/note.h"</b>.
  159. <dt><b>tools</b>
  160. <dd>
  161. This subdirectory should contain all of your source
  162. code for executables. For each program that you build, you
  163. will have one directory in <b>tools</b> that will contain that
  164. program's source code.
  165. <p>
  166. <dt><b>test</b>
  167. <dd>
  168. This subdirectory should contain tests that verify that your code
  169. works correctly. Automated tests are especially useful.
  170. <p>
  171. Currently, the LLVM build system provides basic support for tests.
  172. The LLVM system provides the following:
  173. <ul>
  174. <li>
  175. LLVM provides a tcl procedure that is used by Dejagnu to run
  176. tests. It can be found in <tt>llvm/lib/llvm-dg.exp</tt>. This
  177. test procedure uses RUN lines in the actual test case to determine
  178. how to run the test. See the <a
  179. href="TestingGuide.html">TestingGuide</a> for more details. You
  180. can easily write Makefile support similar to the Makefiles in
  181. <tt>llvm/test</tt> to use Dejagnu to run your project's tests.<br></li>
  182. <li>
  183. LLVM contains an optional package called <tt>llvm-test</tt>
  184. which provides benchmarks and programs that are known to compile with the
  185. LLVM GCC front ends. You can use these
  186. programs to test your code, gather statistics information, and
  187. compare it to the current LLVM performance statistics.
  188. <br>Currently, there is no way to hook your tests directly into the
  189. <tt>llvm/test</tt> testing harness. You will simply
  190. need to find a way to use the source provided within that directory
  191. on your own.
  192. </ul>
  193. </dl>
  194. <p>Typically, you will want to build your <b>lib</b> directory first followed by
  195. your <b>tools</b> directory.</p>
  196. </div>
  197. <!-- *********************************************************************** -->
  198. <h2>
  199. <a name="makefiles">Writing LLVM Style Makefiles</a>
  200. </h2>
  201. <!-- *********************************************************************** -->
  202. <div>
  203. <p>The LLVM build system provides a convenient way to build libraries and
  204. executables. Most of your project Makefiles will only need to define a few
  205. variables. Below is a list of the variables one can set and what they can
  206. do:</p>
  207. <!-- ======================================================================= -->
  208. <h3>
  209. <a name="reqVars">Required Variables</a>
  210. </h3>
  211. <div>
  212. <dl>
  213. <dt>LEVEL
  214. <dd>
  215. This variable is the relative path from this Makefile to the
  216. top directory of your project's source code. For example, if
  217. your source code is in <tt>/tmp/src</tt>, then the Makefile in
  218. <tt>/tmp/src/jump/high</tt> would set <tt>LEVEL</tt> to <tt>"../.."</tt>.
  219. </dl>
  220. </div>
  221. <!-- ======================================================================= -->
  222. <h3>
  223. <a name="varsBuildDir">Variables for Building Subdirectories</a>
  224. </h3>
  225. <div>
  226. <dl>
  227. <dt>DIRS
  228. <dd>
  229. This is a space separated list of subdirectories that should be
  230. built. They will be built, one at a time, in the order
  231. specified.
  232. <p>
  233. <dt>PARALLEL_DIRS
  234. <dd>
  235. This is a list of directories that can be built in parallel.
  236. These will be built after the directories in DIRS have been
  237. built.
  238. <p>
  239. <dt>OPTIONAL_DIRS
  240. <dd>
  241. This is a list of directories that can be built if they exist,
  242. but will not cause an error if they do not exist. They are
  243. built serially in the order in which they are listed.
  244. </dl>
  245. </div>
  246. <!-- ======================================================================= -->
  247. <h3>
  248. <a name="varsBuildLib">Variables for Building Libraries</a>
  249. </h3>
  250. <div>
  251. <dl>
  252. <dt>LIBRARYNAME
  253. <dd>
  254. This variable contains the base name of the library that will
  255. be built. For example, to build a library named
  256. <tt>libsample.a</tt>, LIBRARYNAME should be set to
  257. <tt>sample</tt>.
  258. <p>
  259. <dt>BUILD_ARCHIVE
  260. <dd>
  261. By default, a library is a <tt>.o</tt> file that is linked
  262. directly into a program. To build an archive (also known as
  263. a static library), set the BUILD_ARCHIVE variable.
  264. <p>
  265. <dt>SHARED_LIBRARY
  266. <dd>
  267. If SHARED_LIBRARY is defined in your Makefile, a shared
  268. (or dynamic) library will be built.
  269. </dl>
  270. </div>
  271. <!-- ======================================================================= -->
  272. <h3>
  273. <a name="varsBuildProg">Variables for Building Programs</a>
  274. </h3>
  275. <div>
  276. <dl>
  277. <dt>TOOLNAME
  278. <dd>
  279. This variable contains the name of the program that will
  280. be built. For example, to build an executable named
  281. <tt>sample</tt>, TOOLNAME should be set to <tt>sample</tt>.
  282. <p>
  283. <dt>USEDLIBS
  284. <dd>
  285. This variable holds a space separated list of libraries that should
  286. be linked into the program. These libraries must be libraries that
  287. come from your <b>lib</b> directory. The libraries must be
  288. specified without their "lib" prefix. For example, to link
  289. libsample.a, you would set USEDLIBS to
  290. <tt>sample.a</tt>.
  291. <p>
  292. Note that this works only for statically linked libraries.
  293. <p>
  294. <dt>LLVMLIBS
  295. <dd>
  296. This variable holds a space separated list of libraries that should
  297. be linked into the program. These libraries must be LLVM libraries.
  298. The libraries must be specified without their "lib" prefix. For
  299. example, to link with a driver that performs an IR transformation
  300. you might set LLVMLIBS to this minimal set of libraries
  301. <tt>LLVMSupport.a LLVMCore.a LLVMBitReader.a LLVMAsmParser.a LLVMAnalysis.a LLVMTransformUtils.a LLVMScalarOpts.a LLVMTarget.a</tt>.
  302. <p>
  303. Note that this works only for statically linked libraries. LLVM is
  304. split into a large number of static libraries, and the list of libraries you
  305. require may be much longer than the list above. To see a full list
  306. of libraries use:
  307. <tt>llvm-config --libs all</tt>.
  308. Using LINK_COMPONENTS as described below, obviates the need to set LLVMLIBS.
  309. <p>
  310. <dt>LINK_COMPONENTS
  311. <dd>This variable holds a space separated list of components that
  312. the LLVM Makefiles pass to the <tt>llvm-config</tt> tool to generate
  313. a link line for the program. For example, to link with all LLVM
  314. libraries use
  315. <tt>LINK_COMPONENTS = all</tt>.
  316. <p>
  317. <dt>LIBS
  318. <dd>
  319. To link dynamic libraries, add <tt>-l&lt;library base name&gt;</tt> to
  320. the LIBS variable. The LLVM build system will look in the same places
  321. for dynamic libraries as it does for static libraries.
  322. <p>
  323. For example, to link <tt>libsample.so</tt>, you would have the
  324. following line in your <tt>Makefile</tt>:
  325. <p>
  326. <tt>
  327. LIBS += -lsample
  328. </tt>
  329. <p>
  330. Note that LIBS must occur in the Makefile after the inclusion of Makefile.common.
  331. <p>
  332. </dl>
  333. </div>
  334. <!-- ======================================================================= -->
  335. <h3>
  336. <a name="miscVars">Miscellaneous Variables</a>
  337. </h3>
  338. <div>
  339. <dl>
  340. <dt>ExtraSource
  341. <dd>
  342. This variable contains a space separated list of extra source
  343. files that need to be built. It is useful for including the
  344. output of Lex and Yacc programs.
  345. <p>
  346. <dt>CFLAGS
  347. <dt>CPPFLAGS
  348. <dd>
  349. This variable can be used to add options to the C and C++
  350. compiler, respectively. It is typically used to add options
  351. that tell the compiler the location of additional directories
  352. to search for header files.
  353. <p>
  354. It is highly suggested that you append to CFLAGS and CPPFLAGS as
  355. opposed to overwriting them. The master Makefiles may already
  356. have useful options in them that you may not want to overwrite.
  357. <p>
  358. </dl>
  359. </div>
  360. </div>
  361. <!-- *********************************************************************** -->
  362. <h2>
  363. <a name="objcode">Placement of Object Code</a>
  364. </h2>
  365. <!-- *********************************************************************** -->
  366. <div>
  367. <p>The final location of built libraries and executables will depend upon
  368. whether you do a Debug, Release, or Profile build.</p>
  369. <dl>
  370. <dt>Libraries
  371. <dd>
  372. All libraries (static and dynamic) will be stored in
  373. <tt>PROJ_OBJ_ROOT/&lt;type&gt;/lib</tt>, where type is <tt>Debug</tt>,
  374. <tt>Release</tt>, or <tt>Profile</tt> for a debug, optimized, or
  375. profiled build, respectively.<p>
  376. <dt>Executables
  377. <dd>All executables will be stored in
  378. <tt>PROJ_OBJ_ROOT/&lt;type&gt;/bin</tt>, where type is <tt>Debug</tt>,
  379. <tt>Release</tt>, or <tt>Profile</tt> for a debug, optimized, or profiled
  380. build, respectively.
  381. </dl>
  382. </div>
  383. <!-- *********************************************************************** -->
  384. <h2>
  385. <a name="help">Further Help</a>
  386. </h2>
  387. <!-- *********************************************************************** -->
  388. <div>
  389. <p>If you have any questions or need any help creating an LLVM project,
  390. the LLVM team would be more than happy to help. You can always post your
  391. questions to the <a
  392. href="http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev">LLVM Developers
  393. Mailing List</a>.</p>
  394. </div>
  395. <!-- *********************************************************************** -->
  396. <hr>
  397. <address>
  398. <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
  399. src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
  400. <a href="http://validator.w3.org/check/referer"><img
  401. src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
  402. <a href="mailto:criswell@uiuc.edu">John Criswell</a><br>
  403. <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a>
  404. <br>
  405. Last modified: $Date: 2011-11-03 14:43:23 +0800 (Thu, 03 Nov 2011) $
  406. </address>
  407. </body>
  408. </html>