buildroot.html 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <title>Buildroot - Usage and documentation</title>
  7. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  8. <link rel="stylesheet" type="text/css" href="stylesheet.css" />
  9. </head>
  10. <body>
  11. <div class="main">
  12. <div class="titre">
  13. <h1>Buildroot</h1>
  14. </div>
  15. <p><a href="http://buildroot.uclibc.org/">Buildroot</a>
  16. usage and documentation by Thomas Petazzoni. Contributions from
  17. Karsten Kruse, Ned Ludd, Martin Herren and others. </p>
  18. <p><small>$LastChangedDate$</small></p>
  19. <ul>
  20. <li><a href="#about">About Buildroot</a></li>
  21. <li><a href="#download">Obtaining Buildroot</a></li>
  22. <li><a href="#using">Using Buildroot</a></li>
  23. <li><a href="#custom_targetfs">Customizing the target filesystem</a></li>
  24. <li><a href="#custom_busybox">Customizing the Busybox
  25. configuration</a></li>
  26. <li><a href="#custom_uclibc">Customizing the uClibc
  27. configuration</a></li>
  28. <li><a href="#buildroot_innards">How Buildroot works</a></li>
  29. <li><a href="#using_toolchain">Using the uClibc toolchain</a></li>
  30. <li><a href="#toolchain_standalone">Using the uClibc toolchain
  31. outside of Buildroot</a></li>
  32. <li><a href="#downloaded_packages">Location of downloaded packages</a>
  33. </li>
  34. <li><a href="#add_software">Extending Buildroot with more
  35. Software</a></li>
  36. <li><a href="#links">Resources</a></li>
  37. </ul>
  38. <h2><a name="about" id="about"></a>About Buildroot</h2>
  39. <p>Buildroot is a set of Makefiles and patches that allow to easily
  40. generate both a cross-compilation toolchain and a root filesystem for your
  41. target. The cross-compilation toolchain uses uClibc (<a href=
  42. "http://www.uclibc.org/">http://www.uclibc.org/</a>), a tiny C standard
  43. library. </p>
  44. <p>Buildroot is useful mainly for people working with embedded systems.
  45. Embedded systems often use processors that are not the regular x86
  46. processors everyone is used to have on his PC. It can be PowerPC
  47. processors, MIPS processors, ARM processors, etc. </p>
  48. <p>A compilation toolchain is the set of tools that allows to
  49. compile code for your system. It consists of a compiler (in our
  50. case, <code>gcc</code>), binary utils like assembler and linker
  51. (in our case, <code>binutils</code>) and a C standard library (for
  52. example <a href="http://www.gnu.org/software/libc/libc.html">GNU
  53. Libc</a>, <a href="http://www.uclibc.org/">uClibc</a> or <a
  54. href="http://www.fefe.de/dietlibc/">dietlibc</a>). The system
  55. installed on your development station certainly already has a
  56. compilation toolchain that you can use to compile application that
  57. runs on your system. If you're using a PC, your compilation
  58. toolchain runs on an x86 processor and generates code for a x86
  59. processor. Under most Linux systems, the compilation toolchain
  60. uses the GNU libc as C standard library. This compilation
  61. toolchain is called the &quot;host compilation toolchain&quot;, and more
  62. generally, the machine on which it is running, and on which you're
  63. working is called the &quot;host system&quot;. The compilation toolchain
  64. is provided by your distribution, and Buildroot has nothing to do
  65. with it. </p>
  66. <p>As said above, the compilation toolchain that comes with your system
  67. runs and generates code for the processor of your host system. As your
  68. embedded system has a different processor, you need a cross-compilation
  69. toolchain: it's a compilation toolchain that runs on your host system but
  70. that generates code for your target system (and target processor). For
  71. example, if your host system uses x86 and your target system uses ARM, the
  72. regular compilation toolchain of your host runs on x86 and generates code
  73. for x86, while the cross-compilation toolchain runs on x86 and generates
  74. code for ARM. </p>
  75. <p>Even if your embedded system uses a x86 processor, you might interested
  76. in Buildroot, for two reasons:</p>
  77. <ul>
  78. <li>The compilation toolchain of your host certainly uses the GNU Libc
  79. which is a complete but huge C standard library. Instead of using GNU
  80. Libc on your target system, you can use uClibc which is a tiny C standard
  81. library. If you want to use this C library, then you need a compilation
  82. toolchain to generate binaries linked with it. Buildroot can do it for
  83. you. </li>
  84. <li>Buildroot automates the building of a root filesystem with all needed
  85. tools like busybox. It makes it much easier than doing it by hand. </li>
  86. </ul>
  87. <p>You might wonder why such a tool is needed when you can compile
  88. <code>gcc</code>, <code>binutils</code>, uClibc and all the tools by hand.
  89. Of course, doing so is possible. But dealing with all configure options,
  90. with all problems of every <code>gcc</code> or <code>binutils</code>
  91. version it very time-consuming and uninteresting. Buildroot automates this
  92. process through the use of Makefiles, and has a collection of patches for
  93. each <code>gcc</code> and <code>binutils</code> version to make them work
  94. on most architectures. </p>
  95. <h2><a name="download" id="download"></a>Obtaining Buildroot</h2>
  96. <p>Buildroot is available as daily SVN snapshots or directly using
  97. SVN. </p>
  98. <p>The latest snapshot is always available at <a
  99. href="http://buildroot.uclibc.org/downloads/snapshots/buildroot-snapshot.tar.bz2">http://buildroot.uclibc.org/downloads/snapshots/buildroot-snapshot.tar.bz2</a>,
  100. and previous snapshots are also available at <a
  101. href="http://buildroot.uclibc.org/downloads/snapshots/">http://buildroot.uclibc.org/downloads/snapshots/</a>. </p>
  102. <p>To download Buildroot using SVN, you can simply follow
  103. the rules described on the &quot;Accessing SVN&quot;-page (<a href=
  104. "http://buildroot.uclibc.org/subversion.html">http://buildroot.uclibc.org/subversion.html</a>)
  105. of the uClibc buildroot website (<a href=
  106. "http://buildroot.uclibc.org">http://buildroot.uclibc.org</a>), and download the
  107. <code>buildroot</code> SVN module. For the impatient, here's a quick
  108. recipe:</p>
  109. <pre>
  110. $ svn co svn://uclibc.org/trunk/buildroot
  111. </pre>
  112. <h2><a name="using" id="using"></a>Using Buildroot</h2>
  113. <p>Buildroot has a nice configuration tool similar to the one you can find
  114. in the Linux Kernel (<a href=
  115. "http://www.kernel.org/">http://www.kernel.org/</a>) or in Busybox
  116. (<a href="http://www.busybox.org/">http://www.busybox.org/</a>). Note that
  117. you can build everything as a normal user. There is no need to be root to
  118. configure and use Buildroot. The first step is to run the configuration
  119. assistant:</p>
  120. <pre>
  121. $ make menuconfig
  122. </pre>
  123. <p>For each entry of the configuration tool, you can find associated help
  124. that describes the purpose of the entry. </p>
  125. <p>One of the key configuration items is the <code>PROJECT</code> which
  126. determines where some board specific packages are built and where the
  127. results are stored. </p>
  128. <p>Once everything is configured, the configuration tool has generated a
  129. <code>.config</code> file that contains the description of your
  130. configuration. It will be used by the Makefiles to do what's needed. </p>
  131. <p>Let's go:</p>
  132. <pre>
  133. $ make
  134. </pre>
  135. <p>This command will download, configure and compile all the selected
  136. tools, and finally generate a target filesystem. The target filesystem will
  137. be named <code>root_fs_ARCH.EXT</code> where <code>ARCH</code> is your
  138. architecture and <code>EXT</code> depends on the type of target filesystem
  139. selected in the <code>Target options</code> section of the configuration
  140. tool.
  141. The file is stored in the "binaries/<code>$(PROJECT)</code>/" directory</p>
  142. <h3><a name="local_board_support" id="local_board_support"></a>
  143. Creating your own board support</h3>
  144. <p>Once a package has been unpacked, it is possible to manually update
  145. configuration files. Buildroot can automatically save the configuration
  146. of buildroot, linux, busybox, uclibc and u-boot in "local/$(PROJECT) by
  147. using the command:
  148. </p>
  149. <pre>
  150. $ make saveconfig
  151. </pre>
  152. <p>Once a buildroot configuration has been created by saveconfig,
  153. the default "$(TOPDIR)/.config" file can be overridden by</p>
  154. <pre>
  155. $ make BOARD=&lt;project&gt;
  156. </pre>
  157. <p>Buildroot will then use "local/&lt;project&gt;/&lt;project&gt;.config"
  158. instead of ".config". </p>
  159. <p>If you want to modify your board, you can copy the project configuration
  160. file to ".config" by using the command:</p>
  161. <pre>
  162. $ make BOARD=&lt;project&gt; getconfig
  163. </pre>
  164. <p>You can share your custom board support directory between several buildroot trees
  165. by setting the environment variable <code>BUILDROOT_LOCAL</code> to this directory,
  166. </p>
  167. <h3><a name="offline_builds" id="offline_builds"></a>
  168. Offline builds</h3>
  169. <p>If you intend to do an offline-build and just want to download all
  170. sources that you previously selected in &quot;make menuconfig&quot; then
  171. issue:</p>
  172. <pre>
  173. $ make source
  174. </pre>
  175. <p>You can now disconnect or copy the content of your <code>dl</code>
  176. directory to the build-host. </p>
  177. <h3><a name="building_out_of_tree" id="building_out_of_tree"></a>
  178. Building out-of-tree</h3>
  179. <p>Buildroot supports building out of tree with a syntax similar
  180. to the Linux kernel. To use it, add O=&lt;directory&gt; to the
  181. make command line, E.G.:</p>
  182. <pre>
  183. $ make O=/tmp/build
  184. </pre>
  185. <p>And all the output files will be located under
  186. <code>/tmp/build</code>.</p>
  187. <h3><a name="environment_variables" id="environment_variables"></a>
  188. Environment variables</h3>
  189. <p>Buildroot optionally honors some environment variables that are passed
  190. to <code>make</code> :</p>
  191. <ul>
  192. <li>HOSTCXX</li>
  193. <li>HOSTCC</li>
  194. <li>UCLIBC_CONFIG_FILE=&lt;path/to/.config&gt;</li>
  195. <li>BUSYBOX_CONFIG_FILE=&lt;path/to/.config&gt;</li>
  196. </ul>
  197. <p>An example that uses config files located in the toplevel directory and
  198. in your $HOME:</p>
  199. <pre>
  200. $ make UCLIBC_CONFIG_FILE=uClibc.config BUSYBOX_CONFIG_FILE=$HOME/bb.config
  201. </pre>
  202. <p>If you want to use a compiler other than the default <code>gcc</code>
  203. or <code>g++</code> for building helper-binaries on your host, then do</p>
  204. <pre>
  205. $ make HOSTCXX=g++-4.3-HEAD HOSTCC=gcc-4.3-HEAD
  206. </pre>
  207. <h3><a name="helper_completion" id="helper_completion"></a>
  208. Using auto-completion</h3>
  209. <p>If you are lazy enough that you don't want to type the entire <i>make
  210. menuconfig</i> command line, you can enable auto-completion in your shell.
  211. Here is how you can do that using <i>bash</i>:</p>
  212. <pre>
  213. $ complete -W menuconfig make
  214. </pre>
  215. <p>Then just enter the beginning of the line, and ask <i>bash</i> to
  216. complete it for you by pressing the <i>TAB</i> key:</p>
  217. <pre>
  218. $ make me&lt;TAB&gt;
  219. </pre>
  220. <p>will result in <i>bash</i> to append <i>nuconfig</i> for you!</p>
  221. <p>Alternatively, some distributions (of which Debian and Mandriva are but
  222. an example) have more powerful make completion. Depending on you
  223. distribution, you may have to install a package to enable completion. Under
  224. Mandriva, this is <i>bash-completion</i>, while Debian ships it as part of
  225. the <i>bash</i> package.</p>
  226. <p>Other shells, such as <i>zsh</i>, also have completion facilities. See
  227. the documentation for your shell.</p>
  228. <h2><a name="custom_targetfs" id="custom_targetfs"></a>Customizing the
  229. target filesystem</h2>
  230. <p>There are a few ways to customize the resulting target filesystem:</p>
  231. <ul>
  232. <li>Customize the target filesystem directly, and rebuild the image. The
  233. target filesystem is available under <code>project_build_ARCH/root/</code>
  234. where <code>ARCH</code> is the chosen target architecture.
  235. You can simply make your changes here, and run make afterwards, which will
  236. rebuild the target filesystem image. This method allows to do everything
  237. on the target filesystem, but if you decide to completely rebuild your
  238. toolchain and tools, these changes will be lost. </li>
  239. <li>Customize the target filesystem skeleton, available under
  240. <code>target/generic/target_skeleton/</code>. You can customize
  241. configuration files or other stuff here. However, the full file hierarchy
  242. is not yet present, because it's created during the compilation process.
  243. So you can't do everything on this target filesystem skeleton, but
  244. changes to it remain even if you completely rebuild the cross-compilation
  245. toolchain and the tools. <br />
  246. You can also customize the <code>target/generic/device_table.txt</code>
  247. file which is used by the tools that generate the target filesystem image
  248. to properly set permissions and create device nodes. The
  249. <code>target/generic/skel.tar.gz</code> file contains the main
  250. directories of a root filesystem and there is no obvious reason for which
  251. it should be changed. These main directories are in an tarball inside of
  252. inside the skeleton because it contains symlinks that would be broken
  253. otherwise. <br />
  254. These customizations are deployed into
  255. <code>project_build_ARCH/root/</code> just before the actual image
  256. is made. So simply rebuilding the image by running
  257. make should propagate any new changes to the image. </li>
  258. <li>When configuring the build system, using <code>make menuconfig</code>,
  259. you can specify the contents of the /etc/hostname and /etc/issue
  260. (the welcome banner) in the <code>PROJECT</code> section</li>
  261. </ul>
  262. <h2><a name="custom_busybox" id="custom_busybox"></a>Customizing the
  263. Busybox configuration</h2>
  264. <p><a href="http://www.busybox.net/">Busybox</a> is very configurable, and
  265. you may want to customize it. You can
  266. follow these simple steps to do it. It's not an optimal way, but it's
  267. simple and it works. </p>
  268. <ol>
  269. <li>Make a first compilation of buildroot with busybox without trying to
  270. customize it. </li>
  271. <li>Invoke <code>make busybox-menuconfig</code>.
  272. The nice configuration tool appears and you can
  273. customize everything. </li>
  274. <li>Run the compilation of buildroot again. </li>
  275. </ol>
  276. <p>Otherwise, you can simply change the
  277. <code>package/busybox/busybox-&lt;version&gt;.config</code> file if you
  278. know the options you want to change without using the configuration tool.
  279. </p>
  280. <p>If you want to use an existing config file for busybox, then see
  281. section <a href="#environment_variables">environment variables</a>. </p>
  282. <h2><a name="custom_uclibc" id="custom_uclibc"></a>Customizing the uClibc
  283. configuration</h2>
  284. <p>Just like <a href="#custom_busybox">BusyBox</a>, <a
  285. href="http://www.uclibc.org/">uClibc</a> offers a lot of
  286. configuration options. They allow to select various
  287. functionalities, depending on your needs and limitations. </p>
  288. <p>The easiest way to modify the configuration of uClibc is to
  289. follow these steps :</p>
  290. <ol>
  291. <li>Make a first compilation of buildroot without trying to
  292. customize uClibc. </li>
  293. <li>Invoke <code>make uclibc-menuconfig</code>.
  294. The nice configuration assistant, similar to
  295. the one used in the Linux Kernel or in Buildroot appears. Make
  296. your configuration as appropriate. </li>
  297. <li>Copy the <code>.config</code> file to
  298. <code>toolchain/uClibc/uClibc.config</code> or
  299. <code>toolchain/uClibc/uClibc.config-locale</code>. The former
  300. is used if you haven't selected locale support in Buildroot
  301. configuration, and the latter is used if you have selected
  302. locale support. </li>
  303. <li>Run the compilation of Buildroot again</li>
  304. </ol>
  305. <p>Otherwise, you can simply change
  306. <code>toolchain/uClibc/uClibc.config</code> or
  307. <code>toolchain/uClibc/uClibc.config-locale</code> without running
  308. the configuration assistant. </p>
  309. <p>If you want to use an existing config file for uclibc, then see
  310. section <a href="#environment_variables">environment variables</a>. </p>
  311. <h2><a name="buildroot_innards" id="buildroot_innards"></a>How Buildroot
  312. works</h2>
  313. <p>As said above, Buildroot is basically a set of Makefiles that download,
  314. configure and compiles software with the correct options. It also includes
  315. some patches for various software, mainly the ones involved in the
  316. cross-compilation tool chain (<code>gcc</code>, <code>binutils</code> and
  317. uClibc). </p>
  318. <p>There is basically one Makefile per software, and they are named with
  319. the <code>.mk</code> extension. Makefiles are split into four
  320. sections:</p>
  321. <ul>
  322. <li><b>project</b> (in the <code>project/</code> directory) contains
  323. the Makefiles and associated files for all software related to the
  324. building several root file systems in the same buildroot tree. </li>
  325. <li><b>toolchain</b> (in the <code>toolchain/</code> directory) contains
  326. the Makefiles and associated files for all software related to the
  327. cross-compilation toolchain : <code>binutils</code>, <code>ccache</code>,
  328. <code>gcc</code>, <code>gdb</code>, <code>kernel-headers</code> and
  329. <code>uClibc</code>. </li>
  330. <li><b>package</b> (in the <code>package/</code> directory) contains the
  331. Makefiles and associated files for all user-space tools that Buildroot
  332. can compile and add to the target root filesystem. There is one
  333. sub-directory per tool. </li>
  334. <li><b>target</b> (in the <code>target</code> directory) contains the
  335. Makefiles and associated files for software related to the generation of
  336. the target root filesystem image. Four types of filesystems are supported
  337. : ext2, jffs2, cramfs and squashfs. For each of them, there's a
  338. sub-directory with the required files. There is also a
  339. <code>default/</code> directory that contains the target filesystem
  340. skeleton. </li>
  341. </ul>
  342. <p>Each directory contains at least 2 files :</p>
  343. <ul>
  344. <li><code>something.mk</code> is the Makefile that downloads, configures,
  345. compiles and installs the software <code>something</code>. </li>
  346. <li><code>Config.in</code> is a part of the configuration tool
  347. description file. It describes the option related to the current
  348. software. </li>
  349. </ul>
  350. <p>The main Makefile do the job through the following steps (once the
  351. configuration is done):</p>
  352. <ol>
  353. <li>Create the download directory (<code>dl/</code> by default). This is
  354. where the tarballs will be downloaded. It is interesting to know that the
  355. tarballs are in this directory because it may be useful to save them
  356. somewhere to avoid further downloads. </li>
  357. <li>Create the shared build directory (<code>build_ARCH/</code> by
  358. default, where <code>ARCH</code> is your architecture). This is where all
  359. non configurable user-space tools will be compiled.When building two or
  360. more targets using the same architecture, the first build will go through
  361. the full download, configure, make process, but the second and later
  362. builds will only copy the result from the first build to its project
  363. specific target directory significantly speeding up the build process</li>
  364. <li>Create the project specific build directory
  365. (<code>project_build_ARCH/$(PROJECT)</code> by default, where
  366. <code>ARCH</code> is your architecture). This is where all configurable
  367. user-space tools will be compiled. The project specific build directory
  368. is neccessary, if two different targets needs to use a specific package,
  369. but the packages have different configuration for both targets. Some
  370. examples of packages built in this directory are busybox and linux.
  371. </li>
  372. <li>Create the project specific result directory
  373. (<code>binaries/$(PROJECT)</code> by default, where <code>ARCH</code>
  374. is your architecture). This is where the root filesystem images are
  375. stored, It is also used to store the linux kernel image and any
  376. utilities, boot-loaders etc. needed for a target.
  377. </li>
  378. <li>Create the toolchain build directory
  379. (<code>toolchain_build_ARCH/</code> by default, where <code>ARCH</code>
  380. is your architecture). This is where the cross compilation toolchain will
  381. be compiled. </li>
  382. <li>Setup the staging directory (<code>build_ARCH/staging_dir/</code> by
  383. default). This is where the cross-compilation toolchain will be
  384. installed. If you want to use the same cross-compilation toolchain for
  385. other purposes, such as compiling third-party applications, you can add
  386. <code>build_ARCH/staging_dir/usr/bin</code> to your PATH, and then use
  387. <code>arch-linux-gcc</code> to compile your application. In order to
  388. setup this staging directory, it first removes it, and then it creates
  389. various subdirectories and symlinks inside it. </li>
  390. <li>Create the target directory (<code>project_build_ARCH/root/</code> by
  391. default) and the target filesystem skeleton. This directory will contain
  392. the final root filesystem. To setup it up, it first deletes it, then it
  393. uncompress the <code>target/generic/skel.tar.gz</code> file to create the
  394. main subdirectories and symlinks, copies the skeleton available in
  395. <code>target/generic/target_skeleton</code> and then removes useless
  396. <code>.svn/</code> directories. </li>
  397. <li>Add the <code>TARGETS</code> dependency. This should generally check
  398. if the configuration option for this package is enabled, and if so then
  399. &quot;subscribe&quot; this package to be compiled by adding it to the
  400. TARGETS global variable. </li>
  401. </ol>
  402. <h2><a name="multi_project" id="multi_project"></a>Building several
  403. projects in the same buildroot source tree</h2>
  404. <p><b>BACKGROUND</b></p>
  405. <p>Buildroot has always supported building several projects in the same
  406. tree if each project was for a different architecture. </p>
  407. <p>The root file system has been created in the
  408. <code>&quot;build_&lt;ARCH&gt;/root&quot;</code>
  409. directory which is unique for each architecture.
  410. Toolchains have been built in
  411. <code>&quot;toolchain_build_&lt;ARCH&gt;&quot;</code>. </p>
  412. <p> It the user wanted to build several root file systems for the same
  413. architecture, a prefix or suffix could be added in the configuration file
  414. so the root file system would be built in
  415. <code>&quot;&lt;PREFIX&gt;_build_&lt;ARCH&gt;_&lt;SUFFIX&gt;/root&quot;</code>
  416. By supplying <u>unique</u> combinations of
  417. <code>&quot;&lt;PREFIX&gt;&quot;</code> and
  418. <code>&quot;&lt;SUFFIX&gt;&quot;</code>
  419. each project would get a <u>unique</u> root file system tree. </p>
  420. <p>The disadvantage of this approach is that a new toolchain was
  421. built for each project, adding considerable time to the build
  422. process, even if it was two projects for the same chip. </p>
  423. <p>This drawback has been somewhat lessened with
  424. <code>gcc-4.x.y</code> which allows buildroot to use an external
  425. toolchain. Certain packages requires special
  426. features in the toolchain, and if an external toolchain is selected,
  427. this may lack the neccessary features to complete the build of the root
  428. file system.</p>
  429. <p>A bigger problem was that the
  430. <code>&quot;build_&lt;ARCH&gt;&quot;</code> tree
  431. was also duplicated, so each </code>package</code> would also
  432. be rebuilt once per project, resulting in even longer build times.</p>
  433. <p><b>PROJECT TO SHARE TOOLCHAIN AND PACKAGE BUILDS</b></p>
  434. <p>Work has started on a project which will allow the user to build
  435. multiple root file systems for the same architecture in the same tree.
  436. The toolchain and the package build directory will be shared, but each
  437. project will have a dedicated directory tree for project specific
  438. builds. </p>
  439. <p>With this approach, most, if not all packages will be compiled
  440. when the first project is built.
  441. The process is almost identical to the original process.
  442. Packages are downloaded and extracted to the shared
  443. <code>&quot;build_&lt;ARCH&gt;/&lt;package&gt;&quot;</code>
  444. directory. They are configured and compiled. </p>
  445. <p>Package libraries and headers are installed in the shared $(STAGING_DIR),
  446. and then the project specific root file system &quot;$(TARGET_DIR)&quot;
  447. is populated. </p>
  448. <p>At the end of the build, the root file system will be used
  449. to generate the resulting root file system binaries. </p>
  450. <p>Once the first project has been built, building other projects will
  451. typically involve populating the new project's root file system directory
  452. from the existing binaries generated in the shared
  453. <code>&quot;build_&lt;ARCH&gt;/&lt;&gt;&quot;</code> directory. </p>
  454. <p>Only packages, not used by the first project, will have to go
  455. through the normal extract-configure-compile flow. </p>
  456. <p><b>IMPLEMENTATION</b></p>
  457. <p>The core of the solution is the introduction
  458. of two new directories: </p>
  459. <ul>
  460. <li><code>project_build_&lt;ARCH&gt;</code></li>
  461. <li><code>binaries;</code></li>
  462. </ul>
  463. <p>Each of the directories contain one subdirectory per project.
  464. The name of the subdirectory is configured by the user in the
  465. normal buildroot configuration, using the value of: </p>
  466. <p><code>Project Options ---> Project name</code></p>
  467. <p>The configuration defines the $(PROJECT) variable.</p>
  468. <p>The default project name is <code>&quot;uclibc&quot;</code>.</p>
  469. <p><code>&quot;package/Makefile.in&quot;</code> defines:
  470. <pre>
  471. <code>PROJECT_BUILD_DIR:=project_build_$(ARCH)/$(PROJECT)</code>
  472. <code>BINARIES_DIR:=binaries/$(PROJECT)</code>
  473. </pre>
  474. </p>
  475. <p>It also defines the location for the target root file system:
  476. <pre>
  477. <code>TARGET_DIR:=$(PROJECT_BUILD_DIR)/$(PROJECT)/root</code>
  478. </pre>
  479. </p>
  480. <p>I.E: If the user has choosen
  481. <code>&quot;myproject&quot;</code>
  482. as the $(PROJECT) name:
  483. <ul>
  484. <li><code>&quot;project_build_&lt;ARCH&gt;/myproject&quot;</code></li>
  485. <li><code>&quot;binaries/myproject&quot;</code></li>
  486. </ul>
  487. <p>will be created. </p>
  488. <p>Currently, the <u>root file system</u>, <u>busybox</u> and an Atmel
  489. customized version of
  490. <u><code>U-Boot</code></u>, as well as some Atmel specific
  491. bootloaders like <u>at91-bootstrap</u> and <u>dataflashboot.bin</u>
  492. are built in
  493. <code>&quot;$(PROJECT_BUILD_DIR)&quot;</code>
  494. <p>The resulting binaries for all architectures are stored in the
  495. <code>&quot;$(BINARIES_DIR)&quot;</code> directory. <p>
  496. <p><b>SUMMARY</b></p>
  497. <p>The project will share directories which can be share without
  498. conflicts, but will use unique build directories, where the user
  499. can configure the build. </p>
  500. <p><b>THINGS TO DO</b></p>
  501. <ol>
  502. <li>Linux</li>
  503. <p>The current Linux implementation is flawed. It only works
  504. if the user chooses to use one of the few kernels selected
  505. as base for the kernel-headers. While the Makefile seems to have
  506. hooks, allowing the developer to specify whatever version he/she
  507. wants in the target/device/*/* Makefiles, the build will fail
  508. if another kernel version is choosen.</p>
  509. <p>The reason for this is that the kernel patches are not
  510. applied by the <code>&quot;target/linux/linux.mk&quot;</code>
  511. build script fragment. They are only applied by the
  512. <code>&quot;toolchain/kernel-headers/*.makefile&quot;</code>
  513. build script fragments</p>
  514. <p>If the kernel-header version and the linux version differs,
  515. there will be two <code>&quot;linux-2.6.X.Y&quot;</code>
  516. directories in
  517. <code>&quot;build_&lt;ARCH&gt;/&lt;&gt;&quot;</code>,
  518. each with its own set of patches. </p>
  519. <p>The solution in the works, is to move the build of Linux to
  520. <code>&quot;project_build_&lt;ARCH&gt;/&lt;project name&gt;/linux-2.6.X.Y&quot;</code> combined with method to configure
  521. which patches can be applied. Possibly, the linux source tree
  522. used to generate the kernel headers will be moved to the
  523. <code>&quot;toolchain_build_&lt;ARCH&gt;&quot;</code>
  524. directory
  525. </p>
  526. <p>The user will be able to select from three different
  527. Linux strategies:
  528. <ul>
  529. <li>Conservative Strategy: Only use version ssupported by the kernel headers</li>
  530. <li>Stable Linux Strategy: Allow any 2.6.X.Y combination.
  531. (Minimum 2.6.19)</li>
  532. <li>Power-User Strategy: Allow
  533. <code>&quot;-git&quot;</code>, or
  534. <code>&quot;-mm&quot;</code>, or user downloadable kernels</li>
  535. </ul>
  536. <p>The current kernel patches can be configured to be applied to the
  537. linux source tree even if the version differs from the
  538. kernel header version. </p>
  539. <p>Since the user can select any kernel-patch
  540. he/she will be able to select a non-working combination.
  541. If the patch fails, the user will have to generate a new
  542. proprietary kernel-patch or decide to not apply the kernel
  543. patches</p>
  544. <p>Other optional patches will be <u>board specific</u> or
  545. <u>architecture specific</u> patches. </p>
  546. <p>There will also be a way for the user to supply absolute
  547. or relative paths to patches, possibly outside the main tree.
  548. This can be used to apply custom kernel-header-patches, if
  549. the versions available in buildroot cannot be applied to the
  550. specific linux version used</p>
  551. <p>Maybe, there will also be a possibility to supply an
  552. <code>&quot;URL&quot;</code> to a patch available on Internet. </p>
  553. <li>Configurable packages</li>
  554. <p>Many packages can, on top of the simple
  555. &quot;enable/disable build&quot;,
  556. be further configured using Kconfig.
  557. Currently these packages will be compiled using the
  558. configuration specified in the
  559. <code>&quot;.config&quot;</code> file of the <u>first</u>
  560. project demanding the build of the package.</p>
  561. <p>If <u>another</u> project uses the same packages, but with
  562. a different configuration,these packages will <u>not</u> be rebuilt,
  563. and the root file system for the new project will be populated
  564. with files from the build of the <u>first</u> project</p>
  565. <p>If multiple project are built, and a specific package
  566. needs two different configuration, then the user must
  567. delete the package from the
  568. <code>&quot;build_&lt;ARCH&gt;&quot;</code> directory
  569. before rebuilding the new project.<p>
  570. <p>A long term solution is to edit the package makefile and move
  571. the build of the configurable packages from
  572. <code>&quot;build_&lt;ARCH&gt;&quot;</code> to
  573. <code>&quot;project_build_&lt;ARCH&gt;/&lt;project name&gt;&quot;</code>
  574. and send a patch to the buildroot mailing list.
  575. <li>Naming conventions</li>
  576. <p>Names of resulting binaries should reflect the
  577. &quot;project name&quot;
  578. <li>Generating File System binaries</li>
  579. <p>
  580. Packages which needs to be installed with the &quot;root&quot;
  581. as owner, will generate a
  582. <code>&quot;.fakeroot.&lt;package&gt;&quot;</code> file
  583. which will be used for the final build of the root file system binary. </p>
  584. <p>This was previously located in the
  585. <code>&quot;$(STAGING_DIR)&quot;</code> directory, but was
  586. recently moved to the
  587. <code>&quot;$(PROJECT_BUILD_DIR)&quot;</code> directory. </p>
  588. <p>Currently only three packages:
  589. <code>&quot;at&quot;</code>,
  590. <code>&quot;ltp-testsuite&quot;</code> and
  591. <code>&quot;nfs-utils&quot;</code>
  592. requests fakeroot. <p>
  593. <p>The makefile fragments for each file system type like
  594. <code>&quot;ext2&quot;</code>,
  595. <code>&quot;jffs2&quot;</code> or
  596. <code>&quot;squashfs&quot;</code>
  597. will, when the file system binary is generated,
  598. collect all present
  599. <code>&quot;.fakeroot.&lt;package&gt;&quot;</code> files
  600. to a single <code>&quot;_fakeroot.&lt;file system&gt;&quot;</code>
  601. file and call fakeroot.</p>
  602. <code>&quot;.fakeroot.&lt;package&gt;&quot;</code>
  603. files are deleted as the last action of the Buildroot Makefile. </p>
  604. <p>It needs to be evaluated if any further action for the
  605. file system binary build is needed. </p>
  606. </ol>
  607. <h2><a name="using_toolchain" id="using_toolchain"></a>Using the
  608. uClibc toolchain</h2>
  609. <p>You may want to compile your own programs or other software
  610. that are not packaged in Buildroot. In order to do this, you can
  611. use the toolchain that was generated by Buildroot. </p>
  612. <p>The toolchain generated by Buildroot by default is located in
  613. <code>build_ARCH/staging_dir/</code>. The simplest way to use it
  614. is to add <code>build_ARCH/staging_dir/usr/bin/</code> to your PATH
  615. environnement variable, and then to use
  616. <code>arch-linux-gcc</code>, <code>arch-linux-objdump</code>,
  617. <code>arch-linux-ld</code>, etc. </p>
  618. <p>For example, you may add the following to your
  619. <code>.bashrc</code> (considering you're building for the MIPS
  620. architecture and that Buildroot is located in
  621. <code>~/buildroot/</code>) :</p>
  622. <pre>
  623. export PATH=&quot;$PATH:~/buildroot/build_mips/staging_dir/usr/bin/&quot;
  624. </pre>
  625. <p>Then you can simply do :</p>
  626. <pre>
  627. mips-linux-gcc -o foo foo.c
  628. </pre>
  629. <p><b>Important</b> : do not try to move a gcc-3.x toolchain to an other
  630. directory, it won't work. There are some hardcoded paths in the
  631. <i>gcc</i> configuration. If the default toolchain directory
  632. doesn't suit your needs, please refer to the <a
  633. href="#toolchain_standalone">Using the uClibc toolchain outside of
  634. buildroot</a> section. </p>
  635. <p>If you are using a current gcc-4.x, then use --sysroot and -isysroot
  636. since these toolchains have fully functional sysroot support. No
  637. hardcoded paths do exist in these configurations. </p>
  638. <h2><a name="toolchain_standalone" id="toolchain_standalone"></a>Using the
  639. uClibc toolchain outside of buildroot</h2>
  640. <p>By default, the cross-compilation toolchain is generated inside
  641. <code>build_ARCH/staging_dir/</code>. But sometimes, it may be useful to
  642. install it somewhere else, so that it can be used to compile other programs
  643. or by other users. Moving the <code>build_ARCH/staging_dir/</code>
  644. directory elsewhere is <b>not possible if using gcc-3.x</b>, because there
  645. are some hardcoded paths in the toolchain configuration. This works, thanks
  646. to sysroot support, with current, stable gcc-4.x toolchains, of course. </p>
  647. <p>If you want to use the generated gcc-3.x toolchain for other purposes,
  648. you can configure Buildroot to generate it elsewhere using the
  649. option of the configuration tool : <code>Build options -&gt;
  650. Toolchain and header file location</code>, which defaults to
  651. <code>$(BUILD_DIR)/staging_dir/</code>. </p>
  652. <h2><a name="downloaded_packages"
  653. id="downloaded_packages"></a>Location of downloaded packages</h2>
  654. <p>It might be useful to know that the various tarballs that are
  655. downloaded by the <i>Makefiles</i> are all stored in the
  656. <code>DL_DIR</code> which by default is the <code>dl</code>
  657. directory. It's useful for example if you want to keep a complete
  658. version of Buildroot which is know to be working with the
  659. associated tarballs. This will allow you to regenerate the
  660. toolchain and the target filesystem with exactly the same
  661. versions. </p>
  662. <p>If you maintain several buildroot trees, it might be better to have
  663. a shared download location. This can be accessed by creating a symbolic link
  664. from the <code>dl</code> directory to the shared download location. </p>
  665. <p>I.E:</p>
  666. <pre>
  667. ln -s &lt;shared download location&gt; dl
  668. </pre>
  669. <p>Another way of accessing a shared download location is to
  670. create the <code>BUILDROOT_DL_DIR</code> environment variable.
  671. If this is set, then the value of DL_DIR in the project is
  672. overridden. The following line should be added to
  673. <code>&quot;~/.bashrc&quot;</code>. <p>
  674. <pre>
  675. export BUILDROOT_DL_DIR &lt;shared download location&gt;
  676. </pre>
  677. <h2><a name="add_software" id="add_software"></a>Extending Buildroot with
  678. more software</h2>
  679. <p>This section will only consider the case in which you want to
  680. add user-space software. </p>
  681. <h3>Package directory</h3>
  682. <p>First of all, create a directory under the <code>package</code>
  683. directory for your software, for example <code>foo</code>. </p>
  684. <h3><code>Config.in</code> file</h3>
  685. <p>Then, create a file named <code>Config.in</code>. This file
  686. will contain the portion of options description related to our
  687. <code>foo</code> software that will be used and displayed in the
  688. configuration tool. It should basically contain :</p>
  689. <pre>
  690. config BR2_PACKAGE_FOO
  691. bool "foo"
  692. help
  693. This is a comment that explains what foo is.
  694. http://foosoftware.org/foo/
  695. </pre>
  696. <p>Of course, you can add other options to configure particular
  697. things in your software. </p>
  698. <p>Finally you have to add your new <code>foo/Config.in</code> to
  699. <code>package/Config.in</code>. The files included there are
  700. <em>sorted alphabetically</em> per category and are <em>NOT<em>
  701. supposed to contain anything but the <em>bare</em> name of the package.</p>
  702. <pre>
  703. if !BR2_PACKAGE_BUSYBOX_HIDE_OTHERS
  704. source "package/procps/Config.in"
  705. endif
  706. </pre>
  707. <p><strong>Note:</strong><br>
  708. Generally all packages should live <em>directly</em> in the
  709. <code>package</code> directory to make it easier to find them.
  710. </p>
  711. <h3>The real <i>Makefile</i></h3>
  712. <p>Finally, here's the hardest part. Create a file named
  713. <code>foo.mk</code>. It will contain the <i>Makefile</i> rules that
  714. are in charge of downloading, configuring, compiling and installing
  715. the software. Below is an example that we will comment
  716. afterwards. </p>
  717. <pre>
  718. <a name="line1" id="line1">1</a> #############################################################
  719. <a name="line2" id="line2">2</a> #
  720. <a name="line3" id="line3">3</a> # foo
  721. <a name="line4" id="line4">4</a> #
  722. <a name="line5" id="line5">5</a> #############################################################
  723. <a name="line6" id="line6">6</a> FOO_VERSION:=1.0
  724. <a name="line7" id="line7">7</a> FOO_SOURCE:=foo-$(FOO_VERSION).tar.gz
  725. <a name="line8" id="line8">8</a> FOO_SITE:=http://www.foosoftware.org/downloads
  726. <a name="line9" id="line9">9</a> FOO_DIR:=$(BUILD_DIR)/foo-$(FOO_VERSION)
  727. <a name="line10" id="line10">10</a> FOO_BINARY:=foo
  728. <a name="line11" id="line11">11</a> FOO_TARGET_BINARY:=usr/bin/foo
  729. <a name="line12" id="line12">12</a>
  730. <a name="line13" id="line13">13</a> $(DL_DIR)/$(FOO_SOURCE):
  731. <a name="line14" id="line14">14</a> $(WGET) -P $(DL_DIR) $(FOO_SITE)/$(FOO_SOURCE)
  732. <a name="line15" id="line15">15</a>
  733. <a name="line16" id="line16">16</a> $(FOO_DIR)/.source: $(DL_DIR)/$(FOO_SOURCE)
  734. <a name="line17" id="line17">17</a> $(ZCAT) $(DL_DIR)/$(FOO_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
  735. <a name="line18" id="line18">18</a> touch $@
  736. <a name="line19" id="line19">19</a>
  737. <a name="line20" id="line20">20</a> $(FOO_DIR)/.configured: $(FOO_DIR)/.source
  738. <a name="line21" id="line21">21</a> (cd $(FOO_DIR); rm -rf config.cache; \
  739. <a name="line22" id="line22">22</a> $(TARGET_CONFIGURE_OPTS) \
  740. <a name="line23" id="line23">23</a> $(TARGET_CONFIGURE_ARGS) \
  741. <a name="line24" id="line24">24</a> ./configure \
  742. <a name="line25" id="line25">25</a> --target=$(GNU_TARGET_NAME) \
  743. <a name="line26" id="line26">26</a> --host=$(GNU_TARGET_NAME) \
  744. <a name="line27" id="line27">27</a> --build=$(GNU_HOST_NAME) \
  745. <a name="line28" id="line28">28</a> --prefix=/usr \
  746. <a name="line29" id="line29">29</a> --sysconfdir=/etc \
  747. <a name="line30" id="line30">30</a> )
  748. <a name="line31" id="line31">31</a> touch $@
  749. <a name="line32" id="line32">32</a>
  750. <a name="line33" id="line33">33</a> $(FOO_DIR)/$(FOO_BINARY): $(FOO_DIR)/.configured
  751. <a name="line34" id="line34">34</a> $(MAKE) CC=$(TARGET_CC) -C $(FOO_DIR)
  752. <a name="line35" id="line35">35</a>
  753. <a name="line36" id="line36">36</a> $(TARGET_DIR)/$(FOO_TARGET_BINARY): $(FOO_DIR)/$(FOO_BINARY)
  754. <a name="line37" id="line37">37</a> $(MAKE) prefix=$(TARGET_DIR)/usr -C $(FOO_DIR) install
  755. <a name="line38" id="line38">38</a> rm -Rf $(TARGET_DIR)/usr/man
  756. <a name="line39" id="line39">39</a>
  757. <a name="line40" id="line40">40</a> foo: uclibc ncurses $(TARGET_DIR)/$(FOO_TARGET_BINARY)
  758. <a name="line41" id="line41">41</a>
  759. <a name="line42" id="line42">42</a> foo-source: $(DL_DIR)/$(FOO_SOURCE)
  760. <a name="line43" id="line43">43</a>
  761. <a name="line44" id="line44">44</a> foo-clean:
  762. <a name="line45" id="line45">45</a> $(MAKE) prefix=$(TARGET_DIR)/usr -C $(FOO_DIR) uninstall
  763. <a name="line46" id="line46">46</a> -$(MAKE) -C $(FOO_DIR) clean
  764. <a name="line47" id="line47">47</a>
  765. <a name="line48" id="line48">48</a> foo-dirclean:
  766. <a name="line49" id="line49">49</a> rm -rf $(FOO_DIR)
  767. <a name="line50" id="line50">50</a>
  768. <a name="line51" id="line51">51</a> #############################################################
  769. <a name="line52" id="line52">52</a> #
  770. <a name="line53" id="line53">53</a> # Toplevel Makefile options
  771. <a name="line54" id="line54">54</a> #
  772. <a name="line55" id="line55">55</a> #############################################################
  773. <a name="line56" id="line56">56</a> ifeq ($(BR2_PACKAGE_FOO),y)
  774. <a name="line57" id="line57">57</a> TARGETS+=foo
  775. <a name="line58" id="line58">58</a> endif
  776. </pre>
  777. <p>First of all, this <i>Makefile</i> example works for a single
  778. binary software. For other software such as libraries or more
  779. complex stuff with multiple binaries, it should be adapted. Look at
  780. the other <code>*.mk</code> files in the <code>package</code>
  781. directory. </p>
  782. <p>At lines <a href="#line6">6-11</a>, a couple of useful variables are
  783. defined :</p>
  784. <ul>
  785. <li><code>FOO_VERSION</code> : The version of <i>foo</i> that
  786. should be downloaded. </li>
  787. <li><code>FOO_SOURCE</code> : The name of the tarball of
  788. <i>foo</i> on the download website of FTP site. As you can see
  789. <code>FOO_VERSION</code> is used. </li>
  790. <li><code>FOO_SITE</code> : The HTTP or FTP site from which
  791. <i>foo</i> archive is downloaded. It must include the complete
  792. path to the directory where <code>FOO_SOURCE</code> can be
  793. found. </li>
  794. <li><code>FOO_DIR</code> : The directory into which the software
  795. will be configured and compiled. Basically, it's a subdirectory
  796. of <code>BUILD_DIR</code> which is created upon decompression of
  797. the tarball. </li>
  798. <li><code>FOO_BINARY</code> : Software binary name. As said
  799. previously, this is an example for a single binary software. </li>
  800. <li><code>FOO_TARGET_BINARY</code> : The full path of the binary
  801. inside the target filesystem. </li>
  802. </ul>
  803. <p>Lines <a href="#line13">13-14</a> defines a target that downloads the
  804. tarball from the remote site to the download directory
  805. (<code>DL_DIR</code>). </p>
  806. <p>Lines <a href="#line16">16-18</a> defines a target and associated rules
  807. that uncompress the downloaded tarball. As you can see, this target
  808. depends on the tarball file, so that the previous target (line
  809. <a href="#line13">13-14</a>) is called before executing the rules of the
  810. current target. Uncompressing is followed by <i>touching</i> a hidden file
  811. to mark the software has having been uncompressed. This trick is
  812. used everywhere in Buildroot <i>Makefile</i> to split steps
  813. (download, uncompress, configure, compile, install) while still
  814. having correct dependencies. </p>
  815. <p>Lines <a href="#line20">20-31</a> defines a target and associated rules
  816. that configures the software. It depends on the previous target (the
  817. hidden <code>.source</code> file) so that we are sure the software has
  818. been uncompressed. In order to configure it, it basically runs the
  819. well-known <code>./configure</code> script. As we may be doing
  820. cross-compilation, <code>target</code>, <code>host</code> and
  821. <code>build</code> arguments are given. The prefix is also set to
  822. <code>/usr</code>, not because the software will be installed in
  823. <code>/usr</code> on your host system, but in the target
  824. filesystem. Finally it creates a <code>.configured</code> file to
  825. mark the software as configured. </p>
  826. <p>Lines <a href="#line33">33-34</a> defines a target and a rule that
  827. compiles the software. This target will create the binary file in the
  828. compilation directory, and depends on the software being already
  829. configured (hence the reference to the <code>.configured</code>
  830. file). It basically runs <code>make</code> inside the source
  831. directory. </p>
  832. <p>Lines <a href="#line36">36-38</a> defines a target and associated rules
  833. that install the software inside the target filesystem. It depends on the
  834. binary file in the source directory, to make sure the software has
  835. been compiled. It uses the <code>install</code> target of the
  836. software <code>Makefile</code> by passing a <code>prefix</code>
  837. argument, so that the <code>Makefile</code> doesn't try to install
  838. the software inside host <code>/usr</code> but inside target
  839. <code>/usr</code>. After the installation, the
  840. <code>/usr/man</code> directory inside the target filesystem is
  841. removed to save space. </p>
  842. <p>Line <a href="#line40">40</a> defines the main target of the software,
  843. the one that will be eventually be used by the top level
  844. <code>Makefile</code> to download, compile, and then install
  845. this package. This target should first of all depends on all
  846. needed dependecies of the software (in our example,
  847. <i>uclibc</i> and <i>ncurses</i>), and also depend on the
  848. final binary. This last dependency will call all previous
  849. dependencies in the correct order. </p>
  850. <p>Line <a href="#line42">42</a> defines a simple target that only
  851. downloads the code source. This is not used during normal operation of
  852. Buildroot, but is needed if you intend to download all required sources at
  853. once for later offline build. Note that if you add a new package providing
  854. a <code>foo-source</code> target is <i>mandatory</i> to support
  855. users that wish to do offline-builds. Furthermore it eases checking
  856. if all package-sources are downloadable. </p>
  857. <p>Lines <a href="#line44">44-46</a> define a simple target to clean the
  858. software build by calling the <i>Makefiles</i> with the appropriate option.
  859. The <code>-clean</code> target should run <code>make clean</code>
  860. on $(BUILD_DIR)/package-version and MUST uninstall all files of the
  861. package from $(STAGING_DIR) and from $(TARGET_DIR). </p>
  862. <p>Lines <a href="#line48">48-49</a> define a simple target to completely
  863. remove the directory in which the software was uncompressed, configured and
  864. compiled. The <code>-dirclean</code> target MUST completely rm $(BUILD_DIR)/
  865. package-version. </p>
  866. <p>Lines <a href="#line51">51-58</a> adds the target <code>foo</code> to
  867. the list of targets to be compiled by Buildroot by first checking if
  868. the configuration option for this package has been enabled
  869. using the configuration tool, and if so then &quot;subscribes&quot;
  870. this package to be compiled by adding it to the TARGETS
  871. global variable. The name added to the TARGETS global
  872. variable is the name of this package's target, as defined on
  873. line <a href="#line40">40</a>, which is used by Buildroot to download,
  874. compile, and then install this package. </p>
  875. <h3>Conclusion</h3>
  876. <p>As you can see, adding a software to buildroot is simply a
  877. matter of writing a <i>Makefile</i> using an already existing
  878. example and to modify it according to the compilation process of
  879. the software. </p>
  880. <p>If you package software that might be useful for other persons,
  881. don't forget to send a patch to Buildroot developers !</p>
  882. <h2><a name="links" id="links"></a>Resources</h2>
  883. <p>To learn more about Buildroot you can visit these
  884. websites:</p>
  885. <ul>
  886. <li><a href="http://www.uclibc.org/">http://www.uclibc.org/</a></li>
  887. <li><a href="http://www.busybox.net/">http://www.busybox.net/</a></li>
  888. </ul>
  889. </div>
  890. <!--
  891. <a href="http://validator.w3.org/check?uri=referer"><img
  892. border="0" height="31" width="88"
  893. src="images/valid-html401.png"
  894. alt="Valid HTML"></img></a>
  895. -->
  896. </body>
  897. </html>