buildroot.html 34 KB

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