2
1

buildroot.html 28 KB

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