buildroot.html 88 KB

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