buildroot.html 53 KB

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