buildroot.html 52 KB

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