2
1

buildroot.html 74 KB

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