buildroot.html 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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. <p>If you intend to do an offline-build and just want to download all
  143. sources that you previously selected in &quot;make menuconfig&quot; then
  144. issue:</p>
  145. <pre>
  146. $ make source
  147. </pre>
  148. <p>You can now disconnect or copy the content of your <code>dl</code>
  149. directory to the build-host. </p>
  150. <h3><a name="environment_variables" id="environment_variables"></a>
  151. Environment variables</h3>
  152. <p>Buildroot optionally honors some environment variables that are passed
  153. to <code>make</code> :</p>
  154. <ul>
  155. <li>HOSTCXX</li>
  156. <li>HOSTCC</li>
  157. <li>UCLIBC_CONFIG_FILE=&lt;path/to/.config&gt;</li>
  158. <li>BUSYBOX_CONFIG_FILE=&lt;path/to/.config&gt;</li>
  159. </ul>
  160. <p>An example that uses config files located in the toplevel directory and
  161. in your $HOME:</p>
  162. <pre>
  163. $ make UCLIBC_CONFIG_FILE=uClibc.config BUSYBOX_CONFIG_FILE=$HOME/bb.config
  164. </pre>
  165. <p>If you want to use a compiler other than the default <code>gcc</code>
  166. or <code>g++</code> for building helper-binaries on your host, then do</p>
  167. <pre>
  168. $ make HOSTCXX=g++-4.3-HEAD HOSTCC=gcc-4.3-HEAD
  169. </pre>
  170. <h3><a name="helper_completion" id="helper_completion"></a>
  171. Using auto-completion</h3>
  172. <p>If you are lazy enough that you don't want to type the entire <i>make
  173. menuconfig</i> command line, you can enable auto-completion in your shell.
  174. Here is how you can do that using <i>bash</i>:</p>
  175. <pre>
  176. $ complete -W menuconfig make
  177. </pre>
  178. <p>Then just enter the begining of the line, and ask <i>bash</i> to
  179. complete it for you by pressing the <i>TAB</i> key:</p>
  180. <pre>
  181. $ make me&lt;TAB&gt;
  182. </pre>
  183. <p>will result in <i>bash</i> to append <i>nuconfig</i> for you!</p>
  184. <p>Alternatively, some distributions (of which Debian and Mandriva are but
  185. an example) have more powerful make completion. Depending on you
  186. distribution, you may have to install a package to enable completion. Under
  187. Mandriva, this is <i>bash-completion</i>, while Debian ships it as part of
  188. the <i>bash</i> package.</p>
  189. <p>Other shells, such as <i>zsh</i>, also have completion facilities. See
  190. the documentation for your shell.</p>
  191. <h2><a name="custom_targetfs" id="custom_targetfs"></a>Customizing the
  192. target filesystem</h2>
  193. <p>There are a few ways to customize the resulting target filesystem:</p>
  194. <ul>
  195. <li>Customize the target filesystem directly, and rebuild the image. The
  196. target filesystem is available under <code>project_build_ARCH/root/</code>
  197. where <code>ARCH</code> is the chosen target architecture.
  198. You can simply make your changes here, and run make afterwards, which will
  199. rebuild the target filesystem image. This method allows to do everything
  200. on the target filesystem, but if you decide to completely rebuild your
  201. toolchain and tools, these changes will be lost. </li>
  202. <li>Customize the target filesystem skeleton, available under
  203. <code>target/generic/target_skeleton/</code>. You can customize
  204. configuration files or other stuff here. However, the full file hierarchy
  205. is not yet present, because it's created during the compilation process.
  206. So you can't do everything on this target filesystem skeleton, but
  207. changes to it remain even if you completely rebuild the cross-compilation
  208. toolchain and the tools. <br />
  209. You can also customize the <code>target/generic/device_table.txt</code>
  210. file which is used by the tools that generate the target filesystem image
  211. to properly set permissions and create device nodes. The
  212. <code>target/generic/skel.tar.gz</code> file contains the main
  213. directories of a root filesystem and there is no obvious reason for which
  214. it should be changed. These main directories are in an tarball inside of
  215. inside the skeleton because it contains symlinks that would be broken
  216. otherwise. <br />
  217. These customizations are deployed into
  218. <code>project_build_ARCH/root/</code> just before the actual image
  219. is made. So simply rebuilding the image by running
  220. make should propagate any new changes to the image. </li>
  221. <li>When configuring the build system, using <code>make menuconfig</code>,
  222. you can specify the contents of the /etc/hostname and /etc/issue
  223. (the welcome banner) in the <code>PROJECT</code> section</li>
  224. </ul>
  225. <h2><a name="custom_busybox" id="custom_busybox"></a>Customizing the
  226. Busybox configuration</h2>
  227. <p><a href="http://www.busybox.net/">Busybox</a> is very configurable, and
  228. you may want to customize it. You can
  229. follow these simple steps to do it. It's not an optimal way, but it's
  230. simple and it works. </p>
  231. <ol>
  232. <li>Make a first compilation of buildroot with busybox without trying to
  233. customize it. </li>
  234. <li>Invoke <code>make busybox-menuconfig</code>.
  235. The nice configuration tool appears and you can
  236. customize everything. </li>
  237. <li>Run the compilation of buildroot again. </li>
  238. </ol>
  239. <p>Otherwise, you can simply change the
  240. <code>package/busybox/busybox-&lt;version&gt;.config</code> file if you
  241. know the options you want to change without using the configuration tool.
  242. </p>
  243. <p>If you want to use an existing config file for busybox, then see
  244. section <a href="#environment_variables">environment variables</a>. </p>
  245. <h2><a name="custom_uclibc" id="custom_uclibc"></a>Customizing the uClibc
  246. configuration</h2>
  247. <p>Just like <a href="#custom_busybox">BusyBox</a>, <a
  248. href="http://www.uclibc.org/">uClibc</a> offers a lot of
  249. configuration options. They allow to select various
  250. functionalities, depending on your needs and limitations. </p>
  251. <p>The easiest way to modify the configuration of uClibc is to
  252. follow these steps :</p>
  253. <ol>
  254. <li>Make a first compilation of buildroot without trying to
  255. customize uClibc. </li>
  256. <li>Invoke <code>make uclibc-menuconfig</code>.
  257. The nice configuration assistant, similar to
  258. the one used in the Linux Kernel or in Buildroot appears. Make
  259. your configuration as appropriate. </li>
  260. <li>Copy the <code>.config</code> file to
  261. <code>toolchain/uClibc/uClibc.config</code> or
  262. <code>toolchain/uClibc/uClibc.config-locale</code>. The former
  263. is used if you haven't selected locale support in Buildroot
  264. configuration, and the latter is used if you have selected
  265. locale support. </li>
  266. <li>Run the compilation of Buildroot again</li>
  267. </ol>
  268. <p>Otherwise, you can simply change
  269. <code>toolchain/uClibc/uClibc.config</code> or
  270. <code>toolchain/uClibc/uClibc.config-locale</code> without running
  271. the configuration assistant. </p>
  272. <p>If you want to use an existing config file for uclibc, then see
  273. section <a href="#environment_variables">environment variables</a>. </p>
  274. <h2><a name="buildroot_innards" id="buildroot_innards"></a>How Buildroot
  275. works</h2>
  276. <p>As said above, Buildroot is basically a set of Makefiles that download,
  277. configure and compiles software with the correct options. It also includes
  278. some patches for various software, mainly the ones involved in the
  279. cross-compilation tool chain (<code>gcc</code>, <code>binutils</code> and
  280. uClibc). </p>
  281. <p>There is basically one Makefile per software, and they are named with
  282. the <code>.mk</code> extension. Makefiles are split into three
  283. sections:</p>
  284. <ul>
  285. <li><b>package</b> (in the <code>package/</code> directory) contains the
  286. Makefiles and associated files for all user-space tools that Buildroot
  287. can compile and add to the target root filesystem. There is one
  288. sub-directory per tool. </li>
  289. <li><b>toolchain</b> (in the <code>toolchain/</code> directory) contains
  290. the Makefiles and associated files for all software related to the
  291. cross-compilation toolchain : <code>binutils</code>, <code>ccache</code>,
  292. <code>gcc</code>, <code>gdb</code>, <code>kernel-headers</code> and
  293. <code>uClibc</code>. </li>
  294. <li><b>target</b> (in the <code>target</code> directory) contains the
  295. Makefiles and associated files for software related to the generation of
  296. the target root filesystem image. Four types of filesystems are supported
  297. : ext2, jffs2, cramfs and squashfs. For each of them, there's a
  298. sub-directory with the required files. There is also a
  299. <code>default/</code> directory that contains the target filesystem
  300. skeleton. </li>
  301. </ul>
  302. <p>Each directory contains at least 2 files :</p>
  303. <ul>
  304. <li><code>something.mk</code> is the Makefile that downloads, configures,
  305. compiles and installs the software <code>something</code>. </li>
  306. <li><code>Config.in</code> is a part of the configuration tool
  307. description file. It describes the option related to the current
  308. software. </li>
  309. </ul>
  310. <p>The main Makefile do the job through the following steps (once the
  311. configuration is done):</p>
  312. <ol>
  313. <li>Create the download directory (<code>dl/</code> by default). This is
  314. where the tarballs will be downloaded. It is interesting to know that the
  315. tarballs are in this directory because it may be useful to save them
  316. somewhere to avoid further downloads. </li>
  317. <li>Create the shared build directory (<code>build_ARCH/</code> by
  318. default, where <code>ARCH</code> is your architecture). This is where all
  319. non configurable user-space tools will be compiled.When building two or
  320. more targets using the same architecture, the first build will go through
  321. the full download, configure, make process, but the second and later
  322. builds will only copy the result from the first build to its project
  323. specific target directory significantly speeding up the build process</li>
  324. <li>Create the project specific build directory
  325. (<code>project_build_ARCH/$(PROJECT)</code> by default, where
  326. <code>ARCH</code> is your architecture). This is where all configurable
  327. user-space tools will be compiled. The project specific build directory
  328. is neccessary, if two different targets needs to use a specific package,
  329. but the packages have different configuration for both targets. Some
  330. examples of packages built in this directory are busybox and linux.
  331. </li>
  332. <li>Create the project specific result directory
  333. (<code>binaries/$(PROJECT)</code> by default, where <code>ARCH</code>
  334. is your architecture). This is where the root filesystem images are
  335. stored, It is also used to store the linux kernel image and any
  336. utilities, boot-loaders etc. needed for a target.
  337. </li>
  338. <li>Create the toolchain build directory
  339. (<code>toolchain_build_ARCH/</code> by default, where <code>ARCH</code>
  340. is your architecture). This is where the cross compilation toolchain will
  341. be compiled. </li>
  342. <li>Setup the staging directory (<code>build_ARCH/staging_dir/</code> by
  343. default). This is where the cross-compilation toolchain will be
  344. installed. If you want to use the same cross-compilation toolchain for
  345. other purposes, such as compiling third-party applications, you can add
  346. <code>build_ARCH/staging_dir/usr/bin</code> to your PATH, and then use
  347. <code>arch-linux-gcc</code> to compile your application. In order to
  348. setup this staging directory, it first removes it, and then it creates
  349. various subdirectories and symlinks inside it. </li>
  350. <li>Create the target directory (<code>project_build_ARCH/root/</code> by
  351. default) and the target filesystem skeleton. This directory will contain
  352. the final root filesystem. To setup it up, it first deletes it, then it
  353. uncompress the <code>target/generic/skel.tar.gz</code> file to create the
  354. main subdirectories and symlinks, copies the skeleton available in
  355. <code>target/generic/target_skeleton</code> and then removes useless
  356. <code>.svn/</code> directories. </li>
  357. <li>Add the <code>TARGETS</code> dependency. This should generally check
  358. if the configuration option for this package is enabled, and if so then
  359. &quot;subscribe&quot; this package to be compiled by adding it to the
  360. TARGETS global variable. </li>
  361. </ol>
  362. <h2><a name="using_toolchain" id="using_toolchain"></a>Using the
  363. uClibc toolchain</h2>
  364. <p>You may want to compile your own programs or other software
  365. that are not packaged in Buildroot. In order to do this, you can
  366. use the toolchain that was generated by Buildroot. </p>
  367. <p>The toolchain generated by Buildroot by default is located in
  368. <code>build_ARCH/staging_dir/</code>. The simplest way to use it
  369. is to add <code>build_ARCH/staging_dir/usr/bin/</code> to your PATH
  370. environnement variable, and then to use
  371. <code>arch-linux-gcc</code>, <code>arch-linux-objdump</code>,
  372. <code>arch-linux-ld</code>, etc. </p>
  373. <p>For example, you may add the following to your
  374. <code>.bashrc</code> (considering you're building for the MIPS
  375. architecture and that Buildroot is located in
  376. <code>~/buildroot/</code>) :</p>
  377. <pre>
  378. export PATH=&quot;$PATH:~/buildroot/build_mips/staging_dir/usr/bin/&quot;
  379. </pre>
  380. <p>Then you can simply do :</p>
  381. <pre>
  382. mips-linux-gcc -o foo foo.c
  383. </pre>
  384. <p><b>Important</b> : do not try to move a gcc-3.x toolchain to an other
  385. directory, it won't work. There are some hardcoded paths in the
  386. <i>gcc</i> configuration. If the default toolchain directory
  387. doesn't suit your needs, please refer to the <a
  388. href="#toolchain_standalone">Using the uClibc toolchain outside of
  389. buildroot</a> section. </p>
  390. <p>If you are using a current gcc-4.x, then use --sysroot and -isysroot
  391. since these toolchains have fully functional sysroot support. No
  392. hardcoded paths do exist in these configurations. </p>
  393. <h2><a name="toolchain_standalone" id="toolchain_standalone"></a>Using the
  394. uClibc toolchain outside of buildroot</h2>
  395. <p>By default, the cross-compilation toolchain is generated inside
  396. <code>build_ARCH/staging_dir/</code>. But sometimes, it may be useful to
  397. install it somewhere else, so that it can be used to compile other programs
  398. or by other users. Moving the <code>build_ARCH/staging_dir/</code>
  399. directory elsewhere is <b>not possible if using gcc-3.x</b>, because there
  400. are some hardcoded paths in the toolchain configuration. This works, thanks
  401. to sysroot support, with current, stable gcc-4.x toolchains, of course. </p>
  402. <p>If you want to use the generated gcc-3.x toolchain for other purposes,
  403. you can configure Buildroot to generate it elsewhere using the
  404. option of the configuration tool : <code>Build options -&gt;
  405. Toolchain and header file location</code>, which defaults to
  406. <code>$(BUILD_DIR)/staging_dir/</code>. </p>
  407. <h2><a name="downloaded_packages"
  408. id="downloaded_packages"></a>Location of downloaded packages</h2>
  409. <p>It might be useful to know that the various tarballs that are
  410. downloaded by the <i>Makefiles</i> are all stored in the
  411. <code>DL_DIR</code> which by default is the <code>dl</code>
  412. directory. It's useful for example if you want to keep a complete
  413. version of Buildroot which is know to be working with the
  414. associated tarballs. This will allow you to regenerate the
  415. toolchain and the target filesystem with exactly the same
  416. versions. </p>
  417. <h2><a name="add_software" id="add_software"></a>Extending Buildroot with
  418. more software</h2>
  419. <p>This section will only consider the case in which you want to
  420. add user-space software. </p>
  421. <h3>Package directory</h3>
  422. <p>First of all, create a directory under the <code>package</code>
  423. directory for your software, for example <code>foo</code>. </p>
  424. <h3><code>Config.in</code> file</h3>
  425. <p>Then, create a file named <code>Config.in</code>. This file
  426. will contain the portion of options description related to our
  427. <code>foo</code> software that will be used and displayed in the
  428. configuration tool. It should basically contain :</p>
  429. <pre>
  430. config BR2_PACKAGE_FOO
  431. bool "foo"
  432. default n
  433. help
  434. This is a comment that explains what foo is.
  435. http://foosoftware.org/foo/
  436. </pre>
  437. <p>Of course, you can add other options to configure particular
  438. things in your software. </p>
  439. <h3>The real <i>Makefile</i></h3>
  440. <p>Finally, here's the hardest part. Create a file named
  441. <code>foo.mk</code>. It will contain the <i>Makefile</i> rules that
  442. are in charge of downloading, configuring, compiling and installing
  443. the software. Below is an example that we will comment
  444. afterwards. </p>
  445. <pre>
  446. <a name="line1" id="line1">1</a> #############################################################
  447. <a name="line2" id="line2">2</a> #
  448. <a name="line3" id="line3">3</a> # foo
  449. <a name="line4" id="line4">4</a> #
  450. <a name="line5" id="line5">5</a> #############################################################
  451. <a name="line6" id="line6">6</a> FOO_VERSION:=1.0
  452. <a name="line7" id="line7">7</a> FOO_SOURCE:=foo-$(FOO_VERSION).tar.gz
  453. <a name="line8" id="line8">8</a> FOO_SITE:=http://www.foosoftware.org/downloads
  454. <a name="line9" id="line9">9</a> FOO_DIR:=$(BUILD_DIR)/foo-$(FOO_VERSION)
  455. <a name="line10" id="line10">10</a> FOO_BINARY:=foo
  456. <a name="line11" id="line11">11</a> FOO_TARGET_BINARY:=usr/bin/foo
  457. <a name="line12" id="line12">12</a>
  458. <a name="line13" id="line13">13</a> $(DL_DIR)/$(FOO_SOURCE):
  459. <a name="line14" id="line14">14</a> $(WGET) -P $(DL_DIR) $(FOO_SITE)/$(FOO_SOURCE)
  460. <a name="line15" id="line15">15</a>
  461. <a name="line16" id="line16">16</a> $(FOO_DIR)/.source: $(DL_DIR)/$(FOO_SOURCE)
  462. <a name="line17" id="line17">17</a> $(ZCAT) $(DL_DIR)/$(FOO_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
  463. <a name="line18" id="line18">18</a> touch $@
  464. <a name="line19" id="line19">19</a>
  465. <a name="line20" id="line20">20</a> $(FOO_DIR)/.configured: $(FOO_DIR)/.source
  466. <a name="line21" id="line21">21</a> (cd $(FOO_DIR); rm -rf config.cache ; \
  467. <a name="line22" id="line22">22</a> $(TARGET_CONFIGURE_OPTS) \
  468. <a name="line23" id="line23">23</a> CFLAGS="$(TARGET_CFLAGS)" \
  469. <a name="line24" id="line24">24</a> ./configure \
  470. <a name="line25" id="line25">25</a> --target=$(GNU_TARGET_NAME) \
  471. <a name="line26" id="line26">26</a> --host=$(GNU_TARGET_NAME) \
  472. <a name="line27" id="line27">27</a> --build=$(GNU_HOST_NAME) \
  473. <a name="line28" id="line28">28</a> --prefix=/usr \
  474. <a name="line29" id="line29">29</a> --sysconfdir=/etc \
  475. <a name="line30" id="line30">30</a> );
  476. <a name="line31" id="line31">31</a> touch $@
  477. <a name="line32" id="line32">32</a>
  478. <a name="line33" id="line33">33</a> $(FOO_DIR)/$(FOO_BINARY): $(FOO_DIR)/.configured
  479. <a name="line34" id="line34">34</a> $(MAKE) CC=$(TARGET_CC) -C $(FOO_DIR)
  480. <a name="line35" id="line35">35</a>
  481. <a name="line36" id="line36">36</a> $(TARGET_DIR)/$(FOO_TARGET_BINARY): $(FOO_DIR)/$(FOO_BINARY)
  482. <a name="line37" id="line37">37</a> $(MAKE) prefix=$(TARGET_DIR)/usr -C $(FOO_DIR) install
  483. <a name="line38" id="line38">38</a> rm -Rf $(TARGET_DIR)/usr/man
  484. <a name="line39" id="line39">39</a>
  485. <a name="line40" id="line40">40</a> foo: uclibc ncurses $(TARGET_DIR)/$(FOO_TARGET_BINARY)
  486. <a name="line41" id="line41">41</a>
  487. <a name="line42" id="line42">42</a> foo-source: $(DL_DIR)/$(FOO_SOURCE)
  488. <a name="line43" id="line43">43</a>
  489. <a name="line44" id="line44">44</a> foo-clean:
  490. <a name="line45" id="line45">45</a> $(MAKE) prefix=$(TARGET_DIR)/usr -C $(FOO_DIR) uninstall
  491. <a name="line46" id="line46">46</a> -$(MAKE) -C $(FOO_DIR) clean
  492. <a name="line47" id="line47">47</a>
  493. <a name="line48" id="line48">48</a> foo-dirclean:
  494. <a name="line49" id="line49">49</a> rm -rf $(FOO_DIR)
  495. <a name="line50" id="line50">50</a>
  496. <a name="line51" id="line51">51</a> #############################################################
  497. <a name="line52" id="line52">52</a> #
  498. <a name="line53" id="line53">53</a> # Toplevel Makefile options
  499. <a name="line54" id="line54">54</a> #
  500. <a name="line55" id="line55">55</a> #############################################################
  501. <a name="line56" id="line56">56</a> ifeq ($(strip $(BR2_PACKAGE_FOO)),y)
  502. <a name="line57" id="line57">57</a> TARGETS+=foo
  503. <a name="line58" id="line58">58</a> endif
  504. </pre>
  505. <p>First of all, this <i>Makefile</i> example works for a single
  506. binary software. For other software such as libraries or more
  507. complex stuff with multiple binaries, it should be adapted. Look at
  508. the other <code>*.mk</code> files in the <code>package</code>
  509. directory. </p>
  510. <p>At lines <a href="#line6">6-11</a>, a couple of useful variables are
  511. defined :</p>
  512. <ul>
  513. <li><code>FOO_VERSION</code> : The version of <i>foo</i> that
  514. should be downloaded. </li>
  515. <li><code>FOO_SOURCE</code> : The name of the tarball of
  516. <i>foo</i> on the download website of FTP site. As you can see
  517. <code>FOO_VERSION</code> is used. </li>
  518. <li><code>FOO_SITE</code> : The HTTP or FTP site from which
  519. <i>foo</i> archive is downloaded. It must include the complete
  520. path to the directory where <code>FOO_SOURCE</code> can be
  521. found. </li>
  522. <li><code>FOO_DIR</code> : The directory into which the software
  523. will be configured and compiled. Basically, it's a subdirectory
  524. of <code>BUILD_DIR</code> which is created upon decompression of
  525. the tarball. </li>
  526. <li><code>FOO_BINARY</code> : Software binary name. As said
  527. previously, this is an example for a single binary software. </li>
  528. <li><code>FOO_TARGET_BINARY</code> : The full path of the binary
  529. inside the target filesystem. </li>
  530. </ul>
  531. <p>Lines <a href="#line13">13-14</a> defines a target that downloads the
  532. tarball from the remote site to the download directory
  533. (<code>DL_DIR</code>). </p>
  534. <p>Lines <a href="#line16">16-18</a> defines a target and associated rules
  535. that uncompress the downloaded tarball. As you can see, this target
  536. depends on the tarball file, so that the previous target (line
  537. <a href="#line13">13-14</a>) is called before executing the rules of the
  538. current target. Uncompressing is followed by <i>touching</i> a hidden file
  539. to mark the software has having been uncompressed. This trick is
  540. used everywhere in Buildroot <i>Makefile</i> to split steps
  541. (download, uncompress, configure, compile, install) while still
  542. having correct dependencies. </p>
  543. <p>Lines <a href="#line20">20-31</a> defines a target and associated rules
  544. that configures the software. It depends on the previous target (the
  545. hidden <code>.source</code> file) so that we are sure the software has
  546. been uncompressed. In order to configure it, it basically runs the
  547. well-known <code>./configure</code> script. As we may be doing
  548. cross-compilation, <code>target</code>, <code>host</code> and
  549. <code>build</code> arguments are given. The prefix is also set to
  550. <code>/usr</code>, not because the software will be installed in
  551. <code>/usr</code> on your host system, but in the target
  552. filesystem. Finally it creates a <code>.configured</code> file to
  553. mark the software as configured. </p>
  554. <p>Lines <a href="#line33">33-34</a> defines a target and a rule that
  555. compiles the software. This target will create the binary file in the
  556. compilation directory, and depends on the software being already
  557. configured (hence the reference to the <code>.configured</code>
  558. file). It basically runs <code>make</code> inside the source
  559. directory. </p>
  560. <p>Lines <a href="#line36">36-38</a> defines a target and associated rules
  561. that install the software inside the target filesystem. It depends on the
  562. binary file in the source directory, to make sure the software has
  563. been compiled. It uses the <code>install</code> target of the
  564. software <code>Makefile</code> by passing a <code>prefix</code>
  565. argument, so that the <code>Makefile</code> doesn't try to install
  566. the software inside host <code>/usr</code> but inside target
  567. <code>/usr</code>. After the installation, the
  568. <code>/usr/man</code> directory inside the target filesystem is
  569. removed to save space. </p>
  570. <p>Line <a href="#line40">40</a> defines the main target of the software,
  571. the one that will be eventually be used by the top level
  572. <code>Makefile</code> to download, compile, and then install
  573. this package. This target should first of all depends on all
  574. needed dependecies of the software (in our example,
  575. <i>uclibc</i> and <i>ncurses</i>), and also depend on the
  576. final binary. This last dependency will call all previous
  577. dependencies in the correct order. </p>
  578. <p>Line <a href="#line42">42</a> defines a simple target that only
  579. downloads the code source. This is not used during normal operation of
  580. Buildroot, but is needed if you intend to download all required sources at
  581. once for later offline build. Note that if you add a new package providing
  582. a <code>foo-source</code> target is <i>mandatory</i> to support
  583. users that wish to do offline-builds. Furthermore it eases checking
  584. if all package-sources are downloadable. </p>
  585. <p>Lines <a href="#line44">44-46</a> define a simple target to clean the
  586. software build by calling the <i>Makefiles</i> with the appropriate option.
  587. The <code>-clean</code> target should run <code>make clean</code>
  588. on $(BUILD_DIR)/package-version and MUST uninstall all files of the
  589. package from $(STAGING_DIR) and from $(TARGET_DIR). </p>
  590. <p>Lines <a href="#line48">48-49</a> define a simple target to completely
  591. remove the directory in which the software was uncompressed, configured and
  592. compiled. The <code>-dirclean</code> target MUST completely rm $(BUILD_DIR)/
  593. package-version. </p>
  594. <p>Lines <a href="#line51">51-58</a> adds the target <code>foo</code> to
  595. the list of targets to be compiled by Buildroot by first checking if
  596. the configuration option for this package has been enabled
  597. using the configuration tool, and if so then &quot;subscribes&quot;
  598. this package to be compiled by adding it to the TARGETS
  599. global variable. The name added to the TARGETS global
  600. variable is the name of this package's target, as defined on
  601. line <a href="#line40">40</a>, which is used by Buildroot to download,
  602. compile, and then install this package. </p>
  603. <h3>Conclusion</h3>
  604. <p>As you can see, adding a software to buildroot is simply a
  605. matter of writing a <i>Makefile</i> using an already existing
  606. example and to modify it according to the compilation process of
  607. the software. </p>
  608. <p>If you package software that might be useful for other persons,
  609. don't forget to send a patch to Buildroot developers !</p>
  610. <h2><a name="links" id="links"></a>Resources</h2>
  611. <p>To learn more about Buildroot you can visit these
  612. websites:</p>
  613. <ul>
  614. <li><a href="http://www.uclibc.org/">http://www.uclibc.org/</a></li>
  615. <li><a href="http://www.busybox.net/">http://www.busybox.net/</a></li>
  616. </ul>
  617. </div>
  618. <!--
  619. <a href="http://validator.w3.org/check?uri=referer"><img
  620. border="0" height="31" width="88"
  621. src="images/valid-html401.png"
  622. alt="Valid HTML"></img></a>
  623. -->
  624. </body>
  625. </html>