buildroot.html 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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>Usage and documentation by Thomas Petazzoni. Contributions from
  16. Karsten Kruse, Ned Ludd, Martin Herren.</p>
  17. <p><small>Last modification : $Id: buildroot-documentation.html,v 1.2 2004/12/28 19:15:20 andersen Exp $</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">Ressources</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 allows 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 "host compilation toolchain", and more
  60. generally, the machine on which it is running, and on which you're
  61. working is called the "host system". 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 CVS snapshots or directly using
  95. CVS.</p>
  96. <p>The latest snapshot is always available at <a
  97. href="http://uclibc.org/downloads/snapshots/buildroot-snapshot.tar.bz2">http://uclibc.org/downloads/snapshots/buildroot-snapshot.tar.bz2</a>,
  98. and previous snapshots are also available at <a
  99. href="http://uclibc.org/downloads/snapshots/">http://uclibc.org/downloads/snapshots/</a>.</p>
  100. <p>To download Buildroot using CVS, you can simply follow
  101. the rules described on the "Accessing CVS"-page (<a href=
  102. "http://www.uclibc.org/cvs_anon.html">http://www.uclibc.org/cvs_anon.html</a>)
  103. of the uClibc website (<a href=
  104. "http://www.uclibc.org">http://www.uclibc.org</a>), and download the
  105. <code>buildroot</code> CVS module. For the impatient, here's a quick
  106. recipe:</p>
  107. <pre>
  108. $ cvs -d:pserver:anonymous@uclibc.org:/var/cvs login
  109. $ cvs -z3 -d:pserver:anonymous@uclibc.org:/var/cvs co buildroot
  110. </pre>
  111. <h2><a name="using" id="using"></a>Using Buildroot</h2>
  112. <p>Buildroot has a nice configuration tool similar to the one you can find
  113. in the Linux Kernel (<a href=
  114. "http://www.kernel.org/">http://www.kernel.org/</a>) or in Busybox
  115. (<a href="http://www.busybox.org/">http://www.busybox.org/</a>). Note that
  116. you can run everything as a normal user. There is no need to be root to
  117. configure and use Buildroot. The first step is to run the configuration
  118. assistant:</p>
  119. <pre>
  120. $ make menuconfig
  121. </pre>
  122. <p>For each entry of the configuration tool, you can find associated help
  123. that describes the purpose of the entry.</p>
  124. <p>Once everything is configured, the configuration tool has generated a
  125. <code>.config</code> file that contains the description of your
  126. configuration. It will be used by the Makefiles to do what's needed.</p>
  127. <p>Let's go:</p>
  128. <pre>
  129. $ make
  130. </pre>
  131. <p>This command will download, configure and compile all the selected
  132. tools, and finally generate a target filesystem. The target filesystem will
  133. be named <code>root_fs_ARCH.EXT</code> where <code>ARCH</code> is your
  134. architecture and <code>EXT</code> depends on the type of target filesystem
  135. selected in the <code>Target options</code> section of the configuration
  136. tool.</p>
  137. <h2><a name="custom_targetfs" id="custom_targetfs"></a>Customizing the
  138. target filesystem</h2>
  139. <p>There are two ways to customize the resulting target filesystem:</p>
  140. <ul>
  141. <li>Customize the target filesystem directly, and rebuild the image. The
  142. target filesystem is available under <code>build_ARCH/root/</code> where
  143. <code>ARCH</code> is the chosen target architecture. You can simply make
  144. your changes here, and run make afterwards, which will rebuild the target
  145. filesystem image. This method allows to do everything on the target
  146. filesystem, but if you decide to completely rebuild your toolchain and
  147. tools, these changes will be lost.</li>
  148. <li>Customize the target filesystem skeleton, available under
  149. <code>target/default/target_skeleton/</code>. You can customize
  150. configuration files or other stuff here. However, the full file hierarchy
  151. is not yet present, because it's created during the compilation process.
  152. So you can't do everything on this target filesystem skeleton, but
  153. changes to it remains even you completely rebuild the cross-compilation
  154. toolchain and the tools.<br />
  155. You can also customize the <code>target/default/device_table.txt</code>
  156. file which is used by the tools that generate the target filesystem image
  157. to properly set permissions and create device nodes. The
  158. <code>target/default/skel.tar.gz</code> file contains the main
  159. directories of a root filesystem and there is no obvious reason for which
  160. it should be changed. These main directories are in an tarball inside of
  161. inside the skeleton because it contains symlinks that would be broken
  162. otherwise.</li>
  163. </ul>
  164. <h2><a name="custom_busybox" id="custom_busybox"></a>Customizing the
  165. Busybox configuration</h2>
  166. <p>Busybox is very configurable, and you may want to customize it. You can
  167. follow these simple steps to do it. It's not an optimal way, but it's
  168. simple and it works.</p>
  169. <ol>
  170. <li>Make a first compilation of buildroot with busybox without trying to
  171. customize it.</li>
  172. <li>Go into <code>build_ARCH/busybox/</code> and run <code>make
  173. menuconfig</code>. The nice configuration tool appears and you can
  174. customize everything.</li>
  175. <li>Copy the <code>.config</code> file to
  176. <code>package/busybox/busybox.config</code> so that your customized
  177. configuration will remains even if you remove the cross-compilation
  178. toolchain.</li>
  179. <li>Run the compilation of buildroot again.</li>
  180. </ol>
  181. <p>Otherwise, you can simply change the
  182. <code>package/busybox/busybox.config</code> file if you know the options
  183. you want to change without using the configuration tool.</p>
  184. <h2><a name="custom_uclibc" id="custom_uclibc"></a>Customizing the uClibc
  185. configuration</h2>
  186. <p>Just like <a href="#custom_busybox">BusyBox</a>, <a
  187. href="http://www.uclibc.org">uClibc</a> offers a lot of
  188. configuration options. They allow to select various
  189. functionalities, depending on your needs and limitations.</p>
  190. <p>The easiest way to modify the configuration of uClibc is to
  191. follow these steps :</p>
  192. <ol>
  193. <li>Make a first compilation of buildroot without trying to
  194. customize uClibc.</li>
  195. <li>Go into the directory
  196. <code>toolchain_build_ARCH/uClibc/</code> and run <code>make
  197. menuconfig</code>. The nice configuration assistant, similar to
  198. the one used in the Linux Kernel or in Buildroot appears. Make
  199. your configuration as appropriate.</li>
  200. <li>Copy the <code>.config</code> file to
  201. <code>toolchain/uClibc/uClibc.config</code> or
  202. <code>toolchain/uClibc/uClibc.config-locale</code>. The former
  203. is used if you haven't selected locale support in Buildroot
  204. configuration, and the latter is used if you have selected
  205. locale support.</li>
  206. <li>Run the compilation of Buildroot again</li>
  207. </ol>
  208. <p>Otherwise, you can simply change
  209. <code>toolchain/uClibc/uClibc.config</code> or
  210. <code>toolchain/uClibc/uClibc.config-locale</code> without running
  211. the configuration assistant.</p>
  212. <h2><a name="buildroot_innards" id="buildroot_innards"></a>How Buildroot
  213. works</h2>
  214. <p>As said above, Buildroot is basically a set of Makefiles that download,
  215. configure and compiles software with the correct options. It also includes
  216. some patches for various software, mainly the ones involved in the
  217. cross-compilation tool chain (<code>gcc</code>, <code>binutils</code> and
  218. uClibc).</p>
  219. <p>There is basically one Makefile per software, and they are named with
  220. the <code>.mk</code> extension. Makefiles are split into three
  221. sections:</p>
  222. <ul>
  223. <li><b>package</b> (in the <code>package/</code> directory) contains the
  224. Makefiles and associated files for all user-space tools that Buildroot
  225. can compile and add to the target root filesystem. There is one
  226. sub-directory per tool.</li>
  227. <li><b>toolchain</b> (in the <code>toolchain/</code> directory) contains
  228. the Makefiles and associated files for all software related to the
  229. cross-compilation toolchain : <code>binutils</code>, <code>ccache</code>,
  230. <code>gcc</code>, <code>gdb</code>, <code>kernel-headers</code> and
  231. <code>uClibc</code>.</li>
  232. <li><b>target</b> (in the <code>target</code> directory) contains the
  233. Makefiles and associated files for software related to the generation of
  234. the target root filesystem image. Four types of filesystems are supported
  235. : ext2, jffs2, cramfs and squashfs. For each of them, there's a
  236. sub-directory with the required files. There is also a
  237. <code>default/</code> directory that contains the target filesystem
  238. skeleton.</li>
  239. </ul>
  240. <p>Each directory contains at least 2 files :</p>
  241. <ul>
  242. <li><code>something.mk</code> is the Makefile that downloads, configures,
  243. compiles and installs the software <code>something</code>.</li>
  244. <li><code>Config.in</code> is a part of the configuration tool
  245. description file. It describes the option related to the current
  246. software.</li>
  247. </ul>
  248. <p>The main Makefile do the job through the following steps (once the
  249. configuration is done):</p>
  250. <ol>
  251. <li>Create the download directory (<code>dl/</code> by default). This is
  252. where the tarballs will be downloaded. It is interesting to know that the
  253. tarballs are in this directory because it may be useful to save them
  254. somewhere to avoid further downloads.</li>
  255. <li>Create the build directory (<code>build_ARCH/</code> by default,
  256. where <code>ARCH</code> is your architecture). This is where all
  257. user-space tools while be compiled.</li>
  258. <li>Create the toolchain build directory
  259. (<code>toolchain_build_ARCH/</code> by default, where <code>ARCH</code>
  260. is your architecture). This is where the cross compilation toolchain will
  261. be compiled.</li>
  262. <li>Setup the staging directory (<code>build_ARCH/staging_dir/</code> by
  263. default). This is where the cross-compilation toolchain will be
  264. installed. If you want to use the same cross-compilation toolchain for
  265. other purposes, such as compiling third-party applications, you can add
  266. <code>build_ARCH/staging_dir/bin</code> to your PATH, and then use
  267. <code>arch-linux-gcc</code> to compile your application. In order to
  268. setup this staging directory, it first removes it, and then it creates
  269. various subdirectories and symlinks inside it.</li>
  270. <li>Create the target directory (<code>build_ARCH/root/</code> by
  271. default) and the target filesystem skeleton. This directory will contain
  272. the final root filesystem. To setup it up, it first deletes it, then it
  273. uncompress the <code>target/default/skel.tar.gz</code> file to create the
  274. main subdirectories and symlinks, copies the skeleton available in
  275. <code>target/default/target_skeleton</code> and then removes useless
  276. <code>CVS/</code> directories.</li>
  277. <li>Add the <code>TARGETS</code> dependency. This should generally check
  278. if the configuration option for this package is enabled, and if so then
  279. "subscribe" this package to be compiled by adding it to the TARGETS
  280. global variable.</li>
  281. </ol>
  282. <h2><a name="using_toolchain" id="using_toolchain"></a>Using the
  283. uClibc toolchain</h2>
  284. <p>You may want to compile your own programs or other software
  285. that are not packaged in Buildroot. In order to do this, you can
  286. use the toolchain that was generated by Buildroot.</p>
  287. <p>The toolchain generated by Buildroot by default is located in
  288. <code>build_ARCH/staging_dir/</code>. The simplest way to use it
  289. is to add <code>build_ARCH/staging_dir/bin/</code> to your PATH
  290. environnement variable, and then to use
  291. <code>arch-linux-gcc</code>, <code>arch-linux-objdump</code>,
  292. <code>arch-linux-ld</code>, etc.</p>
  293. <p>For example, you may add the following to your
  294. <code>.bashrc</code> (considering you're building for the MIPS
  295. architecture and that Buildroot is located in
  296. <code>~/buildroot/</code>) :</p>
  297. <pre>
  298. export PATH=$PATH:~/buildroot/build_mips/bin/
  299. </pre>
  300. <p>Then you can simply do :</p>
  301. <pre>
  302. mips-linux-gcc -o foo foo.c
  303. </pre>
  304. <p><b>Important</b> : do not try to move the toolchain to an other
  305. directory, it won't work. There are some hard-coded paths in the
  306. <i>gcc</i> configuration. If the default toolchain directory
  307. doesn't suit your needs, please refer to the <a
  308. href="#toolchain_standalone">Using the uClibc toolchain outside of
  309. buildroot</a> section.</p>
  310. <h2><a name="toolchain_standalone" id="toolchain_standalone"></a>Using the
  311. uClibc toolchain outside of buildroot</h2>
  312. <p>By default, the cross-compilation toolchain is generated inside
  313. <code>build_ARCH/staging_dir/</code>. But sometimes, it may be useful to
  314. install it somewhere else, so that it can be used to compile other programs
  315. or by other users. Moving the <code>build_ARCH/staging_dir/</code>
  316. directory elsewhere is <b>not possible</b>, because they are some hardcoded
  317. paths in the toolchain configuration.</p>
  318. <p>If you want to use the generated toolchain for other purposes,
  319. you can configure Buildroot to generate it elsewhere using the
  320. option of the configuration tool : <code>Build options ->
  321. Toolchain and header file location</code>, which defaults to
  322. <code>$(BUILD_DIR)/staging_dir/</code>.</p>
  323. <h2><a name="downloaded_packages"
  324. id="downloaded_packages"></a>Location of downloaded packages</h2>
  325. <p>It might be useful to know that the various tarballs that are
  326. downloaded by the <i>Makefiles</i> are all stored in the
  327. <code>DL_DIR</code> which by default is the <code>dl</code>
  328. directory. It's useful for example if you want to keep a complete
  329. version of Buildroot which is know to be working with the
  330. associated tarballs. This will allow you to regenerate the
  331. toolchain and the target filesystem with exactly the same
  332. versions.</p>
  333. <h2><a name="add_software" id="add_software"></a>Extending Buildroot with
  334. more software</h2>
  335. <p>This section will only consider the case in which you want to
  336. add user-space software.</p>
  337. <h3>Package directory</h3>
  338. <p>First of all, create a directory under the <code>package</code>
  339. directory for your software, for example <code>foo</code>.</p>
  340. <h3><code>Config.in</code> file</h3>
  341. <p>Then, create a file named <code>Config.in</code>. This file
  342. will contain the portion of options description related to our
  343. <code>foo</code> software that will be used and displayed in the
  344. configuration tool. It should basically contain :</p>
  345. <pre>
  346. config BR2_PACKAGE_FOO
  347. bool "foo"
  348. default n
  349. help
  350. This is a comment that explains what foo is.
  351. </pre>
  352. <p>Of course, you can add other options to configure particular
  353. things in your software.</p>
  354. <h3>The real <i>Makefile</i></h3>
  355. <p>Finally, here's the hardest part. Create a file named
  356. <code>foo.mk</code>. It will contain the <i>Makefile</i> rules that
  357. are in charge of downloading, configuring, compiling and installing
  358. the software. Below is an example that we will comment
  359. afterwards.</p>
  360. <pre>
  361. 1 #############################################################
  362. 2 #
  363. 3 # foo
  364. 4 #
  365. 5 #############################################################
  366. 6 FOO_VERSION:=1.0
  367. 7 FOO_SOURCE:=less-$(FOO_VERSION).tar.gz
  368. 8 FOO_SITE:=http://www.foosoftware.org/downloads
  369. 9 FOO_DIR:=$(BUILD_DIR)/less-$(FOO_VERSION)
  370. 10 FOO_BINARY:=foo
  371. 11 FOO_TARGET_BINARY:=usr/bin/foo
  372. 12
  373. 13 $(DL_DIR)/$(FOO_SOURCE):
  374. 14 $(WGET) -P $(DL_DIR) $(FOO_SITE)/$(FOO_SOURCE)
  375. 15
  376. 16 $(FOO_DIR)/.source: $(DL_DIR)/$(FOO_SOURCE)
  377. 17 zcat $(DL_DIR)/$(FOO_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
  378. 18 touch $(FOO_DIR)/.source
  379. 19
  380. 20 $(FOO_DIR)/.configured: $(FOO_DIR)/.source
  381. 21 (cd $(FOO_DIR); \
  382. 22 $(TARGET_CONFIGURE_OPTS) \
  383. 23 CFLAGS="$(TARGET_CFLAGS)" \
  384. 24 ./configure \
  385. 25 --target=$(GNU_TARGET_NAME) \
  386. 26 --host=$(GNU_TARGET_NAME) \
  387. 27 --build=$(GNU_HOST_NAME) \
  388. 28 --prefix=/usr \
  389. 29 --sysconfdir=/etc \
  390. 30 );
  391. 31 touch $(FOO_DIR)/.configured;
  392. 32
  393. 33 $(FOO_DIR)/$(FOO_BINARY): $(FOO_DIR)/.configured
  394. 34 $(MAKE) CC=$(TARGET_CC) -C $(FOO_DIR)
  395. 35
  396. 36 $(TARGET_DIR)/$(FOO_TARGET_BINARY): $(FOO_DIR)/$(FOO_BINARY)
  397. 37 $(MAKE) prefix=$(TARGET_DIR)/usr -C $(FOO_DIR) install
  398. 38 rm -Rf $(TARGET_DIR)/usr/man
  399. 39
  400. 40 foo: uclibc ncurses $(TARGET_DIR)/$(FOO_TARGET_BINARY)
  401. 41
  402. 42 foo-source: $(DL_DIR)/$(FOO_SOURCE)
  403. 43
  404. 44 foo-clean:
  405. 45 $(MAKE) prefix=$(TARGET_DIR)/usr -C $(FOO_DIR) uninstall
  406. 46 -$(MAKE) -C $(FOO_DIR) clean
  407. 47
  408. 48 foo-dirclean:
  409. 49 rm -rf $(FOO_DIR)
  410. 50
  411. 51 #############################################################
  412. 52 #
  413. 53 # Toplevel Makefile options
  414. 54 #
  415. 55 #############################################################
  416. 56 ifeq ($(strip $(BR2_PACKAGE_FOO)),y)
  417. 57 TARGETS+=foo
  418. 58 endif
  419. </pre>
  420. <p>First of all, this <i>Makefile</i> example works for a single
  421. binary software. For other software such as libraries or more
  422. complex stuff with multiple binaries, it should be adapted. Look at
  423. the other <code>*.mk</code> files in the <code>package</code>
  424. directory.</p>
  425. <p>At lines 6-11, a couple of useful variables are defined :</p>
  426. <ul>
  427. <li><code>FOO_VERSION</code> : The version of <i>foo</i> that
  428. should be downloaded.</li>
  429. <li><code>FOO_SOURCE</code> : The name of the tarball of
  430. <i>foo</i> on the download website of FTP site. As you can see
  431. <code>FOO_VERSION</code> is used.</li>
  432. <li><code>FOO_SITE</code> : The HTTP or FTP site from which
  433. <i>foo</i> archive is downloaded. It must include the complete
  434. path to the directory where <code>FOO_SOURCE</code> can be
  435. found.</li>
  436. <li><code>FOO_DIR</code> : The directory into which the software
  437. will be configured and compiled. Basically, it's a subdirectory
  438. of <code>BUILD_DIR</code> which is created upon decompression of
  439. the tarball.</li>
  440. <li><code>FOO_BINARY</code> : Software binary name. As said
  441. previously, this is an example for a single binary software.</li>
  442. <li><code>FOO_TARGET_BINARY</code> : The full path of the binary
  443. inside the target filesystem.</li>
  444. </ul>
  445. <p>Lines 13-14 defines a target that downloads the tarball from
  446. the remote site to the download directory
  447. (<code>DL_DIR</code>).</p>
  448. <p>Lines 16-18 defines a target and associated rules that
  449. uncompress the downloaded tarball. As you can see, this target
  450. depends on the tarball file, so that the previous target (line
  451. 13-14) is called before executing the rules of the current
  452. target. Uncompressing is followed by <i>touching</i> a hidden file
  453. to mark the software has having been uncompressed. This trick is
  454. used everywhere in Buildroot <i>Makefile</i> to split steps
  455. (download, uncompress, configure, compile, install) while still
  456. having correct dependencies.</p>
  457. <p>Lines 20-31 defines a target and associated rules that
  458. configures the software. It depends on the previous target (the
  459. hidden <code>.source</code> file) so that we are sure the software has
  460. been uncompressed. In order to configure it, it basically runs the
  461. well-known <code>./configure</code>script. As we may be doing
  462. cross-compilation, <code>target</code>, <code>host</code> and
  463. <code>build</code> arguments are given. The prefix is also set to
  464. <code>/usr</code>, not because the software will be installed in
  465. <code>/usr</code> on your host system, but in the target
  466. filesystem. Finally it creates a <code>.configured</code> file to
  467. mark the software as configured.</p>
  468. <p>Lines 33-34 defines a target and a rule that compiles the
  469. software. This target will create the binary file in the
  470. compilation directory, and depends on the software being already
  471. configured (hence the reference to the <code>.configured</code>
  472. file). It basically runs <code>make</code> inside the source
  473. directory.</p>
  474. <p>Lines 36-38 defines a target and associated rules that install
  475. the software inside the target filesystem. It depends on the
  476. binary file in the source directory, to make sure the software has
  477. been compiled. It uses the <code>install</code> target of the
  478. software <code>Makefile</code> by passing a <code>prefix</code>
  479. argument, so that the <code>Makefile</code> doesn't try to install
  480. the software inside host <code>/usr</code> but inside target
  481. <code>/usr</code>. After the installation, the
  482. <code>/usr/man</code> directory inside the target filesystem is
  483. removed to save space.</p>
  484. <p>Line 40 defines the main target of the software, the one
  485. that will be eventually be used by the top level
  486. <code>Makefile</code> to download, compile, and then install
  487. this package. This target should first of all depends on all
  488. needed dependecies of the software (in our example,
  489. <i>uclibc</i> and <i>ncurses</i>), and also depend on the
  490. final binary. This last dependency will call all previous
  491. dependencies in the correct order. </p>
  492. <p>Line 42 defines a simple target that only downloads the code
  493. source. This is not used during normal operation of Buildroot, but
  494. might be useful.</p>
  495. <p>Lignes 44-46 define a simple target to clean the software build
  496. by calling the <i>Makefiles</i> with the appropriate option.</p>
  497. <p>Lines 48-49 define a simple target to completely remove the
  498. directory in which the software was uncompressed, configured and
  499. compiled.</p>
  500. <p>Lines 51-58 adds the target <code>foo</code> to the list
  501. of targets to be compiled by Buildroot by first checking if
  502. the configuration option for this package has been enabled
  503. using the configuration tool, and if so then "subscribes"
  504. this package to be compiled by adding it to the TARGETS
  505. global variable. The name added to the TARGETS global
  506. variable is the name of this package's target, as defined on
  507. line 40, which is used by Buildroot to download, compile, and
  508. then install this package.</p>
  509. <h3>Conclusion</h3>
  510. <p>As you can see, adding a software to buildroot is simply a
  511. matter of writing a <i>Makefile</i> using an already existing
  512. example and to modify it according to the compilation process of
  513. the software.</p>
  514. <p>If you package software that might be useful for other persons,
  515. don't forget to send a patch to Buildroot developers !</p>
  516. <h2><a name="links" id="links"></a>Ressources</h2>
  517. <p>To learn more about Buildroot you can visit these
  518. websites:</p>
  519. <ul>
  520. <li><a href="http://www.uclibc.org/">http://www.uclibc.org/</a></li>
  521. <li><a href="http://www.busybox.net/">http://www.busybox.net/</a></li>
  522. </ul>
  523. </div>
  524. </body>
  525. </html>