buildroot.html 54 KB

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