buildroot.html 88 KB

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