buildroot.html 52 KB

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