buildroot.html 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Buildroot - Usage and documentation</title>
  5. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  6. <link rel="stylesheet" href="stylesheet.css">
  7. </head>
  8. <body>
  9. <div class="main">
  10. <div class="titre">
  11. <h1>Buildroot</h1>
  12. </div>
  13. <p><a href="http://buildroot.net/">Buildroot</a> usage and documentation
  14. by Thomas Petazzoni. Contributions from Karsten Kruse, Ned Ludd, Martin
  15. Herren and others.</p>
  16. <ul>
  17. <li><a href="#about">About Buildroot</a></li>
  18. <li><a href="#download">Obtaining Buildroot</a></li>
  19. <li><a href="#using">Using Buildroot</a></li>
  20. <li><a href="#custom_targetfs">Customizing the generated target filesystem</a></li>
  21. <li><a href="#custom_busybox">Customizing the Busybox configuration</a></li>
  22. <li><a href="#custom_uclibc">Customizing the uClibc configuration</a></li>
  23. <li><a href="#custom_linux26">Customizing the Linux kernel configuration</a></li>
  24. <li><a href="#rebuilding_packages">Understanding how to rebuild packages</a></li>
  25. <li><a href="#buildroot_innards">How Buildroot works</a></li>
  26. <li><a href="#using_toolchain">Using the uClibc toolchain outside Buildroot</a></li>
  27. <li><a href="#external_toolchain">Use an external toolchain</a></li>
  28. <li><a href="#ccache-support">Using <code>ccache</code> in Buildroot</li>
  29. <li><a href="#downloaded_packages">Location of downloaded packages</a></li>
  30. <li><a href="#add_packages">Adding new packages to Buildroot</a></li>
  31. <li><a href="#board_support">Creating your own board support</a></li>
  32. <li><a href="#faq">Frequently asked questions</a></li>
  33. <li><a href="#links">Resources</a></li>
  34. </ul>
  35. <h2 id="about">About Buildroot</h2>
  36. <p>Buildroot is a set of Makefiles and patches that allows you to easily
  37. generate a cross-compilation toolchain, a root filesystem and a Linux
  38. kernel image for your target. Buildroot can be used for one, two or all
  39. of these options, independently.</p>
  40. <p>Buildroot is useful mainly for people working with embedded systems.
  41. Embedded systems often use processors that are not the regular x86
  42. processors everyone is used to having in his PC. They can be PowerPC
  43. processors, MIPS processors, ARM processors, etc.</p>
  44. <p>A compilation toolchain is the set of tools that allows you to
  45. compile code for your system. It consists of a compiler (in our case,
  46. <code>gcc</code>), binary utils like assembler and linker (in our case,
  47. <code>binutils</code>) and a C standard library (for example
  48. <a href="http://www.gnu.org/software/libc/libc.html">GNU Libc</a>,
  49. <a href="http://www.uclibc.org/">uClibc</a> or
  50. <a href="http://www.fefe.de/dietlibc/">dietlibc</a>). The system installed
  51. on your development station certainly already has a compilation
  52. toolchain that you can use to compile an application that runs on your
  53. system. If you're using a PC, your compilation toolchain runs on an x86
  54. processor and generates code for an x86 processor. Under most Linux
  55. systems, the compilation toolchain uses the GNU libc (glibc) as the C
  56. standard library. This compilation toolchain is called the &quot;host
  57. compilation toolchain&quot;. The machine on which it is running, and on
  58. which you're working, is called the &quot;host system&quot;. The
  59. compilation toolchain is provided by your distribution, and Buildroot
  60. has nothing to do with it (other than using it to build a
  61. cross-compilation toolchain and other tools that are run on the
  62. development host).</p>
  63. <p>As said above, the compilation toolchain that comes with your system
  64. runs on and generates code for the processor in your host system. As
  65. your embedded system has a different processor, you need a
  66. cross-compilation toolchain &mdash; a compilation toolchain that runs on
  67. your host system but generates code for your target system (and target
  68. processor). For example, if your host system uses x86 and your target
  69. system uses ARM, the regular compilation toolchain on your host runs on
  70. x86 and generates code for x86, while the cross-compilation toolchain
  71. runs on x86 and generates code for ARM.</p>
  72. <p>Even if your embedded system uses an x86 processor, you might be
  73. interested in Buildroot for two reasons:</p>
  74. <ul>
  75. <li>The compilation toolchain on your host certainly uses the GNU Libc
  76. which is a complete but huge C standard library. Instead of using GNU
  77. Libc on your target system, you can use uClibc which is a tiny C
  78. standard library. If you want to use this C library, then you need a
  79. compilation toolchain to generate binaries linked with it. Buildroot
  80. can do that for you.</li>
  81. <li>Buildroot automates the building of a root filesystem with all needed
  82. tools like busybox. That makes it much easier than doing it by hand.</li>
  83. </ul>
  84. <p>You might wonder why such a tool is needed when you can compile
  85. <code>gcc</code>, <code>binutils</code>, <code>uClibc</code> and all
  86. the other tools by hand. Of course doing so is possible but, dealing with
  87. all of the configure options and problems of every <code>gcc</code> or
  88. <code>binutils</code> version is very time-consuming and uninteresting.
  89. Buildroot automates this process through the use of Makefiles and has a
  90. collection of patches for each <code>gcc</code> and <code>binutils</code>
  91. version to make them work on most architectures.</p>
  92. <p>Moreover, Buildroot provides an infrastructure for reproducing
  93. the build process of your kernel, cross-toolchain, and embedded root
  94. filesystem. Being able to reproduce the build process will be useful when a
  95. component needs to be patched or updated or when another person is supposed
  96. to take over the project.</p>
  97. <h2 id="download">Obtaining Buildroot</h2>
  98. <p>Buildroot releases are made approximately every 3
  99. months. Direct Git access and daily snapshots are also
  100. available, if you want more bleeding edge.</p>
  101. <p>Releases are available at
  102. <a href="http://buildroot.net/downloads/">http://buildroot.net/downloads/</a>.</p>
  103. <p>The latest snapshot is always available at
  104. <a href="http://buildroot.net/downloads/snapshots/buildroot-snapshot.tar.bz2">http://buildroot.net/downloads/snapshots/buildroot-snapshot.tar.bz2</a>,
  105. and previous snapshots are also available at
  106. <a href="http://buildroot.net/downloads/snapshots/">http://buildroot.net/downloads/snapshots/</a>.</p>
  107. <p>To download Buildroot using Git, you can simply follow
  108. the rules described on the &quot;Accessing Git&quot; page
  109. (<a href= "http://buildroot.net/git.html">http://buildroot.net/git.html</a>)
  110. of the Buildroot website
  111. (<a href="http://buildroot.net">http://buildroot.net</a>).
  112. For the impatient, here's a quick recipe:</p>
  113. <pre>
  114. $ git clone git://git.buildroot.net/buildroot
  115. </pre>
  116. <h2 id="using">Using Buildroot</h2>
  117. <p>Buildroot has a nice configuration tool similar to the one you can find
  118. in the Linux kernel
  119. (<a href="http://www.kernel.org/">http://www.kernel.org/</a>) or in Busybox
  120. (<a href="http://www.busybox.org/">http://www.busybox.org/</a>). Note that
  121. you can (and should) build everything as a normal user. There is no need to
  122. be root to configure and use Buildroot. The first step is to run the
  123. configuration assistant:</p>
  124. <pre>
  125. $ make menuconfig
  126. </pre>
  127. <p>to run the curses-based configurator, or</p>
  128. <pre>
  129. $ make xconfig
  130. </pre>
  131. <p>or</p>
  132. <pre>
  133. $ make gconfig
  134. </pre>
  135. <p>to run the Qt3 or GTK-based configurators.</p>
  136. <p>All of these "make" commands will need to build a configuration
  137. utility, so you may need to install "development" packages for relevant
  138. libraries used by the configuration utilities. On Debian-like systems,
  139. the <code>libncurses5-dev</code> package is required to use the <i>
  140. menuconfig</i> interface, <code>libqt3-mt-dev</code> is required to use
  141. the <i>xconfig</i> interface, and <code>libglib2.0-dev, libgtk2.0-dev
  142. and libglade2-dev</code> are needed to use the <i>gconfig</i> interface.</p>
  143. <p>For each menu entry in the configuration tool, you can find associated
  144. help that describes the purpose of the entry.</p>
  145. <p>Once everything is configured, the configuration tool generates a
  146. <code>.config</code> file that contains the description of your
  147. configuration. It will be used by the Makefiles to do what's needed.</p>
  148. <p>Let's go:</p>
  149. <pre>
  150. $ make
  151. </pre>
  152. <p>You <b>should never</b> use <code>make -jN</code> with
  153. Buildroot: it does not support <i>top-level parallel
  154. make</i>. Instead, use the <code>BR2_JLEVEL</code> option to tell
  155. Buildroot to run each package compilation with <pre>make
  156. -jN</pre>.</p>
  157. <p>This command will generally perform the following steps:</p>
  158. <ul>
  159. <li>Download source files (as required)</li>
  160. <li>Configure, build and install the cross-compiling toolchain
  161. if an internal toolchain is used, or import a toolchain if an
  162. external toolchain is used</li>
  163. <li>Build/install selected target packages</li>
  164. <li>Build a kernel image, if selected</li>
  165. <li>Build a bootloader image, if selected</li>
  166. <li>Create a root filesystem in selected formats</li>
  167. </ul>
  168. <p>Buildroot output is stored in a single directory, <code>output/</code>.
  169. This directory contains several subdirectories:</p>
  170. <ul>
  171. <li><code>images/</code> where all the images (kernel image,
  172. bootloader and root filesystem images) are stored.</li>
  173. <li><code>build/</code> where all the components except for the
  174. cross-compilation toolchain are built (this includes tools needed to
  175. run Buildroot on the host and packages compiled for the target). The
  176. <code>build/</code> directory contains one subdirectory for each of
  177. these components.</li>
  178. <li><code>staging/</code> which contains a hierarchy similar to a root
  179. filesystem hierarchy. This directory contains the installation of the
  180. cross-compilation toolchain and all the userspace packages selected
  181. for the target. However, this directory is <i>not</i> intended to be
  182. the root filesystem for the target: it contains a lot of development
  183. files, unstripped binaries and libraries that make it far too big for
  184. an embedded system. These development files are used to compile
  185. libraries and applications for the target that depend on other
  186. libraries.</li>
  187. <li><code>target/</code> which contains <i>almost</i> the complete
  188. root filesystem for the target: everything needed is present except
  189. the device files in <code>/dev/</code> (Buildroot can't create them
  190. because Buildroot doesn't run as root and doesn't want to run as
  191. root). Therefore, this directory <b>should not be used on your target</b>.
  192. Instead, you should use one of the images built in the
  193. <code>images/</code> directory. If you need an extracted image of the
  194. root filesystem for booting over NFS, then use the tarball image
  195. generated in <code>images/</code> and extract it as root.<br/>Compared
  196. to <code>staging/</code>, <code>target/</code> contains only the
  197. files and libraries needed to run the selected target applications:
  198. the development files (headers, etc.) are not present, unless the
  199. <code>development files in target filesystem</code> option is selected.
  200. </li>
  201. <li><code>host/</code> contains the installation of tools compiled for
  202. the host that are needed for the proper execution of Buildroot, except
  203. for the cross-compilation toolchain which is installed under
  204. <code>staging/</code>.</li>
  205. <li><code>toolchain/</code> contains the build directories for the
  206. various components of the cross-compilation toolchain.</li>
  207. </ul>
  208. <h3 id="offline_builds">Offline builds</h3>
  209. <p>If you intend to do an offline build and just want to download
  210. all sources that you previously selected in the configurator
  211. (<i>menuconfig</i>, <i>xconfig</i> or <i>gconfig</i>), then issue:</p>
  212. <pre>
  213. $ make source
  214. </pre>
  215. <p>You can now disconnect or copy the content of your <code>dl</code>
  216. directory to the build-host.</p>
  217. <h3 id="building_out_of_tree">Building out-of-tree</h3>
  218. <p>Buildroot supports building out of tree with a syntax similar to the
  219. Linux kernel. To use it, add O=&lt;directory&gt; to the make command
  220. line:</p>
  221. <pre>
  222. $ make O=/tmp/build
  223. </pre>
  224. <p>Or:</p>
  225. <pre>
  226. $ cd /tmp/build; make O=$PWD -C path/to/buildroot
  227. </pre>
  228. <p>All the output files will be located under <code>/tmp/build</code>.</p>
  229. <p>When using out-of-tree builds, the Buildroot <code>.config</code> and
  230. temporary files are also stored in the output directory. This means that
  231. you can safely run multiple builds in parallel using the same source
  232. tree as long as they use unique output directories.</p>
  233. <p>For ease of use, Buildroot generates a Makefile wrapper in the output
  234. directory - So after the first run, you no longer need to pass
  235. <code>O=..</code> and <code>-C ..</code>, simply run (in the output
  236. directory):</p>
  237. <pre>
  238. $ make &lt;target&gt;
  239. </pre>
  240. <h3 id="environment_variables">Environment variables</h3>
  241. <p>Buildroot also honors some environment variables, when they are passed
  242. to <code>make</code> or set in the environment:</p>
  243. <ul>
  244. <li><code>HOSTCXX</code>, the host C++ compiler to use</li>
  245. <li><code>HOSTCC</code>, the host C compiler to use</li>
  246. <li><code>UCLIBC_CONFIG_FILE=&lt;path/to/.config&gt;</code>, path to
  247. the uClibc configuration file, used to compile uClibc, if an
  248. internal toolchain is being built</li>
  249. <li><code>BUSYBOX_CONFIG_FILE=&lt;path/to/.config&gt;</code>, path to
  250. the Busybox configuration file</li>
  251. <li><code>BUILDROOT_DL_DIR</code> to override the directory in which
  252. Buildroot stores/retrieves downloaded files</li>
  253. </ul>
  254. <p>An example that uses config files located in the toplevel directory and
  255. in your $HOME:</p>
  256. <pre>
  257. $ make UCLIBC_CONFIG_FILE=uClibc.config BUSYBOX_CONFIG_FILE=$HOME/bb.config
  258. </pre>
  259. <p>If you want to use a compiler other than the default <code>gcc</code>
  260. or <code>g++</code> for building helper-binaries on your host, then do</p>
  261. <pre>
  262. $ make HOSTCXX=g++-4.3-HEAD HOSTCC=gcc-4.3-HEAD
  263. </pre>
  264. <h2 id="custom_targetfs">Customizing the generated target filesystem</h2>
  265. <p>There are a few ways to customize the resulting target filesystem:</p>
  266. <ul>
  267. <li>Customize the target filesystem directly and rebuild the image.
  268. The target filesystem is available under <code>output/target/</code>.
  269. You can simply make your changes here and run make afterwards &mdash;
  270. this will rebuild the target filesystem image. This method allows you
  271. to do anything to the target filesystem, but if you decide to
  272. completely rebuild your toolchain and tools, these changes will be
  273. lost.</li>
  274. <li>Create your own <i>target skeleton</i>. You can start with
  275. the default skeleton available under <code>fs/skeleton</code>
  276. and then customize it to suit your
  277. needs. The <code>BR2_ROOTFS_SKELETON_CUSTOM</code>
  278. and <code>BR2_ROOTFS_SKELETON_CUSTOM_PATH</code> will allow you
  279. to specify the location of your custom skeleton. At build time,
  280. the contents of the skeleton are copied to output/target before
  281. any package installation.</li>
  282. <li>Add support for your own target in Buildroot, so that you
  283. have your own target skeleton (see <a href="#board_support">this
  284. section</a> for details).</li>
  285. <li>In the Buildroot configuration, you can specify the path to a
  286. post-build script, that gets called <i>after</i> Buildroot builds all
  287. the selected software, but <i>before</i> the rootfs packages are
  288. assembled. The destination root filesystem folder is given as the
  289. first argument to this script, and this script can then be used to
  290. copy programs, static data or any other needed file to your target
  291. filesystem.<br/>You should, however, use this feature with care.
  292. Whenever you find that a certain package generates wrong or unneeded
  293. files, you should fix that package rather than work around it with a
  294. post-build cleanup script.</li>
  295. <li>A special package, <i>customize</i>, stored in
  296. <code>package/customize</code> can be used. You can put all the
  297. files that you want to see in the final target root filesystem
  298. in <code>package/customize/source</code>, and then enable this
  299. special package in the configuration system.</li>
  300. </ul>
  301. <h2 id="custom_busybox">Customizing the Busybox configuration</h2>
  302. <p><a href="http://www.busybox.net/">Busybox</a> is very configurable,
  303. and you may want to customize it. You can follow these simple steps to
  304. do so. This method isn't optimal, but it's simple, and it works:</p>
  305. <ol>
  306. <li>Do an initial compilation of Buildroot, with busybox, without
  307. trying to customize it.</li>
  308. <li>Invoke <code>make busybox-menuconfig</code>.
  309. The nice configuration tool appears, and you can
  310. customize everything.</li>
  311. <li>Run the compilation of Buildroot again.</li>
  312. </ol>
  313. <p>Otherwise, you can simply change the
  314. <code>package/busybox/busybox-&lt;version&gt;.config</code> file, if you
  315. know the options you want to change, without using the configuration tool.
  316. </p>
  317. <p>If you want to use an existing config file for busybox, then see
  318. section <a href="#environment_variables">environment variables</a>.</p>
  319. <h2 id="custom_uclibc">Customizing the uClibc configuration</h2>
  320. <p>Just like <a href="#custom_busybox">BusyBox</a>,
  321. <a href="http://www.uclibc.org/">uClibc</a> offers a lot of
  322. configuration options. They allow you to select various
  323. functionalities depending on your needs and limitations.</p>
  324. <p>The easiest way to modify the configuration of uClibc is to
  325. follow these steps:</p>
  326. <ol>
  327. <li>Do an initial compilation of Buildroot without trying to
  328. customize uClibc.</li>
  329. <li>Invoke <code>make uclibc-menuconfig</code>.
  330. The nice configuration assistant, similar to
  331. the one used in the Linux kernel or Buildroot, appears. Make
  332. your configuration changes as appropriate.</li>
  333. <li>Copy the <code>.config</code> file to
  334. <code>toolchain/uClibc/uClibc.config</code> or
  335. <code>toolchain/uClibc/uClibc.config-locale</code>. The former
  336. is used if you haven't selected locale support in Buildroot
  337. configuration, and the latter is used if you have selected
  338. locale support.</li>
  339. <li>Run the compilation of Buildroot again.</li>
  340. </ol>
  341. <p>Otherwise, you can simply change
  342. <code>toolchain/uClibc/uClibc.config</code> or
  343. <code>toolchain/uClibc/uClibc.config-locale</code>, without running
  344. the configuration assistant.</p>
  345. <p>If you want to use an existing config file for uclibc, then see
  346. section <a href="#environment_variables">environment variables</a>.</p>
  347. <h2 id="custom_linux26">Customizing the Linux kernel configuration</h2>
  348. <p>The Linux kernel configuration can be customized just like
  349. <a href="#custom_busybox">BusyBox</a> and
  350. <a href="#custom_uclibc">uClibc</a> using <code>make linux-menuconfig
  351. </code>. Make sure you have enabled the kernel build in <code>make
  352. menuconfig</code> first. Once done, run <code>make</code> to (re)build
  353. everything.</p>
  354. <p>If you want to use an existing config file for Linux, then see
  355. section <a href="#environment_variables">environment variables</a>.</p>
  356. <h2 id="rebuilding_packages">Understanding how to rebuild packages</h2>
  357. <p>One of the most common questions asked by Buildroot
  358. users is how to rebuild a given package or how to
  359. remove a package without rebuilding everything from scratch.</p>
  360. <p>Removing a package is currently unsupported by Buildroot
  361. without rebuilding from scratch. This is because Buildroot doesn't
  362. keep track of which package installs what files in the
  363. <code>output/staging</code> and <code>output/target</code>
  364. directories. However, implementing clean package removal is on the
  365. TODO-list of Buildroot developers.</p>
  366. <p>The easiest way to rebuild a single package from scratch is to
  367. remove its build directory in <code>output/build</code>. Buildroot
  368. will then re-extract, re-configure, re-compile and re-install this
  369. package from scratch.</p>
  370. <p>However, if you don't want to rebuild the package completely
  371. from scratch, a better understanding of the Buildroot internals is
  372. needed. Internally, to keep track of which steps have been done
  373. and which steps remain to be done, Buildroot maintains stamp
  374. files (empty files that just tell whether this or that action
  375. has been done). The problem is that these stamp files are not
  376. uniformly named and handled by the different packages, so some
  377. understanding of the particular package is needed.</p>
  378. <p>For packages relying on Buildroot packages infrastructures (see
  379. <a href="#add_packages">this section</a> for details), the
  380. following stamp files are relevant:</p>
  381. <ul>
  382. <li><code>output/build/packagename-version/.stamp_configured</code>. If
  383. removed, Buildroot will trigger the recompilation of the package
  384. from the configuration step (execution of
  385. <code>./configure</code>).</li>
  386. <li><code>output/build/packagename-version/.stamp_built</code>. If
  387. removed, Buildroot will trigger the recompilation of the package
  388. from the compilation step (execution of <code>make</code>).</li>
  389. </ul>
  390. <p>For other packages, an analysis of the specific <i>package.mk</i>
  391. file is needed. For example, the zlib Makefile used to look like this
  392. (before it was converted to the generic package infrastructure):</p>
  393. <pre>
  394. $(ZLIB_DIR)/.configured: $(ZLIB_DIR)/.patched
  395. (cd $(ZLIB_DIR); rm -rf config.cache; \
  396. [...]
  397. )
  398. touch $@
  399. $(ZLIB_DIR)/libz.a: $(ZLIB_DIR)/.configured
  400. $(MAKE) -C $(ZLIB_DIR) all libz.a
  401. touch -c $@
  402. </pre>
  403. <p>If you want to trigger the reconfiguration, you need to
  404. remove <code>output/build/zlib-version/.configured</code>. If
  405. you want to trigger only the recompilation, you need to remove
  406. <code>output/build/zlib-version/libz.a</code>.</p>
  407. <p>Note that most packages, if not all, will progressively be
  408. ported over to the generic or autotools infrastructure, making it
  409. much easier to rebuild individual packages.</p>
  410. <h2 id="buildroot_innards">How Buildroot works</h2>
  411. <p>As mentioned above, Buildroot is basically a set of Makefiles that
  412. download, configure, and compile software with the correct options. It
  413. also includes patches for various software packages &mdash; mainly the
  414. ones involved in the cross-compilation tool chain (<code>gcc</code>,
  415. <code>binutils</code> and <code>uClibc</code>).</p>
  416. <p>There is basically one Makefile per software package, and they are
  417. named with the <code>.mk</code> extension. Makefiles are split into
  418. three main sections:</p>
  419. <ul>
  420. <li><b>toolchain</b> (in the <code>toolchain/</code> directory) contains
  421. the Makefiles and associated files for all software related to the
  422. cross-compilation toolchain: <code>binutils</code>, <code>gcc</code>,
  423. <code>gdb</code>, <code>kernel-headers</code> and <code>uClibc</code>.</li>
  424. <li><b>package</b> (in the <code>package/</code> directory) contains the
  425. Makefiles and associated files for all user-space tools that Buildroot
  426. can compile and add to the target root filesystem. There is one
  427. sub-directory per tool.</li>
  428. <li><b>target</b> (in the <code>target</code> directory) contains the
  429. Makefiles and associated files for software related to the generation of
  430. the target root filesystem image. Four types of filesystems are supported:
  431. ext2, jffs2, cramfs and squashfs. For each of them there is a
  432. sub-directory with the required files. There is also a
  433. <code>default/</code> directory that contains the target filesystem
  434. skeleton.</li>
  435. </ul>
  436. <p>Each directory contains at least 2 files:</p>
  437. <ul>
  438. <li><code>something.mk</code> is the Makefile that downloads, configures,
  439. compiles and installs the package <code>something</code>.</li>
  440. <li><code>Config.in</code> is a part of the configuration tool
  441. description file. It describes the options related to the
  442. package.</li>
  443. </ul>
  444. <p>The main Makefile performs the following steps (once the
  445. configuration is done):</p>
  446. <ol>
  447. <li>Create all the output directories: <code>staging</code>,
  448. <code>target</code>, <code>build</code>, <code>stamps</code>,
  449. etc. in the output directory (<code>output/</code> by default,
  450. another value can be specified using <code>O=</code>)</li>
  451. <li>Generate all the targets listed in the
  452. <code>BASE_TARGETS</code> variable. When an internal toolchain
  453. is used, this means generating the cross-compilation
  454. toolchain. When an external toolchain is used, this means checking
  455. the features of the external toolchain and importing it into the
  456. Buildroot environment.</li>
  457. <li>Generate all the targets listed in the <code>TARGETS</code>
  458. variable. This variable is filled by all the individual
  459. components' Makefiles. Generating these targets will
  460. trigger the compilation of the userspace packages (libraries,
  461. programs), the kernel, the bootloader and the generation of the
  462. root filesystem images, depending on the configuration.</li>
  463. </ol>
  464. <h2 id="board_support"> Creating your own board support</h2>
  465. <p>Creating your own board support in Buildroot allows users of a
  466. particular hardware platform to easily build a system that is
  467. known to work.</p>
  468. <p>To do so, you need to create a normal Buildroot configuration
  469. that builds a basic system for the hardware: toolchain, kernel,
  470. bootloader, filesystem and a simple Busybox-only userspace. No
  471. specific package should be selected: the configuration should be
  472. as minimal as possible, and should only build a working basic
  473. Busybox system for the target platform. You can of course use more
  474. complicated configurations for your internal projects, but the
  475. Buildroot project will only integrate basic board
  476. configurations. This is because package selections are highly
  477. application-specific.</p>
  478. <p>Once you have a known working configuration, run <code>make
  479. savedefconfig</code>. This will generate a
  480. minimal <code>defconfig</code> file at the root of the Buildroot
  481. source tree. Move this file into the <code>configs/</code>
  482. directory, and rename it <code>MYBOARD_defconfig</code>.</p>
  483. <p>It is recommended to use as much as possible upstream versions
  484. of the Linux kernel and bootloaders, and to use as much as
  485. possible default kernel and bootloader configurations. If they are
  486. incorrect for your platform, we encourage you to send fixes to the
  487. corresponding upstream projects.</p>
  488. <p>However, in the mean time, you may want to store kernel or
  489. bootloader configuration or patches specific to your target
  490. platform. To do so, create a
  491. directory <code>board/MANUFACTURER</code> and a
  492. subdirectory <code>board/MANUFACTURER/BOARDNAME</code> (after
  493. replacing, of course, MANUFACTURER and BOARDNAME with the
  494. appropriate values, in lower case letters). You can then store
  495. your patches and configurations in these directories, and
  496. reference them from the main Buildroot configuration.</p>
  497. <h2 id="using_toolchain">Using the generated toolchain outside Buildroot</h2>
  498. <p>You may want to compile, for your target, your own programs or other
  499. software that are not packaged in Buildroot. In order to do this you can
  500. use the toolchain that was generated by Buildroot.</p>
  501. <p>The toolchain generated by Buildroot is located by default in
  502. <code>output/staging/</code>. The simplest way to use it is to add
  503. <code>output/staging/usr/bin/</code> to your PATH environment variable and
  504. then to use <code>ARCH-linux-gcc</code>, <code>ARCH-linux-objdump</code>,
  505. <code>ARCH-linux-ld</code>, etc.</p>
  506. <p>It is possible to relocate the toolchain &mdash; but
  507. then <code>--sysroot</code> must be passed every time the compiler
  508. is called to tell where the libraries and header files are.</p>
  509. <p>It is also possible to generate the Buildroot toolchain in a
  510. directory other than <code>output/staging</code> by using the <code>
  511. Build options -&gt; Toolchain and header file location</code> options.
  512. This could be useful if the toolchain must be shared with other users.</p>
  513. <h2 id="ccache-support">Using <code>ccache</code> in Buildroot</h2>
  514. <p><a href="http://ccache.samba.org">ccache</a> is a compiler
  515. cache. It stores the object files resulting from each compilation
  516. process, and is able to skip future compilation of the same source
  517. file (with same compiler and same arguments) by using the
  518. pre-existing object files. When doing almost identical builds from
  519. scratch a number of times, it can nicely speed up the build
  520. process.</p>
  521. <p><code>ccache</code> support is integrated in Buildroot. You
  522. just have to enable <code>Enable compiler cache</code>
  523. in <code>Build options</code>. This will automatically build
  524. <code>ccache</code> and use it for every host and target
  525. compilation.</p>
  526. <p>The cache is located
  527. in <code>$HOME/.buildroot-ccache</code>. It is stored outside of
  528. Buildroot output directory so that it can be shared by separate
  529. Buildroot builds. If you want to get rid of the cache, simply
  530. remove this directory.</p>
  531. <p>You can get statistics on the cache (its size, number of hits,
  532. misses, etc.) by running <code>make ccache-stats</code>.</p>
  533. <h2 id="downloaded_packages">Location of downloaded packages</h2>
  534. <p>It might be useful to know that the various tarballs that are
  535. downloaded by the Makefiles are all stored in the <code>DL_DIR</code>
  536. which by default is the <code>dl</code> directory. It's useful, for
  537. example, if you want to keep a complete version of Buildroot which is
  538. known to be working with the associated tarballs. This will allow you to
  539. regenerate the toolchain and the target filesystem with exactly the same
  540. versions.</p>
  541. <p>If you maintain several Buildroot trees, it might be better to have a
  542. shared download location. This can be accessed by creating a symbolic
  543. link from the <code>dl</code> directory to the shared download location:</p>
  544. <pre>
  545. $ ln -s &lt;shared download location&gt; dl
  546. </pre>
  547. <p>Another way of accessing a shared download location is to
  548. create the <code>BUILDROOT_DL_DIR</code> environment variable.
  549. If this is set, then the value of DL_DIR in the project is
  550. overridden. The following line should be added to
  551. <code>&quot;~/.bashrc&quot;</code>.</p>
  552. <pre>
  553. $ export BUILDROOT_DL_DIR &lt;shared download location&gt;
  554. </pre>
  555. <h2 id="external_toolchain">Using an external toolchain</h2>
  556. <p>Using an already existing toolchain is useful for different
  557. reasons:</p>
  558. <ul>
  559. <li>you already have a toolchain that is known to work for your
  560. specific CPU</li>
  561. <li>you want to speed up the Buildroot build process by skipping
  562. the long toolchain build part</li>
  563. <li>the toolchain generation feature of Buildroot is not
  564. sufficiently flexible for you (for example if you need to
  565. generate a system with <i>glibc</i> instead of
  566. <i>uClibc</i>)</li>
  567. </ul>
  568. <p>Buildroot supports using existing toolchains through a
  569. mechanism called <i>external toolchain</i>.</p>
  570. <p>To enable the use of an external toolchain, go to the
  571. <code>Toolchain</code> menu, and :</p>
  572. <ul>
  573. <li>Select the <code>External binary toolchain</code> toolchain
  574. type</li>
  575. <li>Select the appropriate <code>External toolchain C
  576. library</code></li>
  577. <li>Select the appropriate values for <code>Enable large
  578. file</code>, <code>Enable IPv6</code>, <code>Enable
  579. RPC</code>, <code>Enable toolchain
  580. locale/i18n</code>, <code>Enable WCHAR</code>, <code>Enable
  581. program invocation</code>, <code>Build/install c++ compiler and
  582. libstdc++</code>, according to the configuration of your
  583. external toolchain. Buildroot will check those values at the
  584. beginning of the compilation process and will tell you if you
  585. used incorrect values.</li>
  586. <li>Adjust the <code>External toolchain path</code>
  587. appropriately. It should be set to a path where a bin/ directory
  588. contains your cross-compiling tools</li>
  589. <li>Adjust the <code>External toolchain prefix</code> so that the
  590. prefix, suffixed with <code>-gcc</code> or <code>-ld</code> will
  591. correspond to your cross-compiling tools</li>
  592. </ul>
  593. <p>Our external toolchain support has been tested with toolchains
  594. from CodeSourcery, toolchains generated
  595. by <a href="http://ymorin.is-a-geek.org/dokuwiki/projects/crosstool">Crosstool-NG</a>,
  596. and toolchains generated by Buildroot itself. In general, all
  597. toolchains that support the <i>sysroot</i> feature should
  598. work. If not, do not hesitate to contact the developers.</p>
  599. <h2 id="add_packages">Adding new packages to Buildroot</h2>
  600. <p>This section covers how new packages (userspace libraries or
  601. applications) can be integrated into Buildroot. It also shows how existing
  602. packages are integrated, which is needed for fixing issues or tuning their
  603. configuration.</p>
  604. <ul>
  605. <li><a href="#package-directory">Package directory</a></li>
  606. <li><a href="#config-in-file"><code>Config.in</code> file</a></li>
  607. <li><a href="#mk-file">The <code>.mk</code> file</a>
  608. <ul>
  609. <li><a href="#generic-tutorial">Makefile for generic packages : tutorial</a></li>
  610. <li><a href="#generic-reference">Makefile for generic packages : reference</a></li>
  611. <li><a href="#autotools-tutorial">Makefile for autotools-based packages : tutorial</a></li>
  612. <li><a href="#autotools-reference">Makefile for autotools-based packages : reference</a></li>
  613. <li><a href="#manual-tutorial">Manual Makefile : tutorial</a></li>
  614. </ul>
  615. </li>
  616. <li><a href="#gettext-integration">Gettext integration and interaction with packages</a></li>
  617. </ul>
  618. <h3 id="package-directory">Package directory</h3>
  619. <p>First of all, create a directory under the <code>package</code>
  620. directory for your software, for example <code>libfoo</code>.</p>
  621. <p>Some packages have been grouped by topic in a sub-directory:
  622. <code>multimedia</code>, <code>java</code>, <code>x11r7</code>, and
  623. <code>games</code>. If your package fits in one of these
  624. categories, then create your package directory in these.</p>
  625. <h3 id="config-in-file"><code>Config.in</code> file</h3>
  626. <p>Then, create a file named <code>Config.in</code>. This file
  627. will contain the option descriptions related to our
  628. <code>libfoo</code> software that will be used and displayed in the
  629. configuration tool. It should basically contain :</p>
  630. <pre>
  631. config BR2_PACKAGE_LIBFOO
  632. bool "libfoo"
  633. help
  634. This is a comment that explains what libfoo is.
  635. http://foosoftware.org/libfoo/
  636. </pre>
  637. <p>Of course, you can add other options to configure particular
  638. things in your software. You can look at examples in other
  639. packages. The syntax of the Config.in file is the same as the one
  640. for the kernel Kconfig file. The documentation for this syntax is
  641. available at
  642. <a href="http://lxr.free-electrons.com/source/Documentation/kbuild/kconfig-language.txt">http://lxr.free-electrons.com/source/Documentation/kbuild/kconfig-language.txt</a>
  643. </p>
  644. <p>Finally you have to add your new <code>libfoo/Config.in</code> to
  645. <code>package/Config.in</code> (or in a category subdirectory if
  646. you decided to put your package in one of the existing
  647. categories). The files included there are <em>sorted
  648. alphabetically</em> per category and are <em>NOT</em> supposed to
  649. contain anything but the <em>bare</em> name of the package.</p>
  650. <pre>
  651. source "package/libfoo/Config.in"
  652. </pre>
  653. <h3 id="mk-file">The <code>.mk</code> file</h3>
  654. <p>Finally, here's the hardest part. Create a file named
  655. <code>libfoo.mk</code>. It describes how the package should be
  656. downloaded, configured, built, installed, etc.</p>
  657. <p>Depending on the package type, the <code>.mk</code> file must be
  658. written in a different way, using different infrastructures:</p>
  659. <ul>
  660. <li><b>Makefiles for generic packages</b> (not using autotools): These
  661. are based on an infrastructure similar to the one used for
  662. autotools-based packages, but requires a little more work from the
  663. developer. They specify what should be done for the configuration,
  664. compilation, installation and cleanup of the package. This
  665. infrastructure must be used for all packages that do not use the
  666. autotools as their build system. In the future, other specialized
  667. infrastructures might be written for other build systems.<br/>We cover
  668. them through a <a href="#generic-tutorial">tutorial</a> and a
  669. <a href="#generic-reference">reference</a>.</li>
  670. <li><b>Makefiles for autotools-based software</b> (autoconf, automake,
  671. etc.): We provide a dedicated infrastructure for such packages, since
  672. autotools is a very common build system. This infrastructure <i>must
  673. </i> be used for new packages that rely on the autotools as their
  674. build system.<br/>We cover them through a
  675. <a href="#autotools-tutorial">tutorial</a> and a
  676. <a href="#autotools-reference">reference</a>.</li>
  677. <li><b>Manual Makefiles:</b> These are currently obsolete, and no new
  678. manual Makefiles should be added. However, since there are still many
  679. of them in the tree, we keep them documented in a
  680. <a href="#manual-tutorial">tutorial</a>.</li>
  681. </ul>
  682. <h4 id="generic-tutorial">Makefile for generic packages : tutorial</h4>
  683. <pre>
  684. <span style="color: #000000">01:</span><span style="font-style: italic; color: #9A1900"> #############################################################</span>
  685. <span style="color: #000000">02:</span><span style="font-style: italic; color: #9A1900"> #</span>
  686. <span style="color: #000000">03:</span><span style="font-style: italic; color: #9A1900"> # libfoo</span>
  687. <span style="color: #000000">04:</span><span style="font-style: italic; color: #9A1900"> #</span>
  688. <span style="color: #000000">05:</span><span style="font-style: italic; color: #9A1900"> #############################################################</span>
  689. <span style="color: #000000">06:</span><span style="color: #009900"> LIBFOO_VERSION</span> = 1.0
  690. <span style="color: #000000">07:</span><span style="color: #009900"> LIBFOO_SOURCE</span> = libfoo-<span style="color: #009900">$(LIBFOO_VERSION)</span>.tar.gz
  691. <span style="color: #000000">08:</span><span style="color: #009900"> LIBFOO_SITE</span> = http://www.foosoftware.org/download
  692. <span style="color: #000000">09:</span><span style="color: #009900"> LIBFOO_INSTALL_STAGING</span> = YES
  693. <span style="color: #000000">10:</span><span style="color: #009900"> LIBFOO_DEPENDENCIES</span> = host-libaaa libbbb
  694. <span style="color: #000000">11:</span>
  695. <span style="color: #000000">12:</span> define LIBFOO_BUILD_CMDS
  696. <span style="color: #000000">13:</span> <span style="color: #009900">$(MAKE)</span> CC=<span style="color: #009900">$(TARGET_CC)</span> LD=<span style="color: #009900">$(TARGET_LD)</span> -C <span style="color: #009900">$(@D)</span> all
  697. <span style="color: #000000">14:</span> endef
  698. <span style="color: #000000">15:</span>
  699. <span style="color: #000000">16:</span> define LIBFOO_INSTALL_STAGING_CMDS
  700. <span style="color: #000000">17:</span> <span style="color: #009900">$(INSTALL)</span> -D -m 0755 <span style="color: #009900">$(@D)</span>/libfoo.a <span style="color: #009900">$(STAGING_DIR)</span>/usr/lib/libfoo.a
  701. <span style="color: #000000">18:</span> <span style="color: #009900">$(INSTALL)</span> -D -m 0644 <span style="color: #009900">$(@D)</span>/foo.h <span style="color: #009900">$(STAGING_DIR)</span>/usr/include/foo.h
  702. <span style="color: #000000">19:</span> <span style="color: #009900">$(INSTALL)</span> -D -m 0755 <span style="color: #009900">$(@D)</span>/libfoo.so* <span style="color: #009900">$(STAGING_DIR)</span>/usr/lib
  703. <span style="color: #000000">20:</span> endef
  704. <span style="color: #000000">21:</span>
  705. <span style="color: #000000">22:</span> define LIBFOO_INSTALL_TARGET_CMDS
  706. <span style="color: #000000">23:</span> <span style="color: #009900">$(INSTALL)</span> -D -m 0755 <span style="color: #009900">$(@D)</span>/libfoo.so* <span style="color: #009900">$(TARGET_DIR)</span>/usr/lib
  707. <span style="color: #000000">24:</span> <span style="color: #009900">$(INSTALL)</span> -d -m 0755 <span style="color: #009900">$(TARGET_DIR)</span>/etc/foo.d
  708. <span style="color: #000000">25:</span> endef
  709. <span style="color: #000000">26:</span>
  710. <span style="color: #000000">27:</span><span style="color: #009900"> $(eval $(call GENTARGETS,package,libfoo))</span>
  711. </pre>
  712. <p>The Makefile begins on line 6 to 8 with metadata information: the
  713. version of the package (<code>LIBFOO_VERSION</code>), the name of the
  714. tarball containing the package (<code>LIBFOO_SOURCE</code>) and the
  715. Internet location at which the tarball can be downloaded
  716. (<code>LIBFOO_SITE</code>). All variables must start with the same prefix,
  717. <code>LIBFOO_</code> in this case. This prefix is always the uppercased
  718. version of the package name (see below to understand where the package
  719. name is defined).</p>
  720. <p>On line 9, we specify that this package wants to install something to
  721. the staging space. This is often needed for libraries, since they must
  722. install header files and other development files in the staging space.
  723. This will ensure that the commands listed in the
  724. <code>LIBFOO_INSTALL_STAGING_CMDS</code> variable will be executed.</p>
  725. <p>On line 10, we specify the list of dependencies this package relies
  726. on. These dependencies are listed in terms of lower-case package names,
  727. which can be packages for the target (without the <code>host-</code>
  728. prefix) or packages for the host (with the <code>host-</code>) prefix).
  729. Buildroot will ensure that all these packages are built and installed
  730. <i>before</i> the current package starts its configuration.</p>
  731. <p>The rest of the Makefile defines what should be done at the different
  732. steps of the package configuration, compilation and installation.
  733. <code>LIBFOO_BUILD_CMDS</code> tells what steps should be performed to
  734. build the package. <code>LIBFOO_INSTALL_STAGING_CMDS</code> tells what
  735. steps should be performed to install the package in the staging space.
  736. <code>LIBFOO_INSTALL_TARGET_CMDS</code> tells what steps should be
  737. performed to install the package in the target space.</p>
  738. <p>All these steps rely on the <code>$(@D)</code> variable, which
  739. contains the directory where the source code of the package has been
  740. extracted.</p>
  741. <p>Finally, on line 27, we call the <code>GENTARGETS</code> which
  742. generates, according to the variables defined previously, all the
  743. Makefile code necessary to make your package working.</p>
  744. <h4 id="generic-reference">Makefile for generic packages : reference</h4>
  745. <p>The <code>GENTARGETS</code> macro takes three arguments:</p>
  746. <ul>
  747. <li>The first argument is the package directory prefix. If your
  748. package is in <code>package/libfoo</code>, then the directory prefix
  749. is <code>package</code>. If your package is in
  750. <code>package/editors/foo</code>, then the directory prefix must be
  751. <code>package/editors</code>.</li>
  752. <li>The second argument is the lower-cased package name. It must match
  753. the prefix of the variables in the <code>.mk</code> file and must
  754. match the configuration option name in the <code>Config.in</code>
  755. file. For example, if the package name is <code>libfoo</code>, then the
  756. variables in the <code>.mk</code> file must start with
  757. <code>LIBFOO_</code> and the configuration option in the
  758. <code>Config.in</code> file must be <code>BR2_PACKAGE_LIBFOO</code>.</li>
  759. <li>The third argument is optional. It can be used to tell if the
  760. package is a target package (cross-compiled for the target) or a host
  761. package (natively compiled for the host). If unspecified, it is
  762. assumed that it is a target package. See below for details.</li>
  763. </ul>
  764. <p>For a given package, in a single <code>.mk</code> file, it is
  765. possible to call GENTARGETS twice, once to create the rules to generate
  766. a target package and once to create the rules to generate a host package:
  767. </p>
  768. <pre>
  769. $(eval $(call GENTARGETS,package,libfoo))
  770. $(eval $(call GENTARGETS,package,libfoo,host))
  771. </pre>
  772. <p>This might be useful if the compilation of the target package
  773. requires some tools to be installed on the host. If the package name is
  774. <code>libfoo</code>, then the name of the package for the target is also
  775. <code>libfoo</code>, while the name of the package for the host is
  776. <code>host-libfoo</code>. These names should be used in the DEPENDENCIES
  777. variables of other packages, if they depend on <code>libfoo</code> or
  778. <code>host-libfoo</code>.</p>
  779. <p>The call to the <code>GENTARGETS</code> macro <b>must</b> be at the
  780. end of the <code>.mk</code> file, after all variable definitions.</p>
  781. <p>For the target package, the <code>GENTARGETS</code> uses the
  782. variables defined by the .mk file and prefixed by the uppercased package
  783. name: <code>LIBFOO_*</code>. For the host package, it uses the
  784. <code>HOST_LIBFOO_*</code>. For <i>some</i> variables, if the
  785. <code>HOST_LIBFOO_</code> prefixed variable doesn't exist, the package
  786. infrastructure uses the corresponding variable prefixed by
  787. <code>LIBFOO_</code>. This is done for variables that are likely to have
  788. the same value for both the target and host packages. See below for
  789. details.</p>
  790. <p>The list of variables that can be set in a <code>.mk</code> file to
  791. give metadata information is (assuming the package name is
  792. <code>libfoo</code>) :</p>
  793. <ul>
  794. <li><code>LIBFOO_VERSION</code>, mandatory, must contain the
  795. version of the package. Note that
  796. if <code>HOST_LIBFOO_VERSION</code> doesn't exist, it is assumed
  797. to be the same as <code>LIBFOO_VERSION</code>. It can also be a
  798. Subversion or Git branch or tag, for packages that are fetched
  799. directly from their revision control system.<br/>
  800. Example: <code>LIBFOO_VERSION = 0.1.2</code></li>
  801. <li><code>LIBFOO_SOURCE</code> may contain the name of the tarball of
  802. the package. If <code>HOST_LIBFOO_SOURCE</code> is not specified, it
  803. defaults to <code>LIBFOO_VERSION</code>. If none are specified, then
  804. the value is assumed to be
  805. <code>packagename-$(LIBFOO_VERSION).tar.gz</code>.<br/>Example:
  806. <code>LIBFOO_SOURCE = foobar-$(LIBFOO_VERSION).tar.bz2</code></li>
  807. <li><code>LIBFOO_PATCH</code> may contain the name of a patch, that
  808. will be downloaded from the same location as the tarball indicated in
  809. <code>LIBFOO_SOURCE</code>. If <code>HOST_LIBFOO_PATCH</code> is not
  810. specified, it defaults to <code>LIBFOO_PATCH</code>. Also note that
  811. another mechanism is available to patch a package: all files of the
  812. form <code>packagename-packageversion-description.patch</code> present
  813. in the package directory inside Buildroot will be applied to the
  814. package after extraction.</li>
  815. <li><code>LIBFOO_SITE</code> may contain the Internet location
  816. of the package. It can either be the HTTP or FTP location of a
  817. tarball, or the URL of a Git or Subversion repository
  818. (see <code>LIBFOO_SITE_METHOD</code>
  819. below). If <code>HOST_LIBFOO_SITE</code> is not specified, it
  820. defaults to <code>LIBFOO_SITE</code>. If none are specified,
  821. then the location is assumed to be
  822. <code>http://$$(BR2_SOURCEFORGE_MIRROR).dl.sourceforge.net/sourceforge/packagename</code>.
  823. <br/>Examples:<br/>
  824. <code>LIBFOO_SITE=http://www.libfoosoftware.org/libfoo</code><br/>
  825. <code>LIBFOO_SITE=http://svn.xiph.org/trunk/Tremor/</code></li>
  826. <li><code>LIBFOO_SITE_METHOD</code> may contain the method to
  827. fetch the package source code. It can either
  828. be <code>WGET</code> (for normal FTP/HTTP downloads of
  829. tarballs), <code>SVN</code> or <code>GIT</code>. When not
  830. specified, it is guessed from the URL given
  831. in <code>LIBFOO_SITE</code>: <code>git://</code>
  832. and <code>svn://</code> URLs will use the <code>GIT</code>
  833. and <code>SVN</code> methods respectively. All other URL-types
  834. will use the <code>WGET</code> method. So for example, in the
  835. case of a package whose source code is available through
  836. Subversion repository on HTTP, one <i>must</i>
  837. specifiy <code>LIBFOO_SITE_METHOD=SVN</code>. For <code>SVN</code>
  838. and <code>GIT</code> methods, what Buildroot does is a
  839. checkout/clone of the repository which is then tarballed and
  840. stored into the download cache. Next builds will not
  841. checkout/clone again, but will use the tarball
  842. directly. When <code>HOST_LIBFOO_SITE_METHOD</code> is not
  843. specified, it defaults to the value
  844. of <code>LIBFOO_SITE_METHOD</code>. See <code>package/multimedia/tremor/</code>
  845. for an example.</li>
  846. <li><code>LIBFOO_DEPENDENCIES</code> lists the dependencies (in terms
  847. of package name) that are required for the current target package to
  848. compile. These dependencies are guaranteed to be compiled and
  849. installed before the configuration of the current package starts. In a
  850. similar way, <code>HOST_LIBFOO_DEPENDENCIES</code> lists the
  851. dependency for the current host package.</li>
  852. <li><code>LIBFOO_INSTALL_STAGING</code> can be set to <code>YES</code>
  853. or <code>NO</code> (default). If set to <code>YES</code>, then the
  854. commands in the <code>LIBFOO_INSTALL_STAGING_CMDS</code> variables are
  855. executed to install the package into the staging directory.</li>
  856. <li><code>LIBFOO_INSTALL_TARGET</code> can be set to <code>YES</code>
  857. (default) or <code>NO</code>. If set to <code>YES</code>, then the
  858. commands in the <code>LIBFOO_INSTALL_TARGET_CMDS</code> variables are
  859. executed to install the package into the target directory.</li> </ul>
  860. <p>The recommended way to define these variables is to use the following
  861. syntax:</p>
  862. <pre>
  863. LIBFOO_VERSION = 2.32
  864. </pre>
  865. <p>Now, the variables that define what should be performed at the
  866. different steps of the build process.</p>
  867. <ul>
  868. <li><code>LIBFOO_CONFIGURE_CMDS</code>, used to list the actions to be
  869. performed to configure the package before its compilation</li>
  870. <li><code>LIBFOO_BUILD_CMDS</code>, used to list the actions to be
  871. performed to compile the package</li>
  872. <li><code>HOST_LIBFOO_INSTALL_CMDS</code>, used to list the actions to
  873. be performed to install the package, when the package is a host
  874. package. The package must install its files to the directory given by
  875. <code>$(HOST_DIR)</code>. All files, including development files such
  876. as headers should be installed, since other packages might be compiled
  877. on top of this package.</li>
  878. <li><code>LIBFOO_INSTALL_TARGET_CMDS</code>, used to list the actions
  879. to be performed to install the package to the target directory, when
  880. the package is a target package. The package must install its files to
  881. the directory given by <code>$(TARGET_DIR)</code>. Only the files
  882. required for <i>documentation</i> and <i>execution</i> of the package
  883. should be installed. Header files should not be installed, they will
  884. be copied to the target, if the
  885. <code>development files in target filesystem</code> option is selected.
  886. </li>
  887. <li><code>LIBFOO_INSTALL_STAGING_CMDS</code>, used to list the actions
  888. to be performed to install the package to the staging directory, when
  889. the package is a target package. The package must install its files to
  890. the directory given by <code>$(STAGING_DIR)</code>. All development
  891. files should be installed, since they might be needed to compile other
  892. packages.</li>
  893. <li><code>LIBFOO_CLEAN_CMDS</code>, used to list the actions to
  894. perform to clean up the build directory of the package.</li>
  895. <li><code>LIBFOO_UNINSTALL_TARGET_CMDS</code>, used to list the actions
  896. to uninstall the package from the target directory
  897. <code>$(TARGET_DIR)</code></li>
  898. <li><code>LIBFOO_UNINSTALL_STAGING_CMDS</code>, used to list the
  899. actions to uninstall the package from the staging directory
  900. <code>$(STAGING_DIR)</code>.</li>
  901. </ul>
  902. <p>The preferred way to define these variables is:</p>
  903. <pre>
  904. define LIBFOO_CONFIGURE_CMDS
  905. action 1
  906. action 2
  907. action 3
  908. endef
  909. </pre>
  910. <p>In the action definitions, you can use the following variables:</p>
  911. <ul>
  912. <li><code>$(@D)</code>, which contains the directory in which the
  913. package source code has been uncompressed.</li>
  914. <li><code>$(TARGET_CC)</code>, <code>$(TARGET_LD)</code>, etc. to get
  915. the target cross-compilation utilities</li>
  916. <li><code>$(TARGET_CROSS)</code> to get the cross-compilation
  917. toolchain prefix</li>
  918. <li>Of course the <code>$(HOST_DIR)</code>, <code>$(STAGING_DIR)</code>
  919. and <code>$(TARGET_DIR)</code> variables to install the packages
  920. properly.</li>
  921. </ul>
  922. <p>The last feature of the generic infrastructure is the ability to add
  923. hooks. These define further actions to perform after existing steps.
  924. Most hooks aren't really useful for generic packages, since the
  925. <code>.mk</code> file already has full control over the actions
  926. performed in each step of the package construction. The hooks are more
  927. useful for packages using the autotools infrastructure described below.
  928. However, since they are provided by the generic infrastructure, they are
  929. documented here. The exception is <code>LIBFOO_POST_PATCH_HOOKS</code>.
  930. Patching the package is not user definable, so
  931. <code>LIBFOO_POST_PATCH_HOOKS</code> will be userful for generic packages.
  932. </p>
  933. <p>The following hook points are available:</p>
  934. <ul>
  935. <li><code>LIBFOO_POST_PATCH_HOOKS</code></li>
  936. <li><code>LIBFOO_PRE_CONFIGURE_HOOKS</code></li>
  937. <li><code>LIBFOO_POST_CONFIGURE_HOOKS</code></li>
  938. <li><code>LIBFOO_POST_BUILD_HOOKS</code></li>
  939. <li><code>LIBFOO_POST_INSTALL_HOOKS</code> (for host packages only)</li>
  940. <li><code>LIBFOO_POST_INSTALL_STAGING_HOOKS</code> (for target packages only)</li>
  941. <li><code>LIBFOO_POST_INSTALL_TARGET_HOOKS</code> (for target packages only)</li>
  942. </ul>
  943. <p>These variables are <i>lists</i> of variable names containing actions
  944. to be performed at this hook point. This allows several hooks to be
  945. registered at a given hook point. Here is an example:</p>
  946. <pre>
  947. define LIBFOO_POST_PATCH_FIXUP
  948. action1
  949. action2
  950. endef
  951. LIBFOO_POST_PATCH_HOOKS += LIBFOO_POST_PATCH_FIXUP
  952. </pre>
  953. <h4 id="autotools-tutorial">Makefile for autotools-based packages : tutorial</h4>
  954. <p>First, let's see how to write a <code>.mk</code> file for an
  955. autotools-based package, with an example :</p>
  956. <pre>
  957. <span style="color: #000000">01:</span><span style="font-style: italic; color: #9A1900"> #############################################################</span>
  958. <span style="color: #000000">02:</span><span style="font-style: italic; color: #9A1900"> #</span>
  959. <span style="color: #000000">03:</span><span style="font-style: italic; color: #9A1900"> # libfoo</span>
  960. <span style="color: #000000">04:</span><span style="font-style: italic; color: #9A1900"> #</span>
  961. <span style="color: #000000">05:</span><span style="font-style: italic; color: #9A1900"> #############################################################</span>
  962. <span style="color: #000000">06:</span><span style="color: #009900"> LIBFOO_VERSION</span> = 1.0
  963. <span style="color: #000000">07:</span><span style="color: #009900"> LIBFOO_SOURCE</span> = libfoo-<span style="color: #009900">$(LIBFOO_VERSION)</span>.tar.gz
  964. <span style="color: #000000">08:</span><span style="color: #009900"> LIBFOO_SITE</span> = http://www.foosoftware.org/download
  965. <span style="color: #000000">09:</span><span style="color: #009900"> LIBFOO_INSTALL_STAGING</span> = YES
  966. <span style="color: #000000">10:</span><span style="color: #009900"> LIBFOO_INSTALL_TARGET</span> = YES
  967. <span style="color: #000000">11:</span><span style="color: #009900"> LIBFOO_CONF_OPT</span> = --enable-shared
  968. <span style="color: #000000">12:</span><span style="color: #009900"> LIBFOO_DEPENDENCIES</span> = libglib2 host-pkg-config
  969. <span style="color: #000000">13:</span>
  970. <span style="color: #000000">14:</span><span style="color: #009900"> $(eval $(call AUTOTARGETS,package,libfoo))</span>
  971. </pre>
  972. <p>On line 6, we declare the version of the package.</p>
  973. <p>On line 7 and 8, we declare the name of the tarball and the location
  974. of the tarball on the Web. Buildroot will automatically download the
  975. tarball from this location.</p>
  976. <p>On line 9, we tell Buildroot to install the package to the staging
  977. directory. The staging directory, located in <code>output/staging/</code>
  978. is the directory where all the packages are installed, including their
  979. development files, etc. By default, packages are not installed to the
  980. staging directory, since usually, only libraries need to be installed in
  981. the staging directory: their development files are needed to compile
  982. other libraries or applications depending on them. Also by default, when
  983. staging installation is enabled, packages are installed in this location
  984. using the <code>make install</code> command.</p>
  985. <p>On line 10, we tell Buildroot to also install the package to the
  986. target directory. This directory contains what will become the root
  987. filesystem running on the target. Usually, we try not to install header
  988. files and to install stripped versions of the binary. By default, target
  989. installation is enabled, so in fact, this line is not strictly
  990. necessary. Also by default, packages are installed in this location
  991. using the <code>make install</code> command.</p>
  992. <p>On line 11, we tell Buildroot to pass a custom configure option, that
  993. will be passed to the <code>./configure</code> script before configuring
  994. and building the package.</p>
  995. <p>On line 12, we declare our dependencies, so that they are built
  996. before the build process of our package starts.</p>
  997. <p>Finally, on line line 14, we invoke the <code>AUTOTARGETS</code>
  998. macro that generates all the Makefile rules that actually allows the
  999. package to be built.</p>
  1000. <h4 id="autotools-reference">Makefile for autotools packages : reference</h4>
  1001. <p>The main macro of the autotools package infrastructure is
  1002. <code>AUTOTARGETS</code>. It has the same number of arguments and the
  1003. same semantic as the <code>GENTARGETS</code> macro, which is the main
  1004. macro of the generic package infrastructure. For autotools packages, the
  1005. ability to have target and host packages is also available (and is
  1006. actually widely used).</p>
  1007. <p>Just like the generic infrastructure, the autotools infrastructure
  1008. works by defining a number of variables before calling the
  1009. <code>AUTOTARGETS</code> macro.</p>
  1010. <p>First, all the package metadata information variables that exist in the
  1011. generic infrastructure also exist in the autotools infrastructure:
  1012. <code>LIBFOO_VERSION</code>, <code>LIBFOO_SOURCE</code>,
  1013. <code>LIBFOO_PATCH</code>, <code>LIBFOO_SITE</code>,
  1014. <code>LIBFOO_SUBDIR</code>, <code>LIBFOO_DEPENDENCIES</code>,
  1015. <code>LIBFOO_INSTALL_STAGING</code>, <code>LIBFOO_INSTALL_TARGET</code>.</p>
  1016. <p>A few additional variables, specific to the autotools infrastructure,
  1017. can also be defined. Many of them are only useful in very specific
  1018. cases, typical packages will therefore only use a few of them.</p>
  1019. <ul>
  1020. <li><code>LIBFOO_SUBDIR</code> may contain the name of a subdirectory
  1021. inside the package that contains the configure script. This is useful,
  1022. if for example, the main configure script is not at the root of the
  1023. tree extracted by the tarball. If <code>HOST_LIBFOO_SUBDIR</code> is
  1024. not specified, it defaults to <code>LIBFOO_SUBDIR</code>.</li>
  1025. <li><code>LIBFOO_CONF_ENV</code>, to specify additional environment
  1026. variables to pass to the configure script. By default, empty.</li>
  1027. <li><code>LIBFOO_CONF_OPT</code>, to specify additional configure
  1028. options to pass to the configure script. By default, empty.</li>
  1029. <li><code>LIBFOO_MAKE</code>, to specify an alternate <code>make</code>
  1030. command. This is typically useful when parallel make is enabled in
  1031. the configuration (using <code>BR2_JLEVEL</code>) but that this
  1032. feature should be disabled for the given package, for one reason or
  1033. another. By default, set to <code>$(MAKE)</code>. If parallel building
  1034. is not supported by the package, then it should be set to
  1035. <code>LIBFOO_MAKE=$(MAKE1)</code>.</li>
  1036. <li><code>LIBFOO_MAKE_ENV</code>, to specify additional environment
  1037. variables to pass to make in the build step. These are passed before
  1038. the <code>make</code> command. By default, empty.</li>
  1039. <li><code>LIBFOO_MAKE_OPT</code>, to specify additional variables to
  1040. pass to make in the build step. These are passed after the
  1041. <code>make</code> command. By default, empty.</li>
  1042. <li><code>LIBFOO_AUTORECONF</code>, tells whether the package should
  1043. be autoreconfigured or not (i.e, if the configure script and
  1044. Makefile.in files should be re-generated by re-running autoconf,
  1045. automake, libtool, etc.). Valid values are <code>YES</code> and
  1046. <code>NO</code>. By default, the value is <code>NO</code></li>
  1047. <li><code>LIBFOO_AUTORECONF_OPT</code> to specify additional options
  1048. passed to the <i>autoreconf</i> program if
  1049. <code>LIBFOO_AUTORECONF=YES</code>. By default, empty.</li>
  1050. <li><code>LIBFOO_LIBTOOL_PATCH</code> tells whether the Buildroot
  1051. patch to fix libtool cross-compilation issues should be applied or
  1052. not. Valid values are <code>YES</code> and <code>NO</code>. By
  1053. default, the value is <code>YES</code></li>
  1054. <li><code>LIBFOO_INSTALL_STAGING_OPT</code> contains the make options
  1055. used to install the package to the staging directory. By default, the
  1056. value is <code>DESTDIR=$$(STAGING_DIR) install</code>, which is
  1057. correct for most autotools packages. It is still possible to override
  1058. it.</li>
  1059. <li><code>LIBFOO_INSTALL_TARGET_OPT</code> contains the make options
  1060. used to install the package to the target directory. By default, the
  1061. value is <code>DESTDIR=$$(TARGET_DIR) install</code>. The default
  1062. value is correct for most autotools packages, but it is still possible
  1063. to override it if needed.</li>
  1064. <li><code>LIBFOO_CLEAN_OPT</code> contains the make options used to
  1065. clean the package. By default, the value is <code>clean</code>.</li>
  1066. <li><code>LIBFOO_UNINSTALL_STAGING_OPT</code>, contains the make
  1067. options used to uninstall the package from the staging directory. By
  1068. default, the value is <code>DESTDIR=$$(STAGING_DIR) uninstall</code>.</li>
  1069. <li><code>LIBFOO_UNINSTALL_TARGET_OPT</code>, contains the make
  1070. options used to uninstall the package from the target directory. By
  1071. default, the value is <code>DESTDIR=$$(TARGET_DIR) uninstall</code>.</li>
  1072. </ul>
  1073. <p>With the autotools infrastructure, all the steps required to build
  1074. and install the packages are already defined, and they generally work
  1075. well for most autotools-based packages. However, when required, it is
  1076. still possible to customize what is done in any particular step:</p>
  1077. <ul>
  1078. <li>By adding a post-operation hook (after extract, patch, configure,
  1079. build or install). See the reference documentation of the generic
  1080. infrastructure for details.</li>
  1081. <li>By overriding one of the steps. For example, even if the autotools
  1082. infrastructure is used, if the package <code>.mk</code> file defines its
  1083. own <code>LIBFOO_CONFIGURE_CMDS</code> variable, it will be used
  1084. instead of the default autotools one. However, using this method
  1085. should be restricted to very specific cases. Do not use it in the
  1086. general case.</li>
  1087. </ul>
  1088. <h4 id ="manual-tutorial">Manual Makefile : tutorial</h4>
  1089. <p><b>NOTE: new manual makefiles should not be created, and existing
  1090. manual makefiles should be converted either to the generic
  1091. infrastructure or the autotools infrastructure. This section is only
  1092. kept to document the existing manual makefiles and to help understand
  1093. how they work.</b></p>
  1094. <pre>
  1095. 01: #############################################################
  1096. 02: #
  1097. 03: # libfoo
  1098. 04: #
  1099. 05: #############################################################
  1100. <span id="ex2line6">06: LIBFOO_VERSION:=1.0</span>
  1101. 07: LIBFOO_SOURCE:=libfoo-$(LIBFOO_VERSION).tar.gz
  1102. 08: LIBFOO_SITE:=http://www.foosoftware.org/downloads
  1103. 09: LIBFOO_DIR:=$(BUILD_DIR)/foo-$(FOO_VERSION)
  1104. 10: LIBFOO_BINARY:=foo
  1105. 11: LIBFOO_TARGET_BINARY:=usr/bin/foo
  1106. 12:
  1107. <span id="ex2line13">13: $(DL_DIR)/$(LIBFOO_SOURCE):</span>
  1108. 14: $(call DOWNLOAD,$(LIBFOO_SITE),$(LIBFOO_SOURCE))
  1109. 15:
  1110. <span id="ex2line16">16: $(LIBFOO_DIR)/.source: $(DL_DIR)/$(LIBFOO_SOURCE)</span>
  1111. 17: $(ZCAT) $(DL_DIR)/$(LIBFOO_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
  1112. 18: touch $@
  1113. 19:
  1114. <span id="ex2line20">20: $(LIBFOO_DIR)/.configured: $(LIBFOO_DIR)/.source</span>
  1115. 21: (cd $(LIBFOO_DIR); rm -rf config.cache; \
  1116. 22: $(TARGET_CONFIGURE_OPTS) \
  1117. 23: $(TARGET_CONFIGURE_ARGS) \
  1118. 24: ./configure \
  1119. 25: --target=$(GNU_TARGET_NAME) \
  1120. 26: --host=$(GNU_TARGET_NAME) \
  1121. 27: --build=$(GNU_HOST_NAME) \
  1122. 28: --prefix=/usr \
  1123. 29: --sysconfdir=/etc \
  1124. 30: )
  1125. 31: touch $@
  1126. 32:
  1127. <span id="ex2line33">33: $(LIBFOO_DIR)/$(LIBFOO_BINARY): $(LIBFOO_DIR)/.configured</span>
  1128. 34: $(MAKE) CC=$(TARGET_CC) -C $(LIBFOO_DIR)
  1129. 35:
  1130. <span id="ex2line36">36: $(TARGET_DIR)/$(LIBFOO_TARGET_BINARY): $(LIBFOO_DIR)/$(LIBFOO_BINARY)</span>
  1131. 37: $(MAKE) DESTDIR=$(TARGET_DIR) -C $(LIBFOO_DIR) install-strip
  1132. 38: rm -Rf $(TARGET_DIR)/usr/man
  1133. 39:
  1134. <span id="ex2line40">40: libfoo: uclibc ncurses $(TARGET_DIR)/$(LIBFOO_TARGET_BINARY)</span>
  1135. 41:
  1136. <span id="ex2line42">42: libfoo-source: $(DL_DIR)/$(LIBFOO_SOURCE)</span>
  1137. 43:
  1138. <span id="ex2line44">44: libfoo-clean:</span>
  1139. 45: $(MAKE) prefix=$(TARGET_DIR)/usr -C $(LIBFOO_DIR) uninstall
  1140. 46: -$(MAKE) -C $(LIBFOO_DIR) clean
  1141. 47:
  1142. <span id="ex2line48">48: libfoo-dirclean:</span>
  1143. 49: rm -rf $(LIBFOO_DIR)
  1144. 50:
  1145. <span id="ex2line51">51: #############################################################</span>
  1146. 52: #
  1147. 53: # Toplevel Makefile options
  1148. 54: #
  1149. 55: #############################################################
  1150. 56: ifeq ($(BR2_PACKAGE_LIBFOO),y)
  1151. 57: TARGETS+=libfoo
  1152. 58: endif
  1153. </pre>
  1154. <p>First of all, this Makefile example works for a package which
  1155. comprises a single binary executable. For other software, such as
  1156. libraries or more complex stuff with multiple binaries, it must be
  1157. adapted. For examples look at the other <code>*.mk</code> files in the
  1158. <code>package</code> directory.</p>
  1159. <p>At lines <a href="#ex2line6">6-11</a>, a couple of useful variables are
  1160. defined:</p>
  1161. <ul>
  1162. <li><code>LIBFOO_VERSION</code>: The version of <i>libfoo</i> that
  1163. should be downloaded.</li>
  1164. <li><code>LIBFOO_SOURCE</code>: The name of the tarball of <i>libfoo</i>
  1165. on the download website or FTP site. As you can see
  1166. <code>LIBFOO_VERSION</code> is used.</li>
  1167. <li><code>LIBFOO_SITE</code>: The HTTP or FTP site from which
  1168. <i>libfoo</i> archive is downloaded. It must include the complete path to
  1169. the directory where <code>LIBFOO_SOURCE</code> can be found.</li>
  1170. <li><code>LIBFOO_DIR</code>: The directory into which the software will
  1171. be configured and compiled. Basically, it's a subdirectory of
  1172. <code>BUILD_DIR</code> which is created upon decompression of the tarball.
  1173. </li>
  1174. <li><code>LIBFOO_BINARY</code>: Software binary name. As said previously,
  1175. this is an example for a package with a single binary.</li>
  1176. <li><code>LIBFOO_TARGET_BINARY</code>: The full path of the binary inside
  1177. the target filesystem.</li> </ul>
  1178. <p>Lines <a href="#ex2line13">13-14</a> define a target that downloads
  1179. the tarball from the remote site to the download directory
  1180. (<code>DL_DIR</code>).</p>
  1181. <p>Lines <a href="#ex2line16">16-18</a> define a target and associated
  1182. rules that uncompress the downloaded tarball. As you can see, this
  1183. target depends on the tarball file so that the previous target (lines
  1184. <a href="#ex2line13">13-14</a>) is called before executing the rules of
  1185. the current target. Uncompressing is followed by <i>touching</i> a
  1186. hidden file to mark the software as having been uncompressed. This trick
  1187. is used everywhere in a Buildroot Makefile to split steps (download,
  1188. uncompress, configure, compile, install) while still having correct
  1189. dependencies.</p>
  1190. <p>Lines <a href="#ex2line20">20-31</a> define a target and associated
  1191. rules that configure the software. It depends on the previous target
  1192. (the hidden <code>.source</code> file) so that we are sure the software
  1193. has been uncompressed. In order to configure the package, it basically
  1194. runs the well-known <code>./configure</code> script. As we may be doing
  1195. cross-compilation, <code>target</code>, <code>host</code> and
  1196. <code>build</code> arguments are given. The prefix is also set to
  1197. <code>/usr</code>, not because the software will be installed in
  1198. <code>/usr</code> on your host system, but because the software will be
  1199. installed in <code> /usr</code> on the target filesystem. Finally it
  1200. creates a <code>.configured</code> file to mark the software as
  1201. configured.</p>
  1202. <p>Lines <a href="#ex2line33">33-34</a> define a target and a rule that
  1203. compile the software. This target will create the binary file in the
  1204. compilation directory and depends on the software being already
  1205. configured (hence the reference to the <code>.configured</code> file).
  1206. It basically runs <code>make</code> inside the source directory.</p>
  1207. <p>Lines <a href="#ex2line36">36-38</a> define a target and associated
  1208. rules that install the software inside the target filesystem. They
  1209. depend on the binary file in the source directory to make sure the
  1210. software has been compiled. They use the <code>install-strip</code>
  1211. target of the software <code>Makefile</code> by passing a
  1212. <code>DESTDIR</code> argument so that the <code>Makefile</code> doesn't
  1213. try to install the software in the host <code>/usr</code> but rather in
  1214. the target <code>/usr</code>. After the installation, the
  1215. <code>/usr/man </code> directory inside the target filesystem is removed
  1216. to save space. </p>
  1217. <p>Line <a href="#ex2line40">40</a> defines the main target of the
  1218. software &mdash; the one that will eventually be used by the top level
  1219. <code>Makefile</code> to download, compile, and then install this
  1220. package. This target should first of all depend on all needed
  1221. dependencies of the software (in our example, <i>uclibc</i> and
  1222. <i>ncurses</i>) and also depend on the final binary. This last dependency
  1223. will call all previous dependencies in the correct order.</p>
  1224. <p>Line <a href="#ex2line42">42</a> defines a simple target that only
  1225. downloads the code source. This is not used during normal operation of
  1226. Buildroot, but is needed if you intend to download all required sources
  1227. at once for later offline build. Note that if you add a new package,
  1228. providing a <code>libfoo-source</code> target is <i>mandatory</i> to
  1229. support users that wish to do offline-builds. Furthermore, it eases
  1230. checking if all package-sources are downloadable.</p>
  1231. <p>Lines <a href="#ex2line44">44-46</a> define a simple target to clean
  1232. the software build by calling the Makefile with the appropriate options.
  1233. The <code>-clean</code> target should run <code>make clean</code> on
  1234. $(BUILD_DIR)/package-version and MUST uninstall all files of the package
  1235. from $(STAGING_DIR) and from $(TARGET_DIR).</p>
  1236. <p>Lines <a href="#ex2line48">48-49</a> define a simple target to
  1237. completely remove the directory in which the software was uncompressed,
  1238. configured and compiled. The <code>-dirclean</code> target MUST
  1239. completely rm $(BUILD_DIR)/ package-version.</p>
  1240. <p>Lines <a href="#ex2line51">51-58</a> add the target <code>libfoo</code>
  1241. to the list of targets to be compiled by Buildroot, by first checking if
  1242. the configuration option for this package has been enabled using the
  1243. configuration tool. If so, it then &quot;subscribes&quot; this package
  1244. to be compiled by adding the package to the TARGETS global variable.
  1245. The name added to the TARGETS global variable is the name of this
  1246. package's target, as defined on line <a href="#ex2line40">40</a>, which
  1247. is used by Buildroot to download, compile, and then install this package.
  1248. </p>
  1249. <h3 id="gettext-integration">Gettext integration and interaction with packages</h3>
  1250. <p>Many packages that support internationalization use the gettext
  1251. library. Dependencies for this library are fairly complicated and therefore,
  1252. deserves some explanation.</p>
  1253. <p>The <i>uClibc</i> C library doesn't implement gettext functionality,
  1254. therefore with this C library, a separate gettext must be compiled. On
  1255. the other hand, the <i>glibc</i> C library does integrate its own
  1256. gettext, and in this case, the separate gettext library should not be
  1257. compiled, because it creates various kinds of build failures.</p>
  1258. <p>Additionally, some packages (such as libglib2) do require gettext
  1259. unconditionally, while other packages (those who support
  1260. <code>--disable-nls</code> in general) only require gettext when locale
  1261. support is enabled.</p>
  1262. <p>Therefore, Buildroot defines two configuration options:</p>
  1263. <ul>
  1264. <li><code>BR2_NEEDS_GETTEXT</code>, which is true as soon as the
  1265. toolchain doesn't provide its own gettext implementation</li>
  1266. <li><code>BR2_NEEDS_GETTEXT_IF_LOCALE</code>, which is true if the
  1267. toolchain doesn't provide its own gettext implementation and if locale
  1268. support is enabled</li> </ul>
  1269. <p>Therefore, packages that unconditionally need gettext should:</p>
  1270. <ol>
  1271. <li>Use <code>select BR2_PACKAGE_GETTEXT if BR2_NEEDS_GETTEXT</code>
  1272. and possibly <code>select BR2_PACKAGE_LIBINTL if BR2_NEEDS_GETTEXT</code>,
  1273. if libintl is also needed</li>
  1274. <li>Use <code>$(if $(BR2_NEEDS_GETTEXT),gettext)</code> in the package
  1275. <code>DEPENDENCIES</code> variable</li>
  1276. </ol>
  1277. <p>Packages that need gettext only when locale support is enabled should:
  1278. </p>
  1279. <ol>
  1280. <li>Use
  1281. <code>select BR2_PACKAGE_GETTEXT if BR2_NEEDS_GETTEXT_IF_LOCALE</code>
  1282. and possibly
  1283. <code>select BR2_PACKAGE_LIBINTL if BR2_NEEDS_GETTEXT_IF_LOCALE</code>,
  1284. if libintl is also needed</li>
  1285. <li>Use <code>$(if $(BR2_NEEDS_GETTEXT_IF_LOCALE),gettext)</code> in
  1286. the package <code>DEPENDENCIES</code> variable</li>
  1287. </ol>
  1288. <h3>Conclusion</h3>
  1289. <p>As you can see, adding a software package to Buildroot is simply a
  1290. matter of writing a Makefile using an existing example and modifying it
  1291. according to the compilation process required by the package.</p>
  1292. <p>If you package software that might be useful for other people, don't
  1293. forget to send a patch to Buildroot developers!</p>
  1294. <h2 id="faq">Frequently asked questions</h2>
  1295. <ul>
  1296. <li><a href="#faq-boot-hangs">The boot hangs
  1297. after <code>Starting network...</code></a></li>
  1298. <li><a href="#module-init-tools-doesnt-build">module-init-tools
  1299. fails to build with <code>cannot find -lc</code></a></li>
  1300. </ul>
  1301. <h3 id="faq-boot-hangs">The boot hangs after <code>Starting
  1302. network...</code></h3>
  1303. <p>If the boot process seems to hang after the following messages
  1304. (messages not necessarly exactly similar, depending on the list of
  1305. packages selected):</p>
  1306. <pre>Freeing init memory: 3972K
  1307. Initializing random number generator... done.
  1308. Starting network...
  1309. Starting dropbear sshd: generating rsa key... generating dsa key... OK</pre>
  1310. <p>then it means that your system is running, but didn't start a
  1311. shell on the serial console. In order to have the system start a
  1312. shell on your serial console, you have to go in the Buildroot
  1313. configuration, <code>Target options</code>, enable <code>Generic
  1314. serial port config</code>, and select the serial port and speed
  1315. you would like to use for the shell. This will automatically tune
  1316. the <code>/etc/inittab</code> file of the generated system so that
  1317. a shell starts on the correct serial port.</p>
  1318. <h3 id="module-init-tools-doesnt-build">module-init-tools
  1319. fails to build with <code>cannot find -lc</code></h3>
  1320. <p>If the build of <i>module-init-tools</i> for the host fails
  1321. with:</p>
  1322. <pre>/usr/bin/ld: cannot find -lc </pre>
  1323. <p>then probably you are running a Fedora (or similar)
  1324. distribution, and you should install the <code>glibc-static</code>
  1325. package. This is because the <i>module-init-tools</i> build
  1326. process wants to link statically against the C library.</p>
  1327. <h2 id="links">Resources</h2>
  1328. <p>To learn more about Buildroot you can visit these websites:</p>
  1329. <ul>
  1330. <li><a href="http://www.uclibc.org/">http://www.uclibc.org/</a></li>
  1331. <li><a href="http://www.busybox.net/">http://www.busybox.net/</a></li>
  1332. </ul>
  1333. </div>
  1334. </body>
  1335. </html>