buildroot.html 88 KB

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