buildroot.html 78 KB

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