buildroot.html 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  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. <ul>
  19. <li><a href="#about">About Buildroot</a></li>
  20. <li><a href="#download">Obtaining Buildroot</a></li>
  21. <li><a href="#using">Using Buildroot</a></li>
  22. <li><a href="#custom_targetfs">Customizing the generated target filesystem</a></li>
  23. <li><a href="#custom_busybox">Customizing the Busybox
  24. configuration</a></li>
  25. <li><a href="#custom_uclibc">Customizing the uClibc
  26. configuration</a></li>
  27. <li><a href="#custom_linux26">Customizing the Linux kernel
  28. configuration</a></li>
  29. <li><a href="#rebuilding_packages">Understanding how to rebuild packages</a></li>
  30. <li><a href="#buildroot_innards">How Buildroot works</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="#board_support">Creating your own board support</a></li>
  39. <li><a href="#links">Resources</a></li>
  40. </ul>
  41. <h2><a name="about" id="about"></a>About Buildroot</h2>
  42. <p>Buildroot is a set of Makefiles and patches that allows you to
  43. easily generate a cross-compilation toolchain, a root filesystem
  44. and a Linux kernel image for your target. Buildroot can be used
  45. for one, two or all of these options, independently.</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 having in his PC. They can be PowerPC
  49. processors, MIPS processors, ARM processors, etc. </p>
  50. <p>A compilation toolchain is the set of tools that allows you 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 an 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 an x86
  61. processor. Under most Linux systems, the compilation toolchain
  62. uses the GNU libc (glibc) as the C standard library. This compilation
  63. toolchain is called the &quot;host compilation toolchain&quot;.
  64. 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 (other than using it to build a cross-compilation toolchain
  68. and other tools that are run on the development host). </p>
  69. <p>As said above, the compilation toolchain that comes with your system
  70. runs on and generates code for the processor in your host system. As your
  71. embedded system has a different processor, you need a cross-compilation
  72. toolchain &mdash; a compilation toolchain that runs on your host system but
  73. generates code for your target system (and target processor). For
  74. example, if your host system uses x86 and your target system uses ARM, the
  75. regular compilation toolchain on your host runs on x86 and generates code
  76. for x86, while the cross-compilation toolchain runs on x86 and generates
  77. code for ARM. </p>
  78. <p>Even if your embedded system uses an x86 processor, you might be interested
  79. in Buildroot for two reasons:</p>
  80. <ul>
  81. <li>The compilation toolchain on your host certainly uses the GNU Libc
  82. which is a complete but huge C standard library. Instead of using GNU
  83. Libc on your target system, you can use uClibc which is a tiny C standard
  84. library. If you want to use this C library, then you need a compilation
  85. toolchain to generate binaries linked with it. Buildroot can do that for
  86. you. </li>
  87. <li>Buildroot automates the building of a root filesystem with all needed
  88. tools like busybox. That makes it much easier than doing it by hand. </li>
  89. </ul>
  90. <p>You might wonder why such a tool is needed when you can compile
  91. <code>gcc</code>, <code>binutils</code>, <code>uClibc</code> and all
  92. the other tools by hand.
  93. Of course doing so is possible. But, dealing with all of the configure options
  94. and problems of every <code>gcc</code> or <code>binutils</code>
  95. version is very time-consuming and uninteresting. Buildroot automates this
  96. process through the use of Makefiles and has a collection of patches for
  97. each <code>gcc</code> and <code>binutils</code> version to make them work
  98. on most architectures. </p>
  99. <p>Moreover, Buildroot provides an infrastructure for reproducing
  100. the build process of your kernel, cross-toolchain, and embedded root filesystem. Being able to
  101. reproduce the build process will be useful when a component needs
  102. to be patched or updated or when another person is supposed to
  103. take over the project.</p>
  104. <h2><a name="download" id="download"></a>Obtaining Buildroot</h2>
  105. <p>Buildroot releases are made approximately every 3
  106. months. Direct Git access and daily snapshots are also
  107. available if you want more bleeding edge.</p>
  108. <p>Releases are available at <a
  109. href="http://buildroot.net/downloads/">http://buildroot.net/downloads/</a>.</p>
  110. <p>The latest snapshot is always available at <a
  111. href="http://buildroot.net/downloads/snapshots/buildroot-snapshot.tar.bz2">http://buildroot.net/downloads/snapshots/buildroot-snapshot.tar.bz2</a>,
  112. and previous snapshots are also available at <a
  113. href="http://buildroot.net/downloads/snapshots/">http://buildroot.net/downloads/snapshots/</a>. </p>
  114. <p>To download Buildroot using Git you can simply follow
  115. the rules described on the &quot;Accessing Git&quot; page (<a href=
  116. "http://buildroot.net/git.html">http://buildroot.net/git.html</a>)
  117. of the Buildroot website (<a href=
  118. "http://buildroot.net">http://buildroot.net</a>).
  119. For the impatient, here's a quick
  120. recipe:</p>
  121. <pre>
  122. $ git clone git://git.buildroot.net/buildroot
  123. </pre>
  124. <h2><a name="using" id="using"></a>Using Buildroot</h2>
  125. <p>Buildroot has a nice configuration tool similar to the one you can find
  126. in the Linux kernel (<a href=
  127. "http://www.kernel.org/">http://www.kernel.org/</a>) or in Busybox
  128. (<a href="http://www.busybox.org/">http://www.busybox.org/</a>). Note that
  129. you can (and should) build everything as a normal user. There is no need to be root to
  130. configure and use Buildroot. The first step is to run the configuration
  131. assistant:</p>
  132. <pre>
  133. $ make menuconfig
  134. </pre>
  135. <p>to run the curses-based configurator, or</p>
  136. <pre>
  137. $ make xconfig
  138. </pre>
  139. <p>to run the Qt3-based configurator.</p>
  140. <p>Both of these "make" commands will need to build a configuration
  141. utility, so you may need to install "development" packages for
  142. relevent libraries used by the configuration utilities.
  143. On Debian-like systems, the
  144. <code>libncurses5-dev</code> package is required to use the
  145. <i>menuconfig</i> interface, and the <code>libqt3-mt-dev</code> is
  146. required to use the <i>xconfig</i> interface.</p>
  147. <p>For each menu entry in the configuration tool, you can find associated help
  148. that describes the purpose of the entry. </p>
  149. <p>Once everything is configured, the configuration tool generates a
  150. <code>.config</code> file that contains the description of your
  151. configuration. It will be used by the Makefiles to do what's needed. </p>
  152. <p>Let's go:</p>
  153. <pre>
  154. $ make
  155. </pre>
  156. <p>This command will generally perform the following steps:</p>
  157. <ul>
  158. <li>Download source files (as required)</li>
  159. <li>Configure cross-compile toolchain</li>
  160. <li>Build/install cross-compile toolchain</li>
  161. <li>Build/install selected target packages</li>
  162. <li>Build a kernel image</li>
  163. <li>Create a root filesystem in selected formats</li>
  164. </ul>
  165. <p>Some of the above steps might not be performed if they are not
  166. selected in the Buildroot configuration.
  167. </p>
  168. <p>Buildroot output is stored in a single directory,
  169. <code>output/</code>. This directory contains several
  170. subdirectories:</p>
  171. <ul>
  172. <li><code>images/</code> where all the images (kernel image,
  173. bootloader and root filesystem images) are stored.</li>
  174. <li><code>build/</code> where all the components except for the
  175. cross-compilation toolchain are built
  176. (this includes tools needed to run Buildroot on the host and packages compiled
  177. for the target). The <code>build/</code> directory contains one
  178. subdirectory for each of these components.</li>
  179. <li><code>staging/</code> which contains a hierarchy similar to
  180. a root filesystem hierarchy. This directory contains the
  181. installation of the cross-compilation toolchain and all the
  182. userspace packages selected for the target. However, this
  183. directory is <i>not</i> intended to be the root filesystem for
  184. the target: it contains a lot of development files, unstripped
  185. binaries and libraries that make it far too big for an embedded
  186. system.</li>
  187. <li><code>target/</code> which contains <i>almost</i> the root
  188. filesystem for the target: everything needed is present except
  189. the device files in <code>/dev/</code> (Buildroot can't create
  190. them because Buildroot doesn't run as root and does not want to
  191. run as root). Therefore, this directory <b>should not be used on
  192. your target</b>. Instead, you should use one of the images
  193. built in the <code>images/</code> directory. If you need an
  194. extracted image of the root filesystem for booting over NFS,
  195. then use the tarball image generated in <code>images/</code> and
  196. extract it as root.<br/>Compared to <code>staging/</code>,
  197. <code>target/</code> contains only the files and libraries needed
  198. to run the selected target applications: the development files
  199. (headers, etc.) are not present.</li>
  200. <li><code>host/</code> contains the installation of tools
  201. compiled for the host that are needed for the proper execution
  202. of Buildroot except for the cross-compilation toolchain which is
  203. installed under <code>staging/</code>.</li>
  204. <li><code>toolchain/</code> contains the build directories for
  205. the various components of the cross-compilation toolchain.</li>
  206. </ul>
  207. <h3><a name="offline_builds" id="offline_builds"></a>
  208. Offline builds</h3>
  209. <p>If you intend to do an offline build and just want to download
  210. all sources that you previously selected in the configurator
  211. (<i>menuconfig</i> or <i>xconfig</i>), then issue:</p>
  212. <pre>
  213. $ make source
  214. </pre>
  215. <p>You can now disconnect or copy the content of your <code>dl</code>
  216. directory to the build-host. </p>
  217. <h3><a name="building_out_of_tree" id="building_out_of_tree"></a>
  218. Building out-of-tree</h3>
  219. <p>Buildroot supports building out of tree with a syntax similar
  220. to the Linux kernel. To use it, add O=&lt;directory&gt; to the
  221. make command line:</p>
  222. <pre>
  223. $ make O=/tmp/build
  224. </pre>
  225. <p>All the output files will be located under
  226. <code>/tmp/build</code>.</p>
  227. <h3><a name="environment_variables" id="environment_variables"></a>
  228. Environment variables</h3>
  229. <p>Buildroot also honors some environment variables when they are passed
  230. to <code>make</code>:</p>
  231. <ul>
  232. <li><code>HOSTCXX</code>, the host C++ compiler to use</li>
  233. <li><code>HOSTCC</code>, the host C compiler to use</li>
  234. <li><code>UCLIBC_CONFIG_FILE=&lt;path/to/.config&gt;</code>, path
  235. to the uClibc configuration file to use to compile uClibc if an
  236. internal toolchain is being built</li>
  237. <li><code>BUSYBOX_CONFIG_FILE=&lt;path/to/.config&gt;</code>, path
  238. to the Busybox configuration file</li>
  239. <li><code>LINUX26_KCONFIG=&lt;path/to/.config&gt;</code>, path
  240. to the Linux kernel configuration file</li>
  241. <li><code>BUILDROOT_COPYTO</code>, an additional location to which
  242. the binary images of the root filesystem, kernel, etc. built by
  243. Buildroot are copied</li>
  244. <li><code>BUILDROOT_DL_DIR</code> to override the directory in
  245. which Buildroot stores/retrieves downloaded files</li>
  246. </ul>
  247. <p>An example that uses config files located in the toplevel directory and
  248. in your $HOME:</p>
  249. <pre>
  250. $ make UCLIBC_CONFIG_FILE=uClibc.config BUSYBOX_CONFIG_FILE=$HOME/bb.config
  251. </pre>
  252. <p>If you want to use a compiler other than the default <code>gcc</code>
  253. or <code>g++</code> for building helper-binaries on your host, then do</p>
  254. <pre>
  255. $ make HOSTCXX=g++-4.3-HEAD HOSTCC=gcc-4.3-HEAD
  256. </pre>
  257. <p>If you want the result of your build to be copied to another directory
  258. like /tftpboot for downloading to a board using tftp, then you
  259. can use BUILDROOT_COPYTO to specify your location</p>
  260. <p>Typically, this is set in your ~/.bashrc file
  261. <pre>
  262. $ export BUILDROOT_COPYTO=/tftpboot
  263. </pre>
  264. <h2><a name="custom_targetfs" id="custom_targetfs"></a>Customizing the
  265. generated target filesystem</h2>
  266. <p>There are a few ways to customize the resulting target filesystem:</p>
  267. <ul>
  268. <li>Customize the target filesystem directly and rebuild the image. The
  269. target filesystem is available under <code>output/target/</code>.
  270. You can simply make your changes here and run make afterwards &mdash; this will
  271. rebuild the target filesystem image. This method allows you to do anything
  272. to the target filesystem, but if you decide to completely rebuild your
  273. toolchain and tools, these changes will be lost. </li>
  274. <li>Customize the target filesystem skeleton available under
  275. <code>target/generic/target_skeleton/</code>. You can customize
  276. configuration files or other stuff here. However, the full file hierarchy
  277. is not yet present because it's created during the compilation process.
  278. Therefore, you can't do everything on this target filesystem skeleton, but
  279. changes to it do remain even if you completely rebuild the cross-compilation
  280. toolchain and the tools. <br />
  281. You can also customize the <code>target/generic/device_table.txt</code>
  282. file which is used by the tools that generate the target filesystem image
  283. to properly set permissions and create device nodes.<br />
  284. These customizations are deployed into
  285. <code>output/target/</code> just before the actual image
  286. is made. Simply rebuilding the image by running
  287. make should propagate any new changes to the image. </li>
  288. <li>Add support for your own target in Buildroot so that you
  289. have your own target skeleton (see <a href="#board_support">this
  290. section</a> for details).</li>
  291. <li>In the Buildroot configuration, you can specify the path to a
  292. post-build script that gets called <i>after</i> Buildroot builds
  293. all the selected software but <i>before</i> the the rootfs
  294. packages are assembled. The destination root filesystem folder
  295. is given as the first argument to this script, and this script can
  296. then be used to copy programs, static data or any other needed
  297. file to your target filesystem.<br/>You should, however, use
  298. this feature with care. Whenever you find that a certain package
  299. generates wrong or unneeded files, you should fix that
  300. package rather than work around it with a post-build cleanup script.</li>
  301. <li>A special package, <i>customize</i>, stored in
  302. <code>package/customize</code> can be used. You can put all the
  303. files that you want to see in the final target root filesystem
  304. in <code>package/customize/source</code> and then enable this
  305. special package in the configuration system.</li>
  306. </ul>
  307. <h2><a name="custom_busybox" id="custom_busybox"></a>Customizing the
  308. Busybox configuration</h2>
  309. <p><a href="http://www.busybox.net/">Busybox</a> is very configurable, and
  310. you may want to customize it. You can
  311. follow these simple steps to do so. This method isn't optimal, but it's
  312. simple and it works:</p>
  313. <ol>
  314. <li>Do an initial compilation of Buildroot with busybox without trying to
  315. customize it. </li>
  316. <li>Invoke <code>make busybox-menuconfig</code>.
  317. The nice configuration tool appears, and you can
  318. customize everything. </li>
  319. <li>Run the compilation of Buildroot again. </li>
  320. </ol>
  321. <p>Otherwise, you can simply change the
  322. <code>package/busybox/busybox-&lt;version&gt;.config</code> file if you
  323. know the options you want to change without using the configuration tool.
  324. </p>
  325. <p>If you want to use an existing config file for busybox, then see
  326. section <a href="#environment_variables">environment variables</a>. </p>
  327. <h2><a name="custom_uclibc" id="custom_uclibc"></a>Customizing the uClibc
  328. configuration</h2>
  329. <p>Just like <a href="#custom_busybox">BusyBox</a>, <a
  330. href="http://www.uclibc.org/">uClibc</a> offers a lot of
  331. configuration options. They allow you to select various
  332. functionalities depending on your needs and limitations. </p>
  333. <p>The easiest way to modify the configuration of uClibc is to
  334. follow these steps:</p>
  335. <ol>
  336. <li>Do an initial compilation of Buildroot without trying to
  337. customize uClibc. </li>
  338. <li>Invoke <code>make uclibc-menuconfig</code>.
  339. The nice configuration assistant, similar to
  340. the one used in the Linux kernel or Buildroot, appears. Make
  341. your configuration changes as appropriate. </li>
  342. <li>Copy the <code>.config</code> file to
  343. <code>toolchain/uClibc/uClibc.config</code> or
  344. <code>toolchain/uClibc/uClibc.config-locale</code>. The former
  345. is used if you haven't selected locale support in Buildroot
  346. configuration, and the latter is used if you have selected
  347. locale support. </li>
  348. <li>Run the compilation of Buildroot again.</li>
  349. </ol>
  350. <p>Otherwise, you can simply change
  351. <code>toolchain/uClibc/uClibc.config</code> or
  352. <code>toolchain/uClibc/uClibc.config-locale</code> without running
  353. the configuration assistant. </p>
  354. <p>If you want to use an existing config file for uclibc, then see
  355. section <a href="#environment_variables">environment variables</a>. </p>
  356. <h2><a name="custom_linux26" id="custom_linux26"></a>Customizing
  357. the Linux kernel configuration</h2>
  358. <p>The Linux kernel configuration can be customized just like <a
  359. href="#custom_busybox">BusyBox</a> and <a href="#custom_uclibc">uClibc</a>
  360. using <code>make linux26-menuconfig</code>. Make sure you have
  361. enabled the kernel build in <code>make menuconfig</code> first.
  362. Once done, run <code>make</code> to (re)build everything.</p>
  363. <p>If you want to use an existing config file for Linux, then see
  364. section <a href="#environment_variables">environment variables</a>.</p>
  365. <h2><a name="#rebuilding_packages"
  366. id="rebuilding_packages">Understanding how to rebuild
  367. packages</a></h2>
  368. <p>One of the most common questions asked by Buildroot
  369. users is how to rebuild a given package or how to
  370. remove a package without rebuilding everything from scratch.</p>
  371. <p>Removing a package is currently unsupported by Buildroot
  372. without rebuilding from scratch. This is because Buildroot doesn't
  373. keep track of which package installs what files in the
  374. <code>output/staging</code> and <code>output/target</code>
  375. directories. However, implementing clean package removal is on the
  376. TODO-list of Buildroot developers.</p>
  377. <p>The easiest way to rebuild a single package from scratch is to
  378. remove its build directory in <code>output/build</code>. Buildroot
  379. will then re-extract, re-configure, re-compile and re-install this
  380. package from scratch.</p>
  381. <p>However, if you don't want to rebuild the package completely
  382. from scratch, a better understanding of the Buildroot internals is
  383. needed. Internally, to keep track of which steps have been done
  384. and which steps remain to be done, Buildroot maintains stamp
  385. files (empty files that just tell whether this or that action
  386. has been done). The problem is that these stamp files are not
  387. uniformely named and handled by the different packages, so some
  388. understanding of the particular package is needed.</p>
  389. <p>For packages relying on the <i>autotools</i> Buildroot
  390. infrastructure (see <a href="#add_software">this section</a> for
  391. details), the following stamp files are relevent:</p>
  392. <ul>
  393. <li><code>output/build/packagename-version/.stamp_configured</code>. If
  394. removed, Buildroot will trigger the recompilation of the package
  395. from the configuration step (execution of
  396. <code>./configure</code>).</li>
  397. <li><code>output/build/packagename-version/.stamp_built</code>. If
  398. removed, Buildroot will trigger the recompilation of the package
  399. from the compilation step (execution of <code>make</code>).</li>
  400. </ul>
  401. <p>For other packages, an analysis of the specific
  402. <i>package.mk</i> file is needed. For example, the zlib Makefile
  403. looks like:</p>
  404. <pre>
  405. $(ZLIB_DIR)/.configured: $(ZLIB_DIR)/.patched
  406. (cd $(ZLIB_DIR); rm -rf config.cache; \
  407. [...]
  408. )
  409. touch $@
  410. $(ZLIB_DIR)/libz.a: $(ZLIB_DIR)/.configured
  411. $(MAKE) -C $(ZLIB_DIR) all libz.a
  412. touch -c $@
  413. </pre>
  414. <p>If you want to trigger the reconfiguration, you need to
  415. remove <code>output/build/zlib-version/.configured</code>. If
  416. you want to trigger only the recompilation, you need to remove
  417. <code>output/build/zlib-version/libz.a</code>.</p>
  418. <h2><a name="buildroot_innards" id="buildroot_innards"></a>How Buildroot
  419. works</h2>
  420. <p>As mentioned above, Buildroot is basically a set of Makefiles that downloads,
  421. configures and compiles software with the correct options. It also includes
  422. patches for various software packages &mdash; mainly the ones involved in the
  423. cross-compilation tool chain (<code>gcc</code>, <code>binutils</code> and
  424. <code>uClibc</code>). </p>
  425. <p>There is basically one Makefile per software package, and they are named with
  426. the <code>.mk</code> extension. Makefiles are split into four
  427. sections:</p>
  428. <ul>
  429. <li><b>toolchain</b> (in the <code>toolchain/</code> directory) contains
  430. the Makefiles and associated files for all software related to the
  431. cross-compilation toolchain: <code>binutils</code>, <code>ccache</code>,
  432. <code>gcc</code>, <code>gdb</code>, <code>kernel-headers</code> and
  433. <code>uClibc</code>. </li>
  434. <li><b>package</b> (in the <code>package/</code> directory) contains the
  435. Makefiles and associated files for all user-space tools that Buildroot
  436. can compile and add to the target root filesystem. There is one
  437. sub-directory per tool. </li>
  438. <li><b>target</b> (in the <code>target</code> directory) contains the
  439. Makefiles and associated files for software related to the generation of
  440. the target root filesystem image. Four types of filesystems are supported:
  441. ext2, jffs2, cramfs and squashfs. For each of them there is a
  442. sub-directory with the required files. There is also a
  443. <code>default/</code> directory that contains the target filesystem
  444. skeleton. </li>
  445. </ul>
  446. <p>Each directory contains at least 2 files:</p>
  447. <ul>
  448. <li><code>something.mk</code> is the Makefile that downloads, configures,
  449. compiles and installs the package <code>something</code>. </li>
  450. <li><code>Config.in</code> is a part of the configuration tool
  451. description file. It describes the options related to the
  452. package. </li>
  453. </ul>
  454. <p>The main Makefile performs the following steps (once the
  455. configuration is done):</p>
  456. <ol>
  457. <li>Create all the output directories: <code>staging</code>,
  458. <code>target</code>, <code>build</code>, <code>stamps</code>,
  459. etc. in the output directory (<code>output/</code> by default,
  460. another value can be specified using <code>O=</code>)</li>
  461. <li>Generate all the targets listed in the
  462. <code>BASE_TARGETS</code> variable. When an internal toolchain
  463. is used, this means generating the cross-compilation
  464. toolchain. When an external toolchain is used, this means checking
  465. the features of the external toolchain and importing it into the
  466. Buildroot environment.</li>
  467. <li>Generate all the targets listed in the <code>TARGETS</code>
  468. variable. This variable is filled by all the individual
  469. components' Makefiles. Generating these targets will
  470. trigger the compilation of the userspace packages (libraries,
  471. programs), the kernel, the bootloader and the generation of the
  472. root filesystem images, depending on the configuration.</li>
  473. </ol>
  474. <h2><a name="board_support" id="board_support"></a>
  475. Creating your own board support</h2>
  476. <p>Creating your own board support in Buildroot allows you to have
  477. a convenient place to store your project's target filesystem skeleton
  478. and configuration files for Buildroot, Busybox, uClibc, and the kernel.
  479. <p>Follow these steps to integrate your board in Buildroot:</p>
  480. <ol>
  481. <li>Create a new directory in <code>target/device/</code> named
  482. after your company or organization</li>
  483. <li>Add a line <code>source
  484. "target/device/yourcompany/Config.in"</code> in
  485. <code>target/device/Config.in</code> so that your board appears
  486. in the configuration system</li>
  487. <li>In <code>target/device/yourcompany/</code>, create a
  488. directory for your project. This way, you'll be able to store
  489. several of your company's projects inside Buildroot.</li>
  490. <li>Create a <code>target/device/yourcompany/Config.in</code>
  491. file that looks like the following:
  492. <pre>
  493. menuconfig BR2_TARGET_COMPANY
  494. bool "Company projects"
  495. if BR2_TARGET_COMPANY
  496. config BR2_TARGET_COMPANY_PROJECT_FOOBAR
  497. bool "Support for Company project Foobar"
  498. help
  499. This option enables support for Company project Foobar
  500. endif
  501. </pre>
  502. Of course, you should customize the different values to match your
  503. company/organization and your project. This file will create a
  504. menu entry that contains the different projects of your
  505. company/organization.</li>
  506. <li>Create a <code>target/device/yourcompany/Makefile.in</code>
  507. file that looks like the following:
  508. <pre>
  509. ifeq ($(BR2_TARGET_COMPANY_PROJECT_FOOBAR),y)
  510. include target/device/yourcompany/project-foobar/Makefile.in
  511. endif
  512. </pre>
  513. </li>
  514. <li>Create the
  515. <code>target/device/yourcompany/project-foobar/Makefile.in</code>
  516. file. It is recommended that you define a
  517. <code>BOARD_PATH</code> variable set to
  518. <code>target/device/yourcompany/project-foobar</code> as it
  519. will simplify further definitions. Then, the file might define
  520. one or several of the following variables:
  521. <ul>
  522. <li><code>TARGET_SKELETON</code> to a directory that contains
  523. the target skeleton for your project. If this variable is
  524. defined, this target skeleton will be used instead of the
  525. default one. If defined, the convention is to define it to
  526. <code>$(BOARD_PATH)/target_skeleton</code> so that the target
  527. skeleton is stored in the board specific directory.</li>
  528. <li><code>TARGET_DEVICE_TABLE</code> to a file that contains
  529. the target device table &mdash; the list of device files (in
  530. <code>/dev/</code>) to be created by the root filesystem build
  531. procedure. If this variable is defined, the given device table
  532. will be used instead of the default one. If defined, the
  533. convention is to define it to
  534. <code>$(BOARD_PATH)/target_device_table.txt</code>. See
  535. <code>target/generic/device_table.txt</code> for an example
  536. file.</li>
  537. </ul>
  538. </li>
  539. <li>In the
  540. <code>target/device/yourcompany/project-foobar/</code>
  541. directory you can store configuration files for the kernel,
  542. Busybox or uClibc.
  543. You can furthermore create one or more preconfigured configuration
  544. files, referencing those files. These config files are named
  545. <code>something_defconfig</code> and are stored in the toplevel
  546. <code>configs/</code> directory. Your users will then be able
  547. to run <code>make something_defconfig</code> and get the right
  548. configuration for your project</li>
  549. </ol>
  550. <h2><a name="using_toolchain" id="using_toolchain"></a>Using the
  551. generated toolchain outside Buildroot</h2>
  552. <p>You may want to compile for your target your own programs or other software
  553. that are not packaged in Buildroot. In order to do this you can
  554. use the toolchain that was generated by Buildroot. </p>
  555. <p>The toolchain generated by Buildroot is located by default in
  556. <code>output/staging/</code>. The simplest way to use it
  557. is to add <code>output/staging/usr/bin/</code> to your PATH
  558. environnement variable and then to use
  559. <code>ARCH-linux-gcc</code>, <code>ARCH-linux-objdump</code>,
  560. <code>ARCH-linux-ld</code>, etc. </p>
  561. <p><b>Important</b>: do not try to move a gcc-3.x toolchain to another
  562. directory &mdash; it won't work because there are some hardcoded paths in the
  563. gcc-3.x configuration. If you are using a current gcc-4.x, it
  564. is possible to relocate the toolchain &mdash; but then
  565. <code>--sysroot</code> must be passed every time the compiler is
  566. called to tell where the libraries and header files are.</p>
  567. <p>It is also possible to generate the Buildroot toolchain in
  568. a directory other than <code>output/staging</code> by using the
  569. <code>Build options -&gt; Toolchain and header file
  570. location</code> options. This could be useful if the toolchain
  571. must be shared with other users.</p>
  572. <h2><a name="downloaded_packages"
  573. id="downloaded_packages"></a>Location of downloaded packages</h2>
  574. <p>It might be useful to know that the various tarballs that are
  575. downloaded by the Makefiles are all stored in the
  576. <code>DL_DIR</code> which by default is the <code>dl</code>
  577. directory. It's useful, for example, if you want to keep a complete
  578. version of Buildroot which is know to be working with the
  579. associated tarballs. This will allow you to regenerate the
  580. toolchain and the target filesystem with exactly the same
  581. versions. </p>
  582. <p>If you maintain several Buildroot trees, it might be better to have
  583. a shared download location. This can be accessed by creating a symbolic link
  584. from the <code>dl</code> directory to the shared download location: </p>
  585. <pre>
  586. ln -s &lt;shared download location&gt; dl
  587. </pre>
  588. <p>Another way of accessing a shared download location is to
  589. create the <code>BUILDROOT_DL_DIR</code> environment variable.
  590. If this is set, then the value of DL_DIR in the project is
  591. overridden. The following line should be added to
  592. <code>&quot;~/.bashrc&quot;</code>. <p>
  593. <pre>
  594. export BUILDROOT_DL_DIR &lt;shared download location&gt;
  595. </pre>
  596. <h2><a name="external_toolchain" id="external_toolchain"></a>Using
  597. an external toolchain</h2>
  598. <p>It might be useful not to use the toolchain generated by
  599. Buildroot, for example if you already have a toolchain that is known
  600. to work for your specific CPU, or if the toolchain generation feature
  601. of Buildroot is not sufficiently flexible for you (for example if you
  602. need to generate a system with <i>glibc</i> instead of
  603. <i>uClibc</i>). Buildroot supports using an <i>external
  604. toolchain</i>.</p>
  605. <p>To enable the use of an external toolchain, go in the
  606. <code>Toolchain</code> menu, and&nbsp;:</p>
  607. <ul>
  608. <li>Select the <code>External binary toolchain</code> toolchain
  609. type</li>
  610. <li>Adjust the <code>External toolchain path</code>
  611. appropriately. It should be set to a path where a bin/ directory
  612. contains your cross-compiling tools</li>
  613. <li>Adjust the <code>External toolchain prefix</code> so that the
  614. prefix, suffixed with <code>-gcc</code> or <code>-ld</code> will
  615. correspond to your cross-compiling tools</li>
  616. </ul>
  617. <p>If you are using an external toolchain based on <i>uClibc</i>, the
  618. <code>Core C library from the external toolchain</code> and
  619. <code>Libraries to copy from the external toolchain</code> options
  620. should already have correct values. However, if your external
  621. toolchain is based on <i>glibc</i>, you'll have to change these values
  622. according to your cross-compiling toolchain.</p>
  623. <p>To generate external toolchains, we recommend using <a
  624. href="http://ymorin.is-a-geek.org/dokuwiki/projects/crosstool">Crosstool-NG</a>.
  625. It allows generating toolchains based on <i>uClibc</i>, <i>glibc</i>
  626. and <i>eglibc</i> for a wide range of architectures and has good
  627. community support.</p>
  628. <h2><a name="add_software" id="add_software"></a>Extending Buildroot with
  629. more software</h2>
  630. <p>This section will only consider the case in which you want to
  631. add user-space software. </p>
  632. <h3>Package directory</h3>
  633. <p>First of all, create a directory under the <code>package</code>
  634. directory for your software, for example <code>foo</code>. </p>
  635. <h3><code>Config.in</code> file</h3>
  636. <p>Then, create a file named <code>Config.in</code>. This file
  637. will contain the option descriptions related to our
  638. <code>foo</code> software that will be used and displayed in the
  639. configuration tool. It should basically contain:</p>
  640. <pre>
  641. config BR2_PACKAGE_FOO
  642. bool "foo"
  643. help
  644. This is a comment that explains what foo is.
  645. http://foosoftware.org/foo/
  646. </pre>
  647. <p>Of course, you can add other options to configure particular
  648. things in your software. </p>
  649. <p>Finally you have to add your new <code>foo/Config.in</code> to
  650. <code>package/Config.in</code>. The files included there are
  651. <em>sorted alphabetically</em> per category and are <em>NOT</em>
  652. supposed to contain anything but the <em>bare</em> name of the package.</p>
  653. <pre>
  654. source "package/procps/Config.in"
  655. </pre>
  656. <p><strong>Note:</strong><br>
  657. Generally all packages should live <em>directly</em> in the
  658. <code>package</code> directory to make it easier to find them.
  659. </p>
  660. <h3>The real Makefile</h3>
  661. <p>Finally, here's the hardest part. Create a file named
  662. <code>foo.mk</code>. It will contain the Makefile rules that
  663. are in charge of downloading, configuring, compiling and installing
  664. the software.</p>
  665. <p>Two types of Makefiles can be written&nbsp;:</p>
  666. <ul>
  667. <li>Makefiles for autotools-based (autoconf, automake, etc.)
  668. software are very easy to write thanks to the infrastructure
  669. available in <code>package/Makefile.autotools.in</code>.</li>
  670. <li>Makefiles for other types of packages are a little bit more
  671. complex to write.</li>
  672. </ul>
  673. <p>First, let's see how to write a Makefile for an
  674. autotools-based package, with an example&nbsp;:</p>
  675. <pre>
  676. <a name="ex1line1" id="ex1line1">1</a> #############################################################
  677. <a name="ex1line2" id="ex1line2">2</a> #
  678. <a name="ex1line3" id="ex1line3">3</a> # foo
  679. <a name="ex1line4" id="ex1line4">4</a> #
  680. <a name="ex1line5" id="ex1line5">5</a> #############################################################
  681. <a name="ex1line6" id="ex1line6">6</a> FOO_VERSION:=1.0
  682. <a name="ex1line7" id="ex1line7">7</a> FOO_SOURCE:=foo-$(FOO_VERSION).tar.gz
  683. <a name="ex1line8" id="ex1line8">8</a> FOO_SITE:=http://www.foosoftware.org/downloads
  684. <a name="ex1line9" id="ex1line9">9</a> FOO_INSTALL_STAGING = YES
  685. <a name="ex1line10" id="ex1line10">10</a> FOO_INSTALL_TARGET = YES
  686. <a name="ex1line11" id="ex1line11">11</a> FOO_CONF_OPT = --enable-shared
  687. <a name="ex1line12" id="ex1line12">12</a> FOO_DEPENDENCIES = libglib2 host-pkgconfig
  688. <a name="ex1line13" id="ex1line13">13</a> $(eval $(call AUTOTARGETS,package,foo))
  689. </pre>
  690. <p>On <a href="#ex1line6">line 6</a>, we declare the version of
  691. the package. On lines <a href="#ex1line7">7</a> and <a
  692. href="#ex1line8">8</a>, we declare the name of the tarball and the
  693. location of the tarball on the web. Buildroot will automatically
  694. download the tarball from this location.</p>
  695. <p>On <a href="#ex1line9">line 9</a>, we tell Buildroot to install
  696. the application to the staging directory. The staging directory,
  697. located in <code>output/staging/</code> is the directory
  698. where all the packages are installed, including their
  699. documentation, etc. By default, packages are installed in this
  700. location using the <code>make install</code> command.</p>
  701. <p>On <a href="#ex1line10">line 10</a>, we tell Buildroot to also
  702. install the application to the target directory. This directory
  703. contains what will become the root filesystem running on the
  704. target. Usually, we try to install stripped binaries and
  705. to not install the documentation. By default, packages are
  706. installed in this location using the <code>make
  707. install-strip</code> command.</p>
  708. <p>On <a href="#ex1line11">line 11</a>, we tell Buildroot to pass
  709. a custom configure option to the
  710. <code>./configure</code> script when configuring the
  711. the package.</p>
  712. <p>On <a href="#ex1line12">line 12</a>, we declare our
  713. dependencies so that they are built before the build process of
  714. our package starts.</p>
  715. <p>Finally, on line <a href="#ex1line13">line 13</a>, we invoke
  716. the <code>package/Makefile.autotools.in</code> magic to get things
  717. working.</p>
  718. <p>For more details about the available variables and options, see
  719. the comment at the top of
  720. <code>package/Makefile.autotools.in</code> and the examples in all
  721. the available packages.</p>
  722. <p>The second solution, suitable for every type of package, looks
  723. like this&nbsp;:</p>
  724. <pre>
  725. <a name="ex2line1" id="ex2line1">1</a> #############################################################
  726. <a name="ex2line2" id="ex2line2">2</a> #
  727. <a name="ex2line3" id="ex2line3">3</a> # foo
  728. <a name="ex2line4" id="ex2line4">4</a> #
  729. <a name="ex2line5" id="ex2line5">5</a> #############################################################
  730. <a name="ex2line6" id="ex2line6">6</a> FOO_VERSION:=1.0
  731. <a name="ex2line7" id="ex2line7">7</a> FOO_SOURCE:=foo-$(FOO_VERSION).tar.gz
  732. <a name="ex2line8" id="ex2line8">8</a> FOO_SITE:=http://www.foosoftware.org/downloads
  733. <a name="ex2line9" id="ex2line9">9</a> FOO_DIR:=$(BUILD_DIR)/foo-$(FOO_VERSION)
  734. <a name="ex2line10" id="ex2line10">10</a> FOO_BINARY:=foo
  735. <a name="ex2line11" id="ex2line11">11</a> FOO_TARGET_BINARY:=usr/bin/foo
  736. <a name="ex2line12" id="ex2line12">12</a>
  737. <a name="ex2line13" id="ex2line13">13</a> $(DL_DIR)/$(FOO_SOURCE):
  738. <a name="ex2line14" id="ex2line14">14</a> $(call DOWNLOAD,$(FOO_SITE),$(FOO_SOURCE))
  739. <a name="ex2line15" id="ex2line15">15</a>
  740. <a name="ex2line16" id="ex2line16">16</a> $(FOO_DIR)/.source: $(DL_DIR)/$(FOO_SOURCE)
  741. <a name="ex2line17" id="ex2line17">17</a> $(ZCAT) $(DL_DIR)/$(FOO_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
  742. <a name="ex2line18" id="ex2line18">18</a> touch $@
  743. <a name="ex2line19" id="ex2line19">19</a>
  744. <a name="ex2line20" id="ex2line20">20</a> $(FOO_DIR)/.configured: $(FOO_DIR)/.source
  745. <a name="ex2line21" id="ex2line21">21</a> (cd $(FOO_DIR); rm -rf config.cache; \
  746. <a name="ex2line22" id="ex2line22">22</a> $(TARGET_CONFIGURE_OPTS) \
  747. <a name="ex2line23" id="ex2line23">23</a> $(TARGET_CONFIGURE_ARGS) \
  748. <a name="ex2line24" id="ex2line24">24</a> ./configure \
  749. <a name="ex2line25" id="ex2line25">25</a> --target=$(GNU_TARGET_NAME) \
  750. <a name="ex2line26" id="ex2line26">26</a> --host=$(GNU_TARGET_NAME) \
  751. <a name="ex2line27" id="ex2line27">27</a> --build=$(GNU_HOST_NAME) \
  752. <a name="ex2line28" id="ex2line28">28</a> --prefix=/usr \
  753. <a name="ex2line29" id="ex2line29">29</a> --sysconfdir=/etc \
  754. <a name="ex2line30" id="ex2line30">30</a> )
  755. <a name="ex2line31" id="ex2line31">31</a> touch $@
  756. <a name="ex2line32" id="ex2line32">32</a>
  757. <a name="ex2line33" id="ex2line33">33</a> $(FOO_DIR)/$(FOO_BINARY): $(FOO_DIR)/.configured
  758. <a name="ex2line34" id="ex2line34">34</a> $(MAKE) CC=$(TARGET_CC) -C $(FOO_DIR)
  759. <a name="ex2line35" id="ex2line35">35</a>
  760. <a name="ex2line36" id="ex2line36">36</a> $(TARGET_DIR)/$(FOO_TARGET_BINARY): $(FOO_DIR)/$(FOO_BINARY)
  761. <a name="ex2line37" id="ex2line37">37</a> $(MAKE) DESTDIR=$(TARGET_DIR) -C $(FOO_DIR) install-strip
  762. <a name="ex2line38" id="ex2line38">38</a> rm -Rf $(TARGET_DIR)/usr/man
  763. <a name="ex2line39" id="ex2line39">39</a>
  764. <a name="ex2line40" id="ex2line40">40</a> foo: uclibc ncurses $(TARGET_DIR)/$(FOO_TARGET_BINARY)
  765. <a name="ex2line41" id="ex2line41">41</a>
  766. <a name="ex2line42" id="ex2line42">42</a> foo-source: $(DL_DIR)/$(FOO_SOURCE)
  767. <a name="ex2line43" id="ex2line43">43</a>
  768. <a name="ex2line44" id="ex2line44">44</a> foo-clean:
  769. <a name="ex2line45" id="ex2line45">45</a> $(MAKE) prefix=$(TARGET_DIR)/usr -C $(FOO_DIR) uninstall
  770. <a name="ex2line46" id="ex2line46">46</a> -$(MAKE) -C $(FOO_DIR) clean
  771. <a name="ex2line47" id="ex2line47">47</a>
  772. <a name="ex2line48" id="ex2line48">48</a> foo-dirclean:
  773. <a name="ex2line49" id="ex2line49">49</a> rm -rf $(FOO_DIR)
  774. <a name="ex2line50" id="ex2line50">50</a>
  775. <a name="ex2line51" id="ex2line51">51</a> #############################################################
  776. <a name="ex2line52" id="ex2line52">52</a> #
  777. <a name="ex2line53" id="ex2line53">53</a> # Toplevel Makefile options
  778. <a name="ex2line54" id="ex2line54">54</a> #
  779. <a name="ex2line55" id="ex2line55">55</a> #############################################################
  780. <a name="ex2line56" id="ex2line56">56</a> ifeq ($(BR2_PACKAGE_FOO),y)
  781. <a name="ex2line57" id="ex2line57">57</a> TARGETS+=foo
  782. <a name="ex2line58" id="ex2line58">58</a> endif
  783. </pre>
  784. <p>First of all, this Makefile example works for a package which comprises a single
  785. binary executable. For other software, such as libraries or more
  786. complex stuff with multiple binaries, it must be adapted. For examples look at
  787. the other <code>*.mk</code> files in the <code>package</code>
  788. directory. </p>
  789. <p>At lines <a href="#ex2line6">6-11</a>, a couple of useful variables are
  790. defined:</p>
  791. <ul>
  792. <li><code>FOO_VERSION</code>: The version of <i>foo</i> that
  793. should be downloaded. </li>
  794. <li><code>FOO_SOURCE</code>: The name of the tarball of
  795. <i>foo</i> on the download website or FTP site. As you can see
  796. <code>FOO_VERSION</code> is used. </li>
  797. <li><code>FOO_SITE</code>: The HTTP or FTP site from which
  798. <i>foo</i> archive is downloaded. It must include the complete
  799. path to the directory where <code>FOO_SOURCE</code> can be
  800. found. </li>
  801. <li><code>FOO_DIR</code>: The directory into which the software
  802. will be configured and compiled. Basically, it's a subdirectory
  803. of <code>BUILD_DIR</code> which is created upon decompression of
  804. the tarball. </li>
  805. <li><code>FOO_BINARY</code>: Software binary name. As said
  806. previously, this is an example for a package with a single binary.</li>
  807. <li><code>FOO_TARGET_BINARY</code>: The full path of the binary
  808. inside the target filesystem. </li>
  809. </ul>
  810. <p>Lines <a href="#ex2line13">13-14</a> define a target that downloads the
  811. tarball from the remote site to the download directory
  812. (<code>DL_DIR</code>). </p>
  813. <p>Lines <a href="#ex2line16">16-18</a> define a target and associated rules
  814. that uncompress the downloaded tarball. As you can see, this target
  815. depends on the tarball file so that the previous target (lines
  816. <a href="#ex2line13">13-14</a>) is called before executing the rules of the
  817. current target. Uncompressing is followed by <i>touching</i> a hidden file
  818. to mark the software as having been uncompressed. This trick is
  819. used everywhere in a Buildroot Makefile to split steps
  820. (download, uncompress, configure, compile, install) while still
  821. having correct dependencies. </p>
  822. <p>Lines <a href="#ex2line20">20-31</a> define a target and associated rules
  823. that configure the software. It depends on the previous target (the
  824. hidden <code>.source</code> file) so that we are sure the software has
  825. been uncompressed. In order to configure the package, it basically runs the
  826. well-known <code>./configure</code> script. As we may be doing
  827. cross-compilation, <code>target</code>, <code>host</code> and
  828. <code>build</code> arguments are given. The prefix is also set to
  829. <code>/usr</code>, not because the software will be installed in
  830. <code>/usr</code> on your host system, but because the software will
  831. bin installed in <code>/usr</code> on the target
  832. filesystem. Finally it creates a <code>.configured</code> file to
  833. mark the software as configured. </p>
  834. <p>Lines <a href="#ex2line33">33-34</a> define a target and a rule that
  835. compile the software. This target will create the binary file in the
  836. compilation directory and depends on the software being already
  837. configured (hence the reference to the <code>.configured</code>
  838. file). It basically runs <code>make</code> inside the source
  839. directory. </p>
  840. <p>Lines <a href="#ex2line36">36-38</a> define a target and associated rules
  841. that install the software inside the target filesystem. They depend on the
  842. binary file in the source directory to make sure the software has
  843. been compiled. They use the <code>install-strip</code> target of the
  844. software <code>Makefile</code> by passing a <code>DESTDIR</code>
  845. argument so that the <code>Makefile</code> doesn't try to install
  846. the software in the host <code>/usr</code> but rather in the target
  847. <code>/usr</code>. After the installation, the
  848. <code>/usr/man</code> directory inside the target filesystem is
  849. removed to save space. </p>
  850. <p>Line <a href="#ex2line40">40</a> defines the main target of the software &mdash;
  851. the one that will be eventually be used by the top level
  852. <code>Makefile</code> to download, compile, and then install
  853. this package. This target should first of all depend on all
  854. needed dependencies of the software (in our example,
  855. <i>uclibc</i> and <i>ncurses</i>) and also depend on the
  856. final binary. This last dependency will call all previous
  857. dependencies in the correct order. </p>
  858. <p>Line <a href="#ex2line42">42</a> defines a simple target that only
  859. downloads the code source. This is not used during normal operation of
  860. Buildroot, but is needed if you intend to download all required sources at
  861. once for later offline build. Note that if you add a new package providing
  862. a <code>foo-source</code> target is <i>mandatory</i> to support
  863. users that wish to do offline-builds. Furthermore it eases checking
  864. if all package-sources are downloadable. </p>
  865. <p>Lines <a href="#ex2line44">44-46</a> define a simple target to clean the
  866. software build by calling the Makefiles with the appropriate option.
  867. The <code>-clean</code> target should run <code>make clean</code>
  868. on $(BUILD_DIR)/package-version and MUST uninstall all files of the
  869. package from $(STAGING_DIR) and from $(TARGET_DIR). </p>
  870. <p>Lines <a href="#ex2line48">48-49</a> define a simple target to completely
  871. remove the directory in which the software was uncompressed, configured and
  872. compiled. The <code>-dirclean</code> target MUST completely rm $(BUILD_DIR)/
  873. package-version. </p>
  874. <p>Lines <a href="#ex2line51">51-58</a> add the target <code>foo</code> to
  875. the list of targets to be compiled by Buildroot by first checking if
  876. the configuration option for this package has been enabled
  877. using the configuration tool. If so, it then &quot;subscribes&quot;
  878. this package to be compiled by adding the package to the TARGETS
  879. global variable. The name added to the TARGETS global
  880. variable is the name of this package's target, as defined on
  881. line <a href="#ex2line40">40</a>, which is used by Buildroot to download,
  882. compile, and then install this package. </p>
  883. <h3>Conclusion</h3>
  884. <p>As you can see, adding a software package to Buildroot is simply a
  885. matter of writing a Makefile using an existing
  886. example and modifying it according to the compilation process required by
  887. the package. </p>
  888. <p>If you package software that might be useful for other people,
  889. don't forget to send a patch to Buildroot developers!</p>
  890. <h2><a name="links" id="links"></a>Resources</h2>
  891. <p>To learn more about Buildroot you can visit these
  892. websites:</p>
  893. <ul>
  894. <li><a href="http://www.uclibc.org/">http://www.uclibc.org/</a></li>
  895. <li><a href="http://www.busybox.net/">http://www.busybox.net/</a></li>
  896. </ul>
  897. </div>
  898. <!--
  899. <a href="http://validator.w3.org/check?uri=referer"><img
  900. border="0" height="31" width="88"
  901. src="images/valid-html401.png"
  902. alt="Valid HTML"></img></a>
  903. -->
  904. </body>
  905. </html>