buildroot.html 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  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. <li>BUILDROOT_USE_XWINDOWS</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/</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><b>BACKGROUND</b></p>
  424. <p>Buildroot has always supported building several projects in the same
  425. tree if each project was for a different architecture. </p>
  426. <p>The root file system has been created in the
  427. <code>&quot;build_&lt;ARCH&gt;/root&quot;</code>
  428. directory which is unique for each architecture.
  429. Toolchains have been built in
  430. <code>&quot;toolchain_build_&lt;ARCH&gt;&quot;</code>. </p>
  431. <p> It the user wanted to build several root file systems for the same
  432. architecture, a prefix or suffix could be added in the configuration file
  433. so the root file system would be built in
  434. <code>&quot;&lt;PREFIX&gt;_build_&lt;ARCH&gt;_&lt;SUFFIX&gt;/root&quot;</code>
  435. By supplying <u>unique</u> combinations of
  436. <code>&quot;&lt;PREFIX&gt;&quot;</code> and
  437. <code>&quot;&lt;SUFFIX&gt;&quot;</code>
  438. each project would get a <u>unique</u> root file system tree. </p>
  439. <p>The disadvantage of this approach is that a new toolchain was
  440. built for each project, adding considerable time to the build
  441. process, even if it was two projects for the same chip. </p>
  442. <p>This drawback has been somewhat lessened with
  443. <code>gcc-4.x.y</code> which allows buildroot to use an external
  444. toolchain. Certain packages requires special
  445. features in the toolchain, and if an external toolchain is selected,
  446. this may lack the neccessary features to complete the build of the root
  447. file system.</p>
  448. <p>A bigger problem was that the
  449. <code>&quot;build_&lt;ARCH&gt;&quot;</code> tree
  450. was also duplicated, so each </code>package</code> would also
  451. be rebuilt once per project, resulting in even longer build times.</p>
  452. <p><b>PROJECT TO SHARE TOOLCHAIN AND PACKAGE BUILDS</b></p>
  453. <p>Work has started on a project which will allow the user to build
  454. multiple root file systems for the same architecture in the same tree.
  455. The toolchain and the package build directory will be shared, but each
  456. project will have a dedicated directory tree for project specific
  457. builds. </p>
  458. <p>With this approach, most, if not all packages will be compiled
  459. when the first project is built.
  460. The process is almost identical to the original process.
  461. Packages are downloaded and extracted to the shared
  462. <code>&quot;build_&lt;ARCH&gt;/&lt;package&gt;&quot;</code>
  463. directory. They are configured and compiled. </p>
  464. <p>Package libraries and headers are installed in the shared $(STAGING_DIR),
  465. and then the project specific root file system &quot;$(TARGET_DIR)&quot;
  466. is populated. </p>
  467. <p>At the end of the build, the root file system will be used
  468. to generate the resulting root file system binaries. </p>
  469. <p>Once the first project has been built, building other projects will
  470. typically involve populating the new project's root file system directory
  471. from the existing binaries generated in the shared
  472. <code>&quot;build_&lt;ARCH&gt;/&lt;&gt;&quot;</code> directory. </p>
  473. <p>Only packages, not used by the first project, will have to go
  474. through the normal extract-configure-compile flow. </p>
  475. <p><b>IMPLEMENTATION</b></p>
  476. <p>The core of the solution is the introduction
  477. of two new directories: </p>
  478. <ul>
  479. <li><code>project_build_&lt;ARCH&gt;</code></li>
  480. <li><code>binaries;</code></li>
  481. </ul>
  482. <p>Each of the directories contain one subdirectory per project.
  483. The name of the subdirectory is configured by the user in the
  484. normal buildroot configuration, using the value of: </p>
  485. <p><code>Project Options ---> Project name</code></p>
  486. <p>The configuration defines the $(PROJECT) variable.</p>
  487. <p>The default project name is <code>&quot;uclibc&quot;</code>.</p>
  488. <p><code>&quot;package/Makefile.in&quot;</code> defines:
  489. <pre>
  490. <code>PROJECT_BUILD_DIR:=project_build_$(ARCH)/$(PROJECT)</code>
  491. <code>BINARIES_DIR:=binaries/$(PROJECT)</code>
  492. </pre>
  493. </p>
  494. <p>It also defines the location for the target root file system:
  495. <pre>
  496. <code>TARGET_DIR:=$(PROJECT_BUILD_DIR)/$(PROJECT)/root</code>
  497. </pre>
  498. </p>
  499. <p>I.E: If the user has choosen
  500. <code>&quot;myproject&quot;</code>
  501. as the $(PROJECT) name:
  502. <ul>
  503. <li><code>&quot;project_build_&lt;ARCH&gt;/myproject&quot;</code></li>
  504. <li><code>&quot;binaries/myproject&quot;</code></li>
  505. </ul>
  506. <p>will be created. </p>
  507. <p>Currently, the <u>root file system</u>, <u>busybox</u> and an Atmel
  508. customized version of
  509. <u><code>U-Boot</code></u>, as well as some Atmel specific
  510. bootloaders like <u>at91-bootstrap</u> and <u>dataflashboot.bin</u>
  511. are built in
  512. <code>&quot;$(PROJECT_BUILD_DIR)&quot;</code>
  513. <p>The resulting binaries for all architectures are stored in the
  514. <code>&quot;$(BINARIES_DIR)&quot;</code> directory. <p>
  515. <p><b>SUMMARY</b></p>
  516. <p>The project will share directories which can be share without
  517. conflicts, but will use unique build directories, where the user
  518. can configure the build. </p>
  519. <h2><a name="Linux" id="Linux"></a>Linux</h2>
  520. <ol>
  521. <p>The user can select from three different Linux strategies:
  522. <ul>
  523. <li>Legacy: Only use version supported by the kernel headers</li>
  524. <li>Advanced: Allow any 2.6.X.Y combination.
  525. (Minimum 2.6.19)</li>
  526. <li>Power-User Strategy: Allow
  527. <code>&quot;-git&quot;</code>, or
  528. <code>&quot;-mm&quot;</code>, or user downloadable kernels</li>
  529. </ul>
  530. <p>The current kernel patches can be applied to the
  531. linux source tree even if the version differs from the
  532. kernel header version. </p>
  533. <p>Since the user can select any kernel-patch
  534. he/she will be able to select a non-working combination.
  535. If the patch fails, the user will have to generate a new
  536. proprietary kernel-patch or decide to not apply the kernel
  537. patches</p>
  538. <p>There is also support for <u>board specific</u> and
  539. <u>architecture specific</u> patches. </p>
  540. <p>There will also be a way for the user to supply absolute
  541. or relative paths to patches, possibly outside the main tree.
  542. This can be used to apply custom kernel-header-patches, if
  543. the versions available in buildroot cannot be applied to the
  544. specific linux version used</p>
  545. <p>Maybe, there will also be a possibility to supply an
  546. <code>&quot;URL&quot;</code> to a patch available on Internet. </p>
  547. <p>
  548. If there is no linux config file available,
  549. buildroot starts the linux configuration system, which
  550. defaults to "make menuconfig".
  551. </p>
  552. </ol>
  553. <h2><a name="Todo" id="Todo"></a>Todo</h2>
  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</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 the default toolchain directory
  634. doesn't suit your needs, please refer to the <a
  635. href="#toolchain_standalone">Using the uClibc toolchain outside of
  636. buildroot</a> section. </p>
  637. <p>If you are using a current gcc-4.x, then use --sysroot and -isysroot
  638. since these toolchains have fully functional sysroot support. No
  639. hardcoded paths do exist in these configurations. </p>
  640. <h2><a name="toolchain_standalone" id="toolchain_standalone"></a>Using the
  641. uClibc toolchain outside of buildroot</h2>
  642. <p>By default, the cross-compilation toolchain is generated inside
  643. <code>build_ARCH/staging_dir/</code>. But sometimes, it may be useful to
  644. install it somewhere else, so that it can be used to compile other programs
  645. or by other users. Moving the <code>build_ARCH/staging_dir/</code>
  646. directory elsewhere is <b>not possible if using gcc-3.x</b>, because there
  647. are some hardcoded paths in the toolchain configuration. This works, thanks
  648. to sysroot support, with current, stable gcc-4.x toolchains, of course. </p>
  649. <p>If you want to use the generated gcc-3.x toolchain for other purposes,
  650. you can configure Buildroot to generate it elsewhere using the
  651. option of the configuration tool : <code>Build options -&gt;
  652. Toolchain and header file location</code>, which defaults to
  653. <code>$(BUILD_DIR)/staging_dir/</code>. </p>
  654. <h2><a name="downloaded_packages"
  655. id="downloaded_packages"></a>Location of downloaded packages</h2>
  656. <p>It might be useful to know that the various tarballs that are
  657. downloaded by the <i>Makefiles</i> are all stored in the
  658. <code>DL_DIR</code> which by default is the <code>dl</code>
  659. directory. It's useful for example if you want to keep a complete
  660. version of Buildroot which is know to be working with the
  661. associated tarballs. This will allow you to regenerate the
  662. toolchain and the target filesystem with exactly the same
  663. versions. </p>
  664. <p>If you maintain several buildroot trees, it might be better to have
  665. a shared download location. This can be accessed by creating a symbolic link
  666. from the <code>dl</code> directory to the shared download location. </p>
  667. <p>I.E:</p>
  668. <pre>
  669. ln -s &lt;shared download location&gt; dl
  670. </pre>
  671. <p>Another way of accessing a shared download location is to
  672. create the <code>BUILDROOT_DL_DIR</code> environment variable.
  673. If this is set, then the value of DL_DIR in the project is
  674. overridden. The following line should be added to
  675. <code>&quot;~/.bashrc&quot;</code>. <p>
  676. <pre>
  677. export BUILDROOT_DL_DIR &lt;shared download location&gt;
  678. </pre>
  679. <h2><a name="add_software" id="add_software"></a>Extending Buildroot with
  680. more software</h2>
  681. <p>This section will only consider the case in which you want to
  682. add user-space software. </p>
  683. <h3>Package directory</h3>
  684. <p>First of all, create a directory under the <code>package</code>
  685. directory for your software, for example <code>foo</code>. </p>
  686. <h3><code>Config.in</code> file</h3>
  687. <p>Then, create a file named <code>Config.in</code>. This file
  688. will contain the portion of options description related to our
  689. <code>foo</code> software that will be used and displayed in the
  690. configuration tool. It should basically contain :</p>
  691. <pre>
  692. config BR2_PACKAGE_FOO
  693. bool "foo"
  694. help
  695. This is a comment that explains what foo is.
  696. http://foosoftware.org/foo/
  697. </pre>
  698. <p>Of course, you can add other options to configure particular
  699. things in your software. </p>
  700. <p>Finally you have to add your new <code>foo/Config.in</code> to
  701. <code>package/Config.in</code>. The files included there are
  702. <em>sorted alphabetically</em> per category and are <em>NOT</em>
  703. supposed to contain anything but the <em>bare</em> name of the package.</p>
  704. <pre>
  705. if !BR2_PACKAGE_BUSYBOX_HIDE_OTHERS
  706. source "package/procps/Config.in"
  707. endif
  708. </pre>
  709. <p><strong>Note:</strong><br>
  710. Generally all packages should live <em>directly</em> in the
  711. <code>package</code> directory to make it easier to find them.
  712. </p>
  713. <h3>The real <i>Makefile</i></h3>
  714. <p>Finally, here's the hardest part. Create a file named
  715. <code>foo.mk</code>. It will contain the <i>Makefile</i> rules that
  716. are in charge of downloading, configuring, compiling and installing
  717. the software.</p>
  718. <p>Two types of <i>Makefiles</i> can be written&nbsp;:</p>
  719. <ul>
  720. <li>Makefiles for autotools-based (autoconf, automake, etc.)
  721. softwares, are very easy to write thanks to the infrastructure
  722. available in <code>package/Makefile.autotools.in</code>.</li>
  723. <li>Makefiles for other types of packages are a little bit more
  724. complex to write.</li>
  725. </ul>
  726. <p>First, let's see how to write a <i>Makefile</i> for an
  727. autotools-based package, with an example&nbsp;:</p>
  728. <pre>
  729. <a name="ex1line1" id="ex1line1">1</a> #############################################################
  730. <a name="ex1line2" id="ex1line2">2</a> #
  731. <a name="ex1line3" id="ex1line3">3</a> # foo
  732. <a name="ex1line4" id="ex1line4">4</a> #
  733. <a name="ex1line5" id="ex1line5">5</a> #############################################################
  734. <a name="ex1line6" id="ex1line6">6</a> FOO_VERSION:=1.0
  735. <a name="ex1line7" id="ex1line7">7</a> FOO_SOURCE:=foo-$(FOO_VERSION).tar.gz
  736. <a name="ex1line8" id="ex1line8">8</a> FOO_SITE:=http://www.foosoftware.org/downloads
  737. <a name="ex1line9" id="ex1line9">9</a> FOO_INSTALL_STAGING = YES
  738. <a name="ex1line10" id="ex1line10">10</a> FOO_INSTALL_TARGET = YES
  739. <a name="ex1line11" id="ex1line11">11</a> FOO_CONF_OPT = --enable-shared
  740. <a name="ex1line12" id="ex1line12">12</a> FOO_DEPENDENCIES = libglib2 pkgconfig
  741. <a name="ex1line13" id="ex1line13">13</a> $(eval $(call AUTOTARGETS,package,foo))
  742. </pre>
  743. <p>On <a href="#ex1line6">line 6</a>, we declare the version of
  744. the package. On line <a href="#ex1line7">7</a> and <a
  745. href="#ex1line8">8</a>, we declare the name of the tarball and the
  746. location of the tarball on the Web. Buildroot will automatically
  747. download the tarball from this location.</p>
  748. <p>On <a href="#ex1line9">line 9</a>, we tell Buildroot to install
  749. the application to the staging directory. The staging directory,
  750. located in <code>build_ARCH/staging_dir/</code> is the directory
  751. where all the packages are installed, including their
  752. documentation, etc. By default, packages are installed in this
  753. location using the <code>make install</code> command.</p>
  754. <p>On <a href="#ex1line10">line 10</a>, we tell Buildroot to also
  755. install the application to the target directory. This directory
  756. contains what will become the root filesystem running on the
  757. target. Usually, we try not to install the documentation, and to
  758. install stripped versions of the binary. By default, packages are
  759. installed in this location using the <code>make
  760. install-strip</code> command.</p>
  761. <p>On <a href="#ex1line11">line 11</a>, we tell Buildroot to pass
  762. a custom configure option, that will be passed to the
  763. <code>./configure</code> script before configuring and building
  764. the package.</p>
  765. <p>On <a href="#ex1line12">line 12</a>, we declare our
  766. dependencies, so that they are built before the build process of
  767. our package starts.</p>
  768. <p>Finally, on line <a href="#ex1line13">line 13</a>, we invoke
  769. the <code>package/Makefile.autotools.in</code> magic to get things
  770. working.</p>
  771. <p>For more details about the available variables and options, see
  772. the comment at the top of
  773. <code>package/Makefile.autotools.in</code> and the examples in all
  774. the available packages.</p>
  775. <p>The second solution, suitable for every type of package, looks
  776. like this&nbsp;:</p>
  777. <pre>
  778. <a name="ex2line1" id="ex2line1">1</a> #############################################################
  779. <a name="ex2line2" id="ex2line2">2</a> #
  780. <a name="ex2line3" id="ex2line3">3</a> # foo
  781. <a name="ex2line4" id="ex2line4">4</a> #
  782. <a name="ex2line5" id="ex2line5">5</a> #############################################################
  783. <a name="ex2line6" id="ex2line6">6</a> FOO_VERSION:=1.0
  784. <a name="ex2line7" id="ex2line7">7</a> FOO_SOURCE:=foo-$(FOO_VERSION).tar.gz
  785. <a name="ex2line8" id="ex2line8">8</a> FOO_SITE:=http://www.foosoftware.org/downloads
  786. <a name="ex2line9" id="ex2line9">9</a> FOO_DIR:=$(BUILD_DIR)/foo-$(FOO_VERSION)
  787. <a name="ex2line10" id="ex2line10">10</a> FOO_BINARY:=foo
  788. <a name="ex2line11" id="ex2line11">11</a> FOO_TARGET_BINARY:=usr/bin/foo
  789. <a name="ex2line12" id="ex2line12">12</a>
  790. <a name="ex2line13" id="ex2line13">13</a> $(DL_DIR)/$(FOO_SOURCE):
  791. <a name="ex2line14" id="ex2line14">14</a> $(call DOWNLOAD,$(FOO_SITE),$(FOO_SOURCE))
  792. <a name="ex2line15" id="ex2line15">15</a>
  793. <a name="ex2line16" id="ex2line16">16</a> $(FOO_DIR)/.source: $(DL_DIR)/$(FOO_SOURCE)
  794. <a name="ex2line17" id="ex2line17">17</a> $(ZCAT) $(DL_DIR)/$(FOO_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
  795. <a name="ex2line18" id="ex2line18">18</a> touch $@
  796. <a name="ex2line19" id="ex2line19">19</a>
  797. <a name="ex2line20" id="ex2line20">20</a> $(FOO_DIR)/.configured: $(FOO_DIR)/.source
  798. <a name="ex2line21" id="ex2line21">21</a> (cd $(FOO_DIR); rm -rf config.cache; \
  799. <a name="ex2line22" id="ex2line22">22</a> $(TARGET_CONFIGURE_OPTS) \
  800. <a name="ex2line23" id="ex2line23">23</a> $(TARGET_CONFIGURE_ARGS) \
  801. <a name="ex2line24" id="ex2line24">24</a> ./configure \
  802. <a name="ex2line25" id="ex2line25">25</a> --target=$(GNU_TARGET_NAME) \
  803. <a name="ex2line26" id="ex2line26">26</a> --host=$(GNU_TARGET_NAME) \
  804. <a name="ex2line27" id="ex2line27">27</a> --build=$(GNU_HOST_NAME) \
  805. <a name="ex2line28" id="ex2line28">28</a> --prefix=/usr \
  806. <a name="ex2line29" id="ex2line29">29</a> --sysconfdir=/etc \
  807. <a name="ex2line30" id="ex2line30">30</a> )
  808. <a name="ex2line31" id="ex2line31">31</a> touch $@
  809. <a name="ex2line32" id="ex2line32">32</a>
  810. <a name="ex2line33" id="ex2line33">33</a> $(FOO_DIR)/$(FOO_BINARY): $(FOO_DIR)/.configured
  811. <a name="ex2line34" id="ex2line34">34</a> $(MAKE) CC=$(TARGET_CC) -C $(FOO_DIR)
  812. <a name="ex2line35" id="ex2line35">35</a>
  813. <a name="ex2line36" id="ex2line36">36</a> $(TARGET_DIR)/$(FOO_TARGET_BINARY): $(FOO_DIR)/$(FOO_BINARY)
  814. <a name="ex2line37" id="ex2line37">37</a> $(MAKE) DESTDIR=$(TARGET_DIR) -C $(FOO_DIR) install-strip
  815. <a name="ex2line38" id="ex2line38">38</a> rm -Rf $(TARGET_DIR)/usr/man
  816. <a name="ex2line39" id="ex2line39">39</a>
  817. <a name="ex2line40" id="ex2line40">40</a> foo: uclibc ncurses $(TARGET_DIR)/$(FOO_TARGET_BINARY)
  818. <a name="ex2line41" id="ex2line41">41</a>
  819. <a name="ex2line42" id="ex2line42">42</a> foo-source: $(DL_DIR)/$(FOO_SOURCE)
  820. <a name="ex2line43" id="ex2line43">43</a>
  821. <a name="ex2line44" id="ex2line44">44</a> foo-clean:
  822. <a name="ex2line45" id="ex2line45">45</a> $(MAKE) prefix=$(TARGET_DIR)/usr -C $(FOO_DIR) uninstall
  823. <a name="ex2line46" id="ex2line46">46</a> -$(MAKE) -C $(FOO_DIR) clean
  824. <a name="ex2line47" id="ex2line47">47</a>
  825. <a name="ex2line48" id="ex2line48">48</a> foo-dirclean:
  826. <a name="ex2line49" id="ex2line49">49</a> rm -rf $(FOO_DIR)
  827. <a name="ex2line50" id="ex2line50">50</a>
  828. <a name="ex2line51" id="ex2line51">51</a> #############################################################
  829. <a name="ex2line52" id="ex2line52">52</a> #
  830. <a name="ex2line53" id="ex2line53">53</a> # Toplevel Makefile options
  831. <a name="ex2line54" id="ex2line54">54</a> #
  832. <a name="ex2line55" id="ex2line55">55</a> #############################################################
  833. <a name="ex2line56" id="ex2line56">56</a> ifeq ($(BR2_PACKAGE_FOO),y)
  834. <a name="ex2line57" id="ex2line57">57</a> TARGETS+=foo
  835. <a name="ex2line58" id="ex2line58">58</a> endif
  836. </pre>
  837. <p>First of all, this <i>Makefile</i> example works for a single
  838. binary software. For other software such as libraries or more
  839. complex stuff with multiple binaries, it should be adapted. Look at
  840. the other <code>*.mk</code> files in the <code>package</code>
  841. directory. </p>
  842. <p>At lines <a href="#ex2line6">6-11</a>, a couple of useful variables are
  843. defined :</p>
  844. <ul>
  845. <li><code>FOO_VERSION</code> : The version of <i>foo</i> that
  846. should be downloaded. </li>
  847. <li><code>FOO_SOURCE</code> : The name of the tarball of
  848. <i>foo</i> on the download website of FTP site. As you can see
  849. <code>FOO_VERSION</code> is used. </li>
  850. <li><code>FOO_SITE</code> : The HTTP or FTP site from which
  851. <i>foo</i> archive is downloaded. It must include the complete
  852. path to the directory where <code>FOO_SOURCE</code> can be
  853. found. </li>
  854. <li><code>FOO_DIR</code> : The directory into which the software
  855. will be configured and compiled. Basically, it's a subdirectory
  856. of <code>BUILD_DIR</code> which is created upon decompression of
  857. the tarball. </li>
  858. <li><code>FOO_BINARY</code> : Software binary name. As said
  859. previously, this is an example for a single binary software. </li>
  860. <li><code>FOO_TARGET_BINARY</code> : The full path of the binary
  861. inside the target filesystem. </li>
  862. </ul>
  863. <p>Lines <a href="#ex2line13">13-14</a> defines a target that downloads the
  864. tarball from the remote site to the download directory
  865. (<code>DL_DIR</code>). </p>
  866. <p>Lines <a href="#ex2line16">16-18</a> defines a target and associated rules
  867. that uncompress the downloaded tarball. As you can see, this target
  868. depends on the tarball file, so that the previous target (line
  869. <a href="#ex2line13">13-14</a>) is called before executing the rules of the
  870. current target. Uncompressing is followed by <i>touching</i> a hidden file
  871. to mark the software has having been uncompressed. This trick is
  872. used everywhere in Buildroot <i>Makefile</i> to split steps
  873. (download, uncompress, configure, compile, install) while still
  874. having correct dependencies. </p>
  875. <p>Lines <a href="#ex2line20">20-31</a> defines a target and associated rules
  876. that configures the software. It depends on the previous target (the
  877. hidden <code>.source</code> file) so that we are sure the software has
  878. been uncompressed. In order to configure it, it basically runs the
  879. well-known <code>./configure</code> script. As we may be doing
  880. cross-compilation, <code>target</code>, <code>host</code> and
  881. <code>build</code> arguments are given. The prefix is also set to
  882. <code>/usr</code>, not because the software will be installed in
  883. <code>/usr</code> on your host system, but in the target
  884. filesystem. Finally it creates a <code>.configured</code> file to
  885. mark the software as configured. </p>
  886. <p>Lines <a href="#ex2line33">33-34</a> defines a target and a rule that
  887. compiles the software. This target will create the binary file in the
  888. compilation directory, and depends on the software being already
  889. configured (hence the reference to the <code>.configured</code>
  890. file). It basically runs <code>make</code> inside the source
  891. directory. </p>
  892. <p>Lines <a href="#ex2line36">36-38</a> defines a target and associated rules
  893. that install the software inside the target filesystem. It depends on the
  894. binary file in the source directory, to make sure the software has
  895. been compiled. It uses the <code>install-strip</code> target of the
  896. software <code>Makefile</code> by passing a <code>DESTDIR</code>
  897. argument, so that the <code>Makefile</code> doesn't try to install
  898. the software inside host <code>/usr</code> but inside target
  899. <code>/usr</code>. After the installation, the
  900. <code>/usr/man</code> directory inside the target filesystem is
  901. removed to save space. </p>
  902. <p>Line <a href="#ex2line40">40</a> defines the main target of the software,
  903. the one that will be eventually be used by the top level
  904. <code>Makefile</code> to download, compile, and then install
  905. this package. This target should first of all depends on all
  906. needed dependecies of the software (in our example,
  907. <i>uclibc</i> and <i>ncurses</i>), and also depend on the
  908. final binary. This last dependency will call all previous
  909. dependencies in the correct order. </p>
  910. <p>Line <a href="#ex2line42">42</a> defines a simple target that only
  911. downloads the code source. This is not used during normal operation of
  912. Buildroot, but is needed if you intend to download all required sources at
  913. once for later offline build. Note that if you add a new package providing
  914. a <code>foo-source</code> target is <i>mandatory</i> to support
  915. users that wish to do offline-builds. Furthermore it eases checking
  916. if all package-sources are downloadable. </p>
  917. <p>Lines <a href="#ex2line44">44-46</a> define a simple target to clean the
  918. software build by calling the <i>Makefiles</i> with the appropriate option.
  919. The <code>-clean</code> target should run <code>make clean</code>
  920. on $(BUILD_DIR)/package-version and MUST uninstall all files of the
  921. package from $(STAGING_DIR) and from $(TARGET_DIR). </p>
  922. <p>Lines <a href="#ex2line48">48-49</a> define a simple target to completely
  923. remove the directory in which the software was uncompressed, configured and
  924. compiled. The <code>-dirclean</code> target MUST completely rm $(BUILD_DIR)/
  925. package-version. </p>
  926. <p>Lines <a href="#ex2line51">51-58</a> adds the target <code>foo</code> to
  927. the list of targets to be compiled by Buildroot by first checking if
  928. the configuration option for this package has been enabled
  929. using the configuration tool, and if so then &quot;subscribes&quot;
  930. this package to be compiled by adding it to the TARGETS
  931. global variable. The name added to the TARGETS global
  932. variable is the name of this package's target, as defined on
  933. line <a href="#ex2line40">40</a>, which is used by Buildroot to download,
  934. compile, and then install this package. </p>
  935. <h3>Conclusion</h3>
  936. <p>As you can see, adding a software to buildroot is simply a
  937. matter of writing a <i>Makefile</i> using an already existing
  938. example and to modify it according to the compilation process of
  939. the software. </p>
  940. <p>If you package software that might be useful for other persons,
  941. don't forget to send a patch to Buildroot developers !</p>
  942. <h2><a name="links" id="links"></a>Resources</h2>
  943. <p>To learn more about Buildroot you can visit these
  944. websites:</p>
  945. <ul>
  946. <li><a href="http://www.uclibc.org/">http://www.uclibc.org/</a></li>
  947. <li><a href="http://www.busybox.net/">http://www.busybox.net/</a></li>
  948. </ul>
  949. </div>
  950. <!--
  951. <a href="http://validator.w3.org/check?uri=referer"><img
  952. border="0" height="31" width="88"
  953. src="images/valid-html401.png"
  954. alt="Valid HTML"></img></a>
  955. -->
  956. </body>
  957. </html>