buildroot.html 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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> usage and documentation by Thomas Petazzoni. Contributions from
  16. Karsten Kruse, Ned Ludd, Martin Herren and others.</p>
  17. <p><small>$LastChangedDate$</small></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="#using_toolchain">Using the uClibc toolchain</a></li>
  29. <li><a href="#toolchain_standalone">Using the uClibc toolchain
  30. outside of Buildroot</a></li>
  31. <li><a href="#downloaded_packages">Location of downloaded packages</a></li>
  32. <li><a href="#add_software">Extending Buildroot with more
  33. Software</a></li>
  34. <li><a href="#links">Resources</a></li>
  35. </ul>
  36. <h2><a name="about" id="about"></a>About Buildroot</h2>
  37. <p>Buildroot is a set of Makefiles and patches that allow to easily
  38. generate both a cross-compilation toolchain and a root filesystem for your
  39. target. The cross-compilation toolchain uses uClibc (<a href=
  40. "http://www.uclibc.org/">http://www.uclibc.org/</a>), a tiny C standard
  41. library.</p>
  42. <p>Buildroot is useful mainly for people working with embedded systems.
  43. Embedded systems often use processors that are not the regular x86
  44. processors everyone is used to have on his PC. It can be PowerPC
  45. processors, MIPS processors, ARM processors, etc.</p>
  46. <p>A compilation toolchain is the set of tools that allows to
  47. compile code for your system. It consists of a compiler (in our
  48. case, <code>gcc</code>), binary utils like assembler and linker
  49. (in our case, <code>binutils</code>) and a C standard library (for
  50. example <a href="http://www.gnu.org/software/libc/libc.html">GNU
  51. Libc</a>, <a href="http://www.uclibc.org/">uClibc</a> or <a
  52. href="http://www.fefe.de/dietlibc/">dietlibc</a>). The system
  53. installed on your development station certainly already has a
  54. compilation toolchain that you can use to compile application that
  55. runs on your system. If you're using a PC, your compilation
  56. toolchain runs on an x86 processor and generates code for a x86
  57. processor. Under most Linux systems, the compilation toolchain
  58. uses the GNU libc as C standard library. This compilation
  59. toolchain is called the &quot;host compilation toolchain&quot;, and more
  60. generally, the machine on which it is running, and on which you're
  61. working is called the &quot;host system&quot;. The compilation toolchain is
  62. provided by your distribution, and Buildroot has nothing to do
  63. with it.</p>
  64. <p>As said above, the compilation toolchain that comes with your system
  65. runs and generates code for the processor of your host system. As your
  66. embedded system has a different processor, you need a cross-compilation
  67. toolchain: it's a compilation toolchain that runs on your host system but
  68. that generates code for your target system (and target processor). For
  69. example, if your host system uses x86 and your target system uses ARM, the
  70. regular compilation toolchain of your host runs on x86 and generates code
  71. for x86, while the cross-compilation toolchain runs on x86 and generates
  72. code for ARM.</p>
  73. <p>Even if your embedded system uses a x86 processor, you might interested
  74. in Buildroot, for two reasons:</p>
  75. <ul>
  76. <li>The compilation toolchain of your host certainly uses the GNU Libc
  77. which is a complete but huge C standard library. Instead of using GNU
  78. Libc on your target system, you can use uClibc which is a tiny C standard
  79. library. If you want to use this C library, then you need a compilation
  80. toolchain to generate binaries linked with it. Buildroot can do it for
  81. you.</li>
  82. <li>Buildroot automates the building of a root filesystem with all needed
  83. tools like busybox. It makes it much easier than doing it by hand.</li>
  84. </ul>
  85. <p>You might wonder why such a tool is needed when you can compile
  86. <code>gcc</code>, <code>binutils</code>, uClibc and all the tools by hand.
  87. Of course, doing so is possible. But dealing with all configure options,
  88. with all problems of every <code>gcc</code> or <code>binutils</code>
  89. version it very time-consuming and uninteresting. Buildroot automates this
  90. process through the use of Makefiles, and has a collection of patches for
  91. each <code>gcc</code> and <code>binutils</code> version to make them work
  92. on most architectures.</p>
  93. <h2><a name="download" id="download"></a>Obtaining Buildroot</h2>
  94. <p>Buildroot is available as daily SVN snapshots or directly using
  95. SVN.</p>
  96. <p>The latest snapshot is always available at <a
  97. href="http://buildroot.uclibc.org/downloads/snapshots/buildroot-snapshot.tar.bz2">http://buildroot.uclibc.org/downloads/snapshots/buildroot-snapshot.tar.bz2</a>,
  98. and previous snapshots are also available at <a
  99. href="http://buildroot.uclibc.org/downloads/snapshots/">http://buildroot.uclibc.org/downloads/snapshots/</a>.</p>
  100. <p>To download Buildroot using SVN, you can simply follow
  101. the rules described on the &quot;Accessing SVN&quot;-page (<a href=
  102. "http://buildroot.uclibc.org/subversion.html">http://buildroot.uclibc.org/subversion.html</a>)
  103. of the uClibc buildroot website (<a href=
  104. "http://buildroot.uclibc.org">http://buildroot.uclibc.org</a>), and download the
  105. <code>buildroot</code> SVN module. For the impatient, here's a quick
  106. recipe:</p>
  107. <pre>
  108. $ svn co svn://uclibc.org/trunk/buildroot
  109. </pre>
  110. <h2><a name="using" id="using"></a>Using Buildroot</h2>
  111. <p>Buildroot has a nice configuration tool similar to the one you can find
  112. in the Linux Kernel (<a href=
  113. "http://www.kernel.org/">http://www.kernel.org/</a>) or in Busybox
  114. (<a href="http://www.busybox.org/">http://www.busybox.org/</a>). Note that
  115. you can build everything as a normal user. There is no need to be root to
  116. configure and use Buildroot. The first step is to run the configuration
  117. assistant:</p>
  118. <pre>
  119. $ make menuconfig
  120. </pre>
  121. <p>For each entry of the configuration tool, you can find associated help
  122. that describes the purpose of the entry.</p>
  123. <p>Once everything is configured, the configuration tool has generated a
  124. <code>.config</code> file that contains the description of your
  125. configuration. It will be used by the Makefiles to do what's needed.</p>
  126. <p>Let's go:</p>
  127. <pre>
  128. $ make
  129. </pre>
  130. <p>This command will download, configure and compile all the selected
  131. tools, and finally generate a target filesystem. The target filesystem will
  132. be named <code>root_fs_ARCH.EXT</code> where <code>ARCH</code> is your
  133. architecture and <code>EXT</code> depends on the type of target filesystem
  134. selected in the <code>Target options</code> section of the configuration
  135. tool.</p>
  136. <p>If you intend to do an offline-build and just want to download all
  137. sources that you previously selected in &quot;make menuconfig&quot; then
  138. issue:</p>
  139. <pre>
  140. $ make source
  141. </pre>
  142. <p>You can now disconnect or copy the content of your <code>dl</code>
  143. directory to the build-host.</p>
  144. <h3><a name="environment_variables" id="environment_variables"></a>
  145. Environment variables</h3>
  146. <p>Buildroot optionally honors some environment variables that are passed
  147. to <code>make</code> :</p>
  148. <ul>
  149. <li>HOSTCXX</li>
  150. <li>HOSTCC</li>
  151. <li>UCLIBC_CONFIG_FILE=&lt;path/to/.config&gt;</li>
  152. <li>BUSYBOX_CONFIG_FILE=&lt;path/to/.config&gt;</li>
  153. </ul>
  154. <p>An example that uses config files located in the toplevel directory and
  155. in your $HOME:</p>
  156. <pre>
  157. $ make UCLIBC_CONFIG_FILE=uClibc.config BUSYBOX_CONFIG_FILE=$HOME/bb.config
  158. </pre>
  159. <p>If you want to use a compiler other than the default <code>gcc</code>
  160. or <code>g++</code> for building helper-binaries on your host, then do</p>
  161. <pre>
  162. $ make HOSTCXX=g++-4.3-HEAD HOSTCC=gcc-4.3-HEAD
  163. </pre>
  164. <h2><a name="custom_targetfs" id="custom_targetfs"></a>Customizing the
  165. target filesystem</h2>
  166. <p>There are two ways to customize the resulting target filesystem:</p>
  167. <ul>
  168. <li>Customize the target filesystem directly, and rebuild the image. The
  169. target filesystem is available under <code>build_ARCH/root/</code> where
  170. <code>ARCH</code> is the chosen target architecture. You can simply make
  171. your changes here, and run make afterwards, which will rebuild the target
  172. filesystem image. This method allows to do everything on the target
  173. filesystem, but if you decide to completely rebuild your toolchain and
  174. tools, these changes will be lost.</li>
  175. <li>Customize the target filesystem skeleton, available under
  176. <code>target/generic/target_skeleton/</code>. You can customize
  177. configuration files or other stuff here. However, the full file hierarchy
  178. is not yet present, because it's created during the compilation process.
  179. So you can't do everything on this target filesystem skeleton, but
  180. changes to it remain even if you completely rebuild the cross-compilation
  181. toolchain and the tools.<br />
  182. You can also customize the <code>target/generic/device_table.txt</code>
  183. file which is used by the tools that generate the target filesystem image
  184. to properly set permissions and create device nodes. The
  185. <code>target/generic/skel.tar.gz</code> file contains the main
  186. directories of a root filesystem and there is no obvious reason for which
  187. it should be changed. These main directories are in an tarball inside of
  188. inside the skeleton because it contains symlinks that would be broken
  189. otherwise.<br />
  190. These customizations are deployed into <code>build_ARCH/root/</code> just
  191. before the actual image is made. So simply rebuilding the image by running
  192. make should propogate any new changes to the image.</li>
  193. </ul>
  194. <h2><a name="custom_busybox" id="custom_busybox"></a>Customizing the
  195. Busybox configuration</h2>
  196. <p><a href="http://www.busybox.net/">Busybox</a> is very configurable, and
  197. you may want to customize it. You can
  198. follow these simple steps to do it. It's not an optimal way, but it's
  199. simple and it works.</p>
  200. <ol>
  201. <li>Make a first compilation of buildroot with busybox without trying to
  202. customize it.</li>
  203. <li>Invoke <code>make busybox-menuconfig</code>.
  204. The nice configuration tool appears and you can
  205. customize everything.</li>
  206. <li>Run the compilation of buildroot again.</li>
  207. </ol>
  208. <p>Otherwise, you can simply change the
  209. <code>package/busybox/busybox-&lt;version&gt;.config</code> file if you know the options
  210. you want to change without using the configuration tool.</p>
  211. <p>If you want to use an existing config file for busybox, then see
  212. section <a href="#environment_variables">environment variables</a>.</p>
  213. <h2><a name="custom_uclibc" id="custom_uclibc"></a>Customizing the uClibc
  214. configuration</h2>
  215. <p>Just like <a href="#custom_busybox">BusyBox</a>, <a
  216. href="http://www.uclibc.org/">uClibc</a> offers a lot of
  217. configuration options. They allow to select various
  218. functionalities, depending on your needs and limitations.</p>
  219. <p>The easiest way to modify the configuration of uClibc is to
  220. follow these steps :</p>
  221. <ol>
  222. <li>Make a first compilation of buildroot without trying to
  223. customize uClibc.</li>
  224. <li>Invoke <code>make uclibc-menuconfig</code>.
  225. The nice configuration assistant, similar to
  226. the one used in the Linux Kernel or in Buildroot appears. Make
  227. your configuration as appropriate.</li>
  228. <li>Copy the <code>.config</code> file to
  229. <code>toolchain/uClibc/uClibc.config</code> or
  230. <code>toolchain/uClibc/uClibc.config-locale</code>. The former
  231. is used if you haven't selected locale support in Buildroot
  232. configuration, and the latter is used if you have selected
  233. locale support.</li>
  234. <li>Run the compilation of Buildroot again</li>
  235. </ol>
  236. <p>Otherwise, you can simply change
  237. <code>toolchain/uClibc/uClibc.config</code> or
  238. <code>toolchain/uClibc/uClibc.config-locale</code> without running
  239. the configuration assistant.</p>
  240. <p>If you want to use an existing config file for uclibc, then see
  241. section <a href="#environment_variables">environment variables</a>.</p>
  242. <h2><a name="buildroot_innards" id="buildroot_innards"></a>How Buildroot
  243. works</h2>
  244. <p>As said above, Buildroot is basically a set of Makefiles that download,
  245. configure and compiles software with the correct options. It also includes
  246. some patches for various software, mainly the ones involved in the
  247. cross-compilation tool chain (<code>gcc</code>, <code>binutils</code> and
  248. uClibc).</p>
  249. <p>There is basically one Makefile per software, and they are named with
  250. the <code>.mk</code> extension. Makefiles are split into three
  251. sections:</p>
  252. <ul>
  253. <li><b>package</b> (in the <code>package/</code> directory) contains the
  254. Makefiles and associated files for all user-space tools that Buildroot
  255. can compile and add to the target root filesystem. There is one
  256. sub-directory per tool.</li>
  257. <li><b>toolchain</b> (in the <code>toolchain/</code> directory) contains
  258. the Makefiles and associated files for all software related to the
  259. cross-compilation toolchain : <code>binutils</code>, <code>ccache</code>,
  260. <code>gcc</code>, <code>gdb</code>, <code>kernel-headers</code> and
  261. <code>uClibc</code>.</li>
  262. <li><b>target</b> (in the <code>target</code> directory) contains the
  263. Makefiles and associated files for software related to the generation of
  264. the target root filesystem image. Four types of filesystems are supported
  265. : ext2, jffs2, cramfs and squashfs. For each of them, there's a
  266. sub-directory with the required files. There is also a
  267. <code>default/</code> directory that contains the target filesystem
  268. skeleton.</li>
  269. </ul>
  270. <p>Each directory contains at least 2 files :</p>
  271. <ul>
  272. <li><code>something.mk</code> is the Makefile that downloads, configures,
  273. compiles and installs the software <code>something</code>.</li>
  274. <li><code>Config.in</code> is a part of the configuration tool
  275. description file. It describes the option related to the current
  276. software.</li>
  277. </ul>
  278. <p>The main Makefile do the job through the following steps (once the
  279. configuration is done):</p>
  280. <ol>
  281. <li>Create the download directory (<code>dl/</code> by default). This is
  282. where the tarballs will be downloaded. It is interesting to know that the
  283. tarballs are in this directory because it may be useful to save them
  284. somewhere to avoid further downloads.</li>
  285. <li>Create the build directory (<code>build_ARCH/</code> by default,
  286. where <code>ARCH</code> is your architecture). This is where all
  287. user-space tools while be compiled.</li>
  288. <li>Create the toolchain build directory
  289. (<code>toolchain_build_ARCH/</code> by default, where <code>ARCH</code>
  290. is your architecture). This is where the cross compilation toolchain will
  291. be compiled.</li>
  292. <li>Setup the staging directory (<code>build_ARCH/staging_dir/</code> by
  293. default). This is where the cross-compilation toolchain will be
  294. installed. If you want to use the same cross-compilation toolchain for
  295. other purposes, such as compiling third-party applications, you can add
  296. <code>build_ARCH/staging_dir/bin</code> to your PATH, and then use
  297. <code>arch-linux-gcc</code> to compile your application. In order to
  298. setup this staging directory, it first removes it, and then it creates
  299. various subdirectories and symlinks inside it.</li>
  300. <li>Create the target directory (<code>build_ARCH/root/</code> by
  301. default) and the target filesystem skeleton. This directory will contain
  302. the final root filesystem. To setup it up, it first deletes it, then it
  303. uncompress the <code>target/generic/skel.tar.gz</code> file to create the
  304. main subdirectories and symlinks, copies the skeleton available in
  305. <code>target/generic/target_skeleton</code> and then removes useless
  306. <code>.svn/</code> directories.</li>
  307. <li>Add the <code>TARGETS</code> dependency. This should generally check
  308. if the configuration option for this package is enabled, and if so then
  309. &quot;subscribe&quot; this package to be compiled by adding it to the
  310. TARGETS global variable.</li>
  311. </ol>
  312. <h2><a name="using_toolchain" id="using_toolchain"></a>Using the
  313. uClibc toolchain</h2>
  314. <p>You may want to compile your own programs or other software
  315. that are not packaged in Buildroot. In order to do this, you can
  316. use the toolchain that was generated by Buildroot.</p>
  317. <p>The toolchain generated by Buildroot by default is located in
  318. <code>build_ARCH/staging_dir/</code>. The simplest way to use it
  319. is to add <code>build_ARCH/staging_dir/bin/</code> to your PATH
  320. environnement variable, and then to use
  321. <code>arch-linux-gcc</code>, <code>arch-linux-objdump</code>,
  322. <code>arch-linux-ld</code>, etc.</p>
  323. <p>For example, you may add the following to your
  324. <code>.bashrc</code> (considering you're building for the MIPS
  325. architecture and that Buildroot is located in
  326. <code>~/buildroot/</code>) :</p>
  327. <pre>
  328. export PATH=&quot;$PATH:~/buildroot/build_mips/staging_dir/bin/&quot;
  329. </pre>
  330. <p>Then you can simply do :</p>
  331. <pre>
  332. mips-linux-gcc -o foo foo.c
  333. </pre>
  334. <p><b>Important</b> : do not try to move the toolchain to an other
  335. directory, it won't work. There are some hard-coded paths in the
  336. <i>gcc</i> configuration. If the default toolchain directory
  337. doesn't suit your needs, please refer to the <a
  338. href="#toolchain_standalone">Using the uClibc toolchain outside of
  339. buildroot</a> section.</p>
  340. <h2><a name="toolchain_standalone" id="toolchain_standalone"></a>Using the
  341. uClibc toolchain outside of buildroot</h2>
  342. <p>By default, the cross-compilation toolchain is generated inside
  343. <code>build_ARCH/staging_dir/</code>. But sometimes, it may be useful to
  344. install it somewhere else, so that it can be used to compile other programs
  345. or by other users. Moving the <code>build_ARCH/staging_dir/</code>
  346. directory elsewhere is <b>not possible</b>, because they are some hardcoded
  347. paths in the toolchain configuration.</p>
  348. <p>If you want to use the generated toolchain for other purposes,
  349. you can configure Buildroot to generate it elsewhere using the
  350. option of the configuration tool : <code>Build options -&gt;
  351. Toolchain and header file location</code>, which defaults to
  352. <code>$(BUILD_DIR)/staging_dir/</code>.</p>
  353. <h2><a name="downloaded_packages"
  354. id="downloaded_packages"></a>Location of downloaded packages</h2>
  355. <p>It might be useful to know that the various tarballs that are
  356. downloaded by the <i>Makefiles</i> are all stored in the
  357. <code>DL_DIR</code> which by default is the <code>dl</code>
  358. directory. It's useful for example if you want to keep a complete
  359. version of Buildroot which is know to be working with the
  360. associated tarballs. This will allow you to regenerate the
  361. toolchain and the target filesystem with exactly the same
  362. versions.</p>
  363. <h2><a name="add_software" id="add_software"></a>Extending Buildroot with
  364. more software</h2>
  365. <p>This section will only consider the case in which you want to
  366. add user-space software.</p>
  367. <h3>Package directory</h3>
  368. <p>First of all, create a directory under the <code>package</code>
  369. directory for your software, for example <code>foo</code>.</p>
  370. <h3><code>Config.in</code> file</h3>
  371. <p>Then, create a file named <code>Config.in</code>. This file
  372. will contain the portion of options description related to our
  373. <code>foo</code> software that will be used and displayed in the
  374. configuration tool. It should basically contain :</p>
  375. <pre>
  376. config BR2_PACKAGE_FOO
  377. bool "foo"
  378. default n
  379. help
  380. This is a comment that explains what foo is.
  381. http://foosoftware.org/foo/
  382. </pre>
  383. <p>Of course, you can add other options to configure particular
  384. things in your software.</p>
  385. <h3>The real <i>Makefile</i></h3>
  386. <p>Finally, here's the hardest part. Create a file named
  387. <code>foo.mk</code>. It will contain the <i>Makefile</i> rules that
  388. are in charge of downloading, configuring, compiling and installing
  389. the software. Below is an example that we will comment
  390. afterwards.</p>
  391. <pre>
  392. <a name="line1" id="line1">1</a> #############################################################
  393. <a name="line2" id="line2">2</a> #
  394. <a name="line3" id="line3">3</a> # foo
  395. <a name="line4" id="line4">4</a> #
  396. <a name="line5" id="line5">5</a> #############################################################
  397. <a name="line6" id="line6">6</a> FOO_VERSION:=1.0
  398. <a name="line7" id="line7">7</a> FOO_SOURCE:=foo-$(FOO_VERSION).tar.gz
  399. <a name="line8" id="line8">8</a> FOO_SITE:=http://www.foosoftware.org/downloads
  400. <a name="line9" id="line9">9</a> FOO_DIR:=$(BUILD_DIR)/foo-$(FOO_VERSION)
  401. <a name="line10" id="line10">10</a> FOO_BINARY:=foo
  402. <a name="line11" id="line11">11</a> FOO_TARGET_BINARY:=usr/bin/foo
  403. <a name="line12" id="line12">12</a>
  404. <a name="line13" id="line13">13</a> $(DL_DIR)/$(FOO_SOURCE):
  405. <a name="line14" id="line14">14</a> $(WGET) -P $(DL_DIR) $(FOO_SITE)/$(FOO_SOURCE)
  406. <a name="line15" id="line15">15</a>
  407. <a name="line16" id="line16">16</a> $(FOO_DIR)/.source: $(DL_DIR)/$(FOO_SOURCE)
  408. <a name="line17" id="line17">17</a> $(ZCAT) $(DL_DIR)/$(FOO_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
  409. <a name="line18" id="line18">18</a> touch $@
  410. <a name="line19" id="line19">19</a>
  411. <a name="line20" id="line20">20</a> $(FOO_DIR)/.configured: $(FOO_DIR)/.source
  412. <a name="line21" id="line21">21</a> (cd $(FOO_DIR); rm -rf config.cache ; \
  413. <a name="line22" id="line22">22</a> $(TARGET_CONFIGURE_OPTS) \
  414. <a name="line23" id="line23">23</a> CFLAGS="$(TARGET_CFLAGS)" \
  415. <a name="line24" id="line24">24</a> ./configure \
  416. <a name="line25" id="line25">25</a> --target=$(GNU_TARGET_NAME) \
  417. <a name="line26" id="line26">26</a> --host=$(GNU_TARGET_NAME) \
  418. <a name="line27" id="line27">27</a> --build=$(GNU_HOST_NAME) \
  419. <a name="line28" id="line28">28</a> --prefix=/usr \
  420. <a name="line29" id="line29">29</a> --sysconfdir=/etc \
  421. <a name="line30" id="line30">30</a> );
  422. <a name="line31" id="line31">31</a> touch $@
  423. <a name="line32" id="line32">32</a>
  424. <a name="line33" id="line33">33</a> $(FOO_DIR)/$(FOO_BINARY): $(FOO_DIR)/.configured
  425. <a name="line34" id="line34">34</a> $(MAKE) CC=$(TARGET_CC) -C $(FOO_DIR)
  426. <a name="line35" id="line35">35</a>
  427. <a name="line36" id="line36">36</a> $(TARGET_DIR)/$(FOO_TARGET_BINARY): $(FOO_DIR)/$(FOO_BINARY)
  428. <a name="line37" id="line37">37</a> $(MAKE) prefix=$(TARGET_DIR)/usr -C $(FOO_DIR) install
  429. <a name="line38" id="line38">38</a> rm -Rf $(TARGET_DIR)/usr/man
  430. <a name="line39" id="line39">39</a>
  431. <a name="line40" id="line40">40</a> foo: uclibc ncurses $(TARGET_DIR)/$(FOO_TARGET_BINARY)
  432. <a name="line41" id="line41">41</a>
  433. <a name="line42" id="line42">42</a> foo-source: $(DL_DIR)/$(FOO_SOURCE)
  434. <a name="line43" id="line43">43</a>
  435. <a name="line44" id="line44">44</a> foo-clean:
  436. <a name="line45" id="line45">45</a> $(MAKE) prefix=$(TARGET_DIR)/usr -C $(FOO_DIR) uninstall
  437. <a name="line46" id="line46">46</a> -$(MAKE) -C $(FOO_DIR) clean
  438. <a name="line47" id="line47">47</a>
  439. <a name="line48" id="line48">48</a> foo-dirclean:
  440. <a name="line49" id="line49">49</a> rm -rf $(FOO_DIR)
  441. <a name="line50" id="line50">50</a>
  442. <a name="line51" id="line51">51</a> #############################################################
  443. <a name="line52" id="line52">52</a> #
  444. <a name="line53" id="line53">53</a> # Toplevel Makefile options
  445. <a name="line54" id="line54">54</a> #
  446. <a name="line55" id="line55">55</a> #############################################################
  447. <a name="line56" id="line56">56</a> ifeq ($(strip $(BR2_PACKAGE_FOO)),y)
  448. <a name="line57" id="line57">57</a> TARGETS+=foo
  449. <a name="line58" id="line58">58</a> endif
  450. </pre>
  451. <p>First of all, this <i>Makefile</i> example works for a single
  452. binary software. For other software such as libraries or more
  453. complex stuff with multiple binaries, it should be adapted. Look at
  454. the other <code>*.mk</code> files in the <code>package</code>
  455. directory.</p>
  456. <p>At lines <a href="#line6">6-11</a>, a couple of useful variables are defined :</p>
  457. <ul>
  458. <li><code>FOO_VERSION</code> : The version of <i>foo</i> that
  459. should be downloaded.</li>
  460. <li><code>FOO_SOURCE</code> : The name of the tarball of
  461. <i>foo</i> on the download website of FTP site. As you can see
  462. <code>FOO_VERSION</code> is used.</li>
  463. <li><code>FOO_SITE</code> : The HTTP or FTP site from which
  464. <i>foo</i> archive is downloaded. It must include the complete
  465. path to the directory where <code>FOO_SOURCE</code> can be
  466. found.</li>
  467. <li><code>FOO_DIR</code> : The directory into which the software
  468. will be configured and compiled. Basically, it's a subdirectory
  469. of <code>BUILD_DIR</code> which is created upon decompression of
  470. the tarball.</li>
  471. <li><code>FOO_BINARY</code> : Software binary name. As said
  472. previously, this is an example for a single binary software.</li>
  473. <li><code>FOO_TARGET_BINARY</code> : The full path of the binary
  474. inside the target filesystem.</li>
  475. </ul>
  476. <p>Lines <a href="#line13">13-14</a> defines a target that downloads the tarball from
  477. the remote site to the download directory
  478. (<code>DL_DIR</code>).</p>
  479. <p>Lines <a href="#line16">16-18</a> defines a target and associated rules that
  480. uncompress the downloaded tarball. As you can see, this target
  481. depends on the tarball file, so that the previous target (line
  482. <a href="#line13">13-14</a>) is called before executing the rules of the current
  483. target. Uncompressing is followed by <i>touching</i> a hidden file
  484. to mark the software has having been uncompressed. This trick is
  485. used everywhere in Buildroot <i>Makefile</i> to split steps
  486. (download, uncompress, configure, compile, install) while still
  487. having correct dependencies.</p>
  488. <p>Lines <a href="#line20">20-31</a> defines a target and associated rules that
  489. configures the software. It depends on the previous target (the
  490. hidden <code>.source</code> file) so that we are sure the software has
  491. been uncompressed. In order to configure it, it basically runs the
  492. well-known <code>./configure</code> script. As we may be doing
  493. cross-compilation, <code>target</code>, <code>host</code> and
  494. <code>build</code> arguments are given. The prefix is also set to
  495. <code>/usr</code>, not because the software will be installed in
  496. <code>/usr</code> on your host system, but in the target
  497. filesystem. Finally it creates a <code>.configured</code> file to
  498. mark the software as configured.</p>
  499. <p>Lines <a href="#line33">33-34</a> defines a target and a rule that compiles the
  500. software. This target will create the binary file in the
  501. compilation directory, and depends on the software being already
  502. configured (hence the reference to the <code>.configured</code>
  503. file). It basically runs <code>make</code> inside the source
  504. directory.</p>
  505. <p>Lines <a href="#line36">36-38</a> defines a target and associated rules that install
  506. the software inside the target filesystem. It depends on the
  507. binary file in the source directory, to make sure the software has
  508. been compiled. It uses the <code>install</code> target of the
  509. software <code>Makefile</code> by passing a <code>prefix</code>
  510. argument, so that the <code>Makefile</code> doesn't try to install
  511. the software inside host <code>/usr</code> but inside target
  512. <code>/usr</code>. After the installation, the
  513. <code>/usr/man</code> directory inside the target filesystem is
  514. removed to save space.</p>
  515. <p>Line <a href="#line40">40</a> defines the main target of the software, the one
  516. that will be eventually be used by the top level
  517. <code>Makefile</code> to download, compile, and then install
  518. this package. This target should first of all depends on all
  519. needed dependecies of the software (in our example,
  520. <i>uclibc</i> and <i>ncurses</i>), and also depend on the
  521. final binary. This last dependency will call all previous
  522. dependencies in the correct order. </p>
  523. <p>Line <a href="#line42">42</a> defines a simple target that only downloads the code
  524. source. This is not used during normal operation of Buildroot, but
  525. is needed if you intend to download all required sources at once
  526. for later offline build. Note that if you add a new package providing
  527. a <code>foo-source</code> target is <i>mandatory</i> to support
  528. users that wish to do offline-builds. Furthermore it eases checking
  529. if all package-sources are downloadable.</p>
  530. <p>Lines <a href="#line44">44-46</a> define a simple target to clean the software build
  531. by calling the <i>Makefiles</i> with the appropriate option.
  532. The <code>-clean</code> target should run <code>make clean</code>
  533. on $(BUILD_DIR)/package-version and MUST uninstall all files of the
  534. package from $(STAGING_DIR) and from $(TARGET_DIR).</p>
  535. <p>Lines <a href="#line48">48-49</a> define a simple target to completely remove the
  536. directory in which the software was uncompressed, configured and
  537. compiled. The <code>-dirclean</code> target MUST completely rm $(BUILD_DIR)/package-version.</p>
  538. <p>Lines <a href="#line51">51-58</a> adds the target <code>foo</code> to the list
  539. of targets to be compiled by Buildroot by first checking if
  540. the configuration option for this package has been enabled
  541. using the configuration tool, and if so then &quot;subscribes&quot;
  542. this package to be compiled by adding it to the TARGETS
  543. global variable. The name added to the TARGETS global
  544. variable is the name of this package's target, as defined on
  545. line <a href="#line40">40</a>, which is used by Buildroot to download, compile, and
  546. then install this package.</p>
  547. <h3>Conclusion</h3>
  548. <p>As you can see, adding a software to buildroot is simply a
  549. matter of writing a <i>Makefile</i> using an already existing
  550. example and to modify it according to the compilation process of
  551. the software.</p>
  552. <p>If you package software that might be useful for other persons,
  553. don't forget to send a patch to Buildroot developers !</p>
  554. <h2><a name="links" id="links"></a>Resources</h2>
  555. <p>To learn more about Buildroot you can visit these
  556. websites:</p>
  557. <ul>
  558. <li><a href="http://www.uclibc.org/">http://www.uclibc.org/</a></li>
  559. <li><a href="http://www.busybox.net/">http://www.busybox.net/</a></li>
  560. </ul>
  561. </div>
  562. <!--
  563. <a href="http://validator.w3.org/check?uri=referer"><img
  564. border="0" height="31" width="88"
  565. src="images/valid-html401.png"
  566. alt="Valid HTML"></img></a>
  567. -->
  568. </body>
  569. </html>