2
1

buildroot.html 52 KB

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