buildroot.html 53 KB

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