buildroot.html 78 KB

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