5 <title>Buildroot - Usage and documentation</title>
6 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
7 <link rel="stylesheet" href="stylesheet.css">
16 <p><a href="http://buildroot.net/">Buildroot</a> usage and documentation
17 by Thomas Petazzoni. Contributions from Karsten Kruse, Ned Ludd, Martin
18 Herren and others.</p>
21 <li><a href="#about">About Buildroot</a></li>
22 <li><a href="#download">Obtaining Buildroot</a></li>
23 <li><a href="#using">Using Buildroot</a></li>
24 <li><a href="#custom_targetfs">Customizing the generated target filesystem</a></li>
25 <li><a href="#custom_busybox">Customizing the Busybox configuration</a></li>
26 <li><a href="#custom_uclibc">Customizing the uClibc configuration</a></li>
27 <li><a href="#custom_linux26">Customizing the Linux kernel configuration</a></li>
28 <li><a href="#rebuilding_packages">Understanding how to rebuild packages</a></li>
29 <li><a href="#buildroot_innards">How Buildroot works</a></li>
30 <li><a href="#using_toolchain">Using the uClibc toolchain outside Buildroot</a></li>
31 <li><a href="#external_toolchain">Use an external toolchain</a></li>
32 <li><a href="#ccache-support">Using <code>ccache</code> in Buildroot</li>
33 <li><a href="#downloaded_packages">Location of downloaded packages</a></li>
34 <li><a href="#add_packages">Adding new packages to Buildroot</a></li>
35 <li><a href="#board_support">Creating your own board support</a></li>
36 <li><a href="#faq">Frequently asked questions</a></li>
37 <li><a href="#links">Resources</a></li>
40 <h2 id="about">About Buildroot</h2>
42 <p>Buildroot is a set of Makefiles and patches that allows you to easily
43 generate a cross-compilation toolchain, a root filesystem and a Linux
44 kernel image for your target. Buildroot can be used for one, two or all
45 of these options, independently.</p>
47 <p>Buildroot is useful mainly for people working with embedded systems.
48 Embedded systems often use processors that are not the regular x86
49 processors everyone is used to having in his PC. They can be PowerPC
50 processors, MIPS processors, ARM processors, etc.</p>
52 <p>A compilation toolchain is the set of tools that allows you to
53 compile code for your system. It consists of a compiler (in our case,
54 <code>gcc</code>), binary utils like assembler and linker (in our case,
55 <code>binutils</code>) and a C standard library (for example
56 <a href="http://www.gnu.org/software/libc/libc.html">GNU Libc</a>,
57 <a href="http://www.uclibc.org/">uClibc</a> or
58 <a href="http://www.fefe.de/dietlibc/">dietlibc</a>). The system installed
59 on your development station certainly already has a compilation
60 toolchain that you can use to compile an application that runs on your
61 system. If you're using a PC, your compilation toolchain runs on an x86
62 processor and generates code for an x86 processor. Under most Linux
63 systems, the compilation toolchain uses the GNU libc (glibc) as the C
64 standard library. This compilation toolchain is called the "host
65 compilation toolchain". The machine on which it is running, and on
66 which you're working, is called the "host system". The
67 compilation toolchain is provided by your distribution, and Buildroot
68 has nothing to do with it (other than using it to build a
69 cross-compilation toolchain and other tools that are run on the
70 development host).</p>
72 <p>As said above, the compilation toolchain that comes with your system
73 runs on and generates code for the processor in your host system. As
74 your embedded system has a different processor, you need a
75 cross-compilation toolchain — a compilation toolchain that runs on
76 your host system but generates code for your target system (and target
77 processor). For example, if your host system uses x86 and your target
78 system uses ARM, the regular compilation toolchain on your host runs on
79 x86 and generates code for x86, while the cross-compilation toolchain
80 runs on x86 and generates code for ARM.</p>
82 <p>Even if your embedded system uses an x86 processor, you might be
83 interested in Buildroot for two reasons:</p>
86 <li>The compilation toolchain on your host certainly uses the GNU Libc
87 which is a complete but huge C standard library. Instead of using GNU
88 Libc on your target system, you can use uClibc which is a tiny C
89 standard library. If you want to use this C library, then you need a
90 compilation toolchain to generate binaries linked with it. Buildroot
91 can do that for you.</li>
93 <li>Buildroot automates the building of a root filesystem with all needed
94 tools like busybox. That makes it much easier than doing it by hand.</li>
97 <p>You might wonder why such a tool is needed when you can compile
98 <code>gcc</code>, <code>binutils</code>, <code>uClibc</code> and all
99 the other tools by hand. Of course doing so is possible but, dealing with
100 all of the configure options and problems of every <code>gcc</code> or
101 <code>binutils</code> version is very time-consuming and uninteresting.
102 Buildroot automates this process through the use of Makefiles and has a
103 collection of patches for each <code>gcc</code> and <code>binutils</code>
104 version to make them work on most architectures.</p>
106 <p>Moreover, Buildroot provides an infrastructure for reproducing
107 the build process of your kernel, cross-toolchain, and embedded root
108 filesystem. Being able to reproduce the build process will be useful when a
109 component needs to be patched or updated or when another person is supposed
110 to take over the project.</p>
112 <h2 id="download">Obtaining Buildroot</h2>
114 <p>Buildroot releases are made approximately every 3
115 months. Direct Git access and daily snapshots are also
116 available, if you want more bleeding edge.</p>
118 <p>Releases are available at
119 <a href="http://buildroot.net/downloads/">http://buildroot.net/downloads/</a>.</p>
121 <p>The latest snapshot is always available at
122 <a href="http://buildroot.net/downloads/snapshots/buildroot-snapshot.tar.bz2">http://buildroot.net/downloads/snapshots/buildroot-snapshot.tar.bz2</a>,
123 and previous snapshots are also available at
124 <a href="http://buildroot.net/downloads/snapshots/">http://buildroot.net/downloads/snapshots/</a>.</p>
126 <p>To download Buildroot using Git, you can simply follow
127 the rules described on the "Accessing Git" page
128 (<a href= "http://buildroot.net/git.html">http://buildroot.net/git.html</a>)
129 of the Buildroot website
130 (<a href="http://buildroot.net">http://buildroot.net</a>).
131 For the impatient, here's a quick recipe:</p>
134 $ git clone git://git.buildroot.net/buildroot
137 <h2 id="using">Using Buildroot</h2>
139 <p>Buildroot has a nice configuration tool similar to the one you can find
141 (<a href="http://www.kernel.org/">http://www.kernel.org/</a>) or in Busybox
142 (<a href="http://www.busybox.org/">http://www.busybox.org/</a>). Note that
143 you can (and should) build everything as a normal user. There is no need to
144 be root to configure and use Buildroot. The first step is to run the
145 configuration assistant:</p>
151 <p>to run the curses-based configurator, or</p>
163 <p>to run the Qt3 or GTK-based configurators.</p>
165 <p>All of these "make" commands will need to build a configuration
166 utility, so you may need to install "development" packages for relevant
167 libraries used by the configuration utilities. On Debian-like systems,
168 the <code>libncurses5-dev</code> package is required to use the <i>
169 menuconfig</i> interface, <code>libqt3-mt-dev</code> is required to use
170 the <i>xconfig</i> interface, and <code>libglib2.0-dev, libgtk2.0-dev
171 and libglade2-dev</code> are needed to use the <i>gconfig</i> interface.</p>
173 <p>For each menu entry in the configuration tool, you can find associated
174 help that describes the purpose of the entry.</p>
176 <p>Once everything is configured, the configuration tool generates a
177 <code>.config</code> file that contains the description of your
178 configuration. It will be used by the Makefiles to do what's needed.</p>
187 <p>You <b>should never</b> use <code>make -jN</code> with
188 Buildroot: it does not support <i>top-level parallel
189 make</i>. Instead, use the <code>BR2_JLEVEL</code> option to tell
190 Buildroot to run each package compilation with <pre>make
193 <p>This command will generally perform the following steps:</p>
195 <li>Download source files (as required)</li>
196 <li>Configure, build and install the cross-compiling toolchain
197 if an internal toolchain is used, or import a toolchain if an
198 external toolchain is used</li>
199 <li>Build/install selected target packages</li>
200 <li>Build a kernel image, if selected</li>
201 <li>Build a bootloader image, if selected</li>
202 <li>Create a root filesystem in selected formats</li>
205 <p>Buildroot output is stored in a single directory, <code>output/</code>.
206 This directory contains several subdirectories:</p>
209 <li><code>images/</code> where all the images (kernel image,
210 bootloader and root filesystem images) are stored.</li>
212 <li><code>build/</code> where all the components except for the
213 cross-compilation toolchain are built (this includes tools needed to
214 run Buildroot on the host and packages compiled for the target). The
215 <code>build/</code> directory contains one subdirectory for each of
216 these components.</li>
218 <li><code>staging/</code> which contains a hierarchy similar to a root
219 filesystem hierarchy. This directory contains the installation of the
220 cross-compilation toolchain and all the userspace packages selected
221 for the target. However, this directory is <i>not</i> intended to be
222 the root filesystem for the target: it contains a lot of development
223 files, unstripped binaries and libraries that make it far too big for
224 an embedded system. These development files are used to compile
225 libraries and applications for the target that depend on other
228 <li><code>target/</code> which contains <i>almost</i> the complete
229 root filesystem for the target: everything needed is present except
230 the device files in <code>/dev/</code> (Buildroot can't create them
231 because Buildroot doesn't run as root and doesn't want to run as
232 root). Therefore, this directory <b>should not be used on your target</b>.
233 Instead, you should use one of the images built in the
234 <code>images/</code> directory. If you need an extracted image of the
235 root filesystem for booting over NFS, then use the tarball image
236 generated in <code>images/</code> and extract it as root.<br/>Compared
237 to <code>staging/</code>, <code>target/</code> contains only the
238 files and libraries needed to run the selected target applications:
239 the development files (headers, etc.) are not present, unless the
240 <code>development files in target filesystem</code> option is selected.
243 <li><code>host/</code> contains the installation of tools compiled for
244 the host that are needed for the proper execution of Buildroot, except
245 for the cross-compilation toolchain which is installed under
246 <code>staging/</code>.</li>
248 <li><code>toolchain/</code> contains the build directories for the
249 various components of the cross-compilation toolchain.</li>
252 <h3 id="offline_builds">Offline builds</h3>
254 <p>If you intend to do an offline build and just want to download
255 all sources that you previously selected in the configurator
256 (<i>menuconfig</i>, <i>xconfig</i> or <i>gconfig</i>), then issue:</p>
262 <p>You can now disconnect or copy the content of your <code>dl</code>
263 directory to the build-host.</p>
265 <h3 id="building_out_of_tree">Building out-of-tree</h3>
267 <p>Buildroot supports building out of tree with a syntax similar to the
268 Linux kernel. To use it, add O=<directory> to the make command
278 $ cd /tmp/build; make O=$PWD -C path/to/buildroot
281 <p>All the output files will be located under <code>/tmp/build</code>.</p>
283 <p>When using out-of-tree builds, the Buildroot <code>.config</code> and
284 temporary files are also stored in the output directory. This means that
285 you can safely run multiple builds in parallel using the same source
286 tree as long as they use unique output directories.</p>
288 <p>For ease of use, Buildroot generates a Makefile wrapper in the output
289 directory - So after the first run, you no longer need to pass
290 <code>O=..</code> and <code>-C ..</code>, simply run (in the output
294 $ make <target>
297 <h3 id="environment_variables">Environment variables</h3>
299 <p>Buildroot also honors some environment variables, when they are passed
300 to <code>make</code> or set in the environment:</p>
302 <li><code>HOSTCXX</code>, the host C++ compiler to use</li>
303 <li><code>HOSTCC</code>, the host C compiler to use</li>
304 <li><code>UCLIBC_CONFIG_FILE=<path/to/.config></code>, path to
305 the uClibc configuration file, used to compile uClibc, if an
306 internal toolchain is being built</li>
307 <li><code>BUSYBOX_CONFIG_FILE=<path/to/.config></code>, path to
308 the Busybox configuration file</li>
309 <li><code>BUILDROOT_DL_DIR</code> to override the directory in which
310 Buildroot stores/retrieves downloaded files</li>
313 <p>An example that uses config files located in the toplevel directory and
317 $ make UCLIBC_CONFIG_FILE=uClibc.config BUSYBOX_CONFIG_FILE=$HOME/bb.config
320 <p>If you want to use a compiler other than the default <code>gcc</code>
321 or <code>g++</code> for building helper-binaries on your host, then do</p>
324 $ make HOSTCXX=g++-4.3-HEAD HOSTCC=gcc-4.3-HEAD
327 <h2 id="custom_targetfs">Customizing the generated target filesystem</h2>
329 <p>There are a few ways to customize the resulting target filesystem:</p>
332 <li>Customize the target filesystem directly and rebuild the image.
333 The target filesystem is available under <code>output/target/</code>.
334 You can simply make your changes here and run make afterwards —
335 this will rebuild the target filesystem image. This method allows you
336 to do anything to the target filesystem, but if you decide to
337 completely rebuild your toolchain and tools, these changes will be
340 <li>Create your own <i>target skeleton</i>. You can start with
341 the default skeleton available under <code>fs/skeleton</code>
342 and then customize it to suit your
343 needs. The <code>BR2_ROOTFS_SKELETON_CUSTOM</code>
344 and <code>BR2_ROOTFS_SKELETON_CUSTOM_PATH</code> will allow you
345 to specify the location of your custom skeleton. At build time,
346 the contents of the skeleton are copied to output/target before
347 any package installation.</li>
349 <li>In the Buildroot configuration, you can specify the path to a
350 post-build script, that gets called <i>after</i> Buildroot builds all
351 the selected software, but <i>before</i> the rootfs packages are
352 assembled. The destination root filesystem folder is given as the
353 first argument to this script, and this script can then be used to
354 copy programs, static data or any other needed file to your target
355 filesystem.<br/>You should, however, use this feature with care.
356 Whenever you find that a certain package generates wrong or unneeded
357 files, you should fix that package rather than work around it with a
358 post-build cleanup script.</li>
360 <li>A special package, <i>customize</i>, stored in
361 <code>package/customize</code> can be used. You can put all the
362 files that you want to see in the final target root filesystem
363 in <code>package/customize/source</code>, and then enable this
364 special package in the configuration system.</li>
367 <h2 id="custom_busybox">Customizing the Busybox configuration</h2>
369 <p><a href="http://www.busybox.net/">Busybox</a> is very configurable,
370 and you may want to customize it. You can follow these simple steps to
371 do so. This method isn't optimal, but it's simple, and it works:</p>
374 <li>Do an initial compilation of Buildroot, with busybox, without
375 trying to customize it.</li>
377 <li>Invoke <code>make busybox-menuconfig</code>.
378 The nice configuration tool appears, and you can
379 customize everything.</li>
381 <li>Run the compilation of Buildroot again.</li>
384 <p>Otherwise, you can simply change the
385 <code>package/busybox/busybox-<version>.config</code> file, if you
386 know the options you want to change, without using the configuration tool.
389 <p>If you want to use an existing config file for busybox, then see
390 section <a href="#environment_variables">environment variables</a>.</p>
392 <h2 id="custom_uclibc">Customizing the uClibc configuration</h2>
394 <p>Just like <a href="#custom_busybox">BusyBox</a>,
395 <a href="http://www.uclibc.org/">uClibc</a> offers a lot of
396 configuration options. They allow you to select various
397 functionalities depending on your needs and limitations.</p>
399 <p>The easiest way to modify the configuration of uClibc is to
400 follow these steps:</p>
403 <li>Do an initial compilation of Buildroot without trying to
404 customize uClibc.</li>
406 <li>Invoke <code>make uclibc-menuconfig</code>.
407 The nice configuration assistant, similar to
408 the one used in the Linux kernel or Buildroot, appears. Make
409 your configuration changes as appropriate.</li>
411 <li>Copy the <code>.config</code> file to
412 <code>toolchain/uClibc/uClibc.config</code> or
413 <code>toolchain/uClibc/uClibc.config-locale</code>. The former
414 is used if you haven't selected locale support in Buildroot
415 configuration, and the latter is used if you have selected
418 <li>Run the compilation of Buildroot again.</li>
421 <p>Otherwise, you can simply change
422 <code>toolchain/uClibc/uClibc.config</code> or
423 <code>toolchain/uClibc/uClibc.config-locale</code>, without running
424 the configuration assistant.</p>
426 <p>If you want to use an existing config file for uclibc, then see
427 section <a href="#environment_variables">environment variables</a>.</p>
429 <h2 id="custom_linux26">Customizing the Linux kernel configuration</h2>
431 <p>The Linux kernel configuration can be customized just like
432 <a href="#custom_busybox">BusyBox</a> and
433 <a href="#custom_uclibc">uClibc</a> using <code>make linux-menuconfig
434 </code>. Make sure you have enabled the kernel build in <code>make
435 menuconfig</code> first. Once done, run <code>make</code> to (re)build
438 <p>If you want to use an existing config file for Linux, then see
439 section <a href="#environment_variables">environment variables</a>.</p>
441 <h2 id="rebuilding_packages">Understanding how to rebuild packages</h2>
443 <p>One of the most common questions asked by Buildroot
444 users is how to rebuild a given package or how to
445 remove a package without rebuilding everything from scratch.</p>
447 <p>Removing a package is currently unsupported by Buildroot
448 without rebuilding from scratch. This is because Buildroot doesn't
449 keep track of which package installs what files in the
450 <code>output/staging</code> and <code>output/target</code>
451 directories. However, implementing clean package removal is on the
452 TODO-list of Buildroot developers.</p>
454 <p>The easiest way to rebuild a single package from scratch is to
455 remove its build directory in <code>output/build</code>. Buildroot
456 will then re-extract, re-configure, re-compile and re-install this
457 package from scratch.</p>
459 <p>However, if you don't want to rebuild the package completely
460 from scratch, a better understanding of the Buildroot internals is
461 needed. Internally, to keep track of which steps have been done
462 and which steps remain to be done, Buildroot maintains stamp
463 files (empty files that just tell whether this or that action
464 has been done). The problem is that these stamp files are not
465 uniformly named and handled by the different packages, so some
466 understanding of the particular package is needed.</p>
468 <p>For packages relying on Buildroot packages infrastructures (see
469 <a href="#add_packages">this section</a> for details), the
470 following stamp files are relevant:</p>
473 <li><code>output/build/packagename-version/.stamp_configured</code>. If
474 removed, Buildroot will trigger the recompilation of the package
475 from the configuration step (execution of
476 <code>./configure</code>).</li>
478 <li><code>output/build/packagename-version/.stamp_built</code>. If
479 removed, Buildroot will trigger the recompilation of the package
480 from the compilation step (execution of <code>make</code>).</li>
483 <p>For other packages, an analysis of the specific <i>package.mk</i>
484 file is needed. For example, the zlib Makefile used to look like this
485 (before it was converted to the generic package infrastructure):</p>
488 $(ZLIB_DIR)/.configured: $(ZLIB_DIR)/.patched
489 (cd $(ZLIB_DIR); rm -rf config.cache; \
494 $(ZLIB_DIR)/libz.a: $(ZLIB_DIR)/.configured
495 $(MAKE) -C $(ZLIB_DIR) all libz.a
499 <p>If you want to trigger the reconfiguration, you need to
500 remove <code>output/build/zlib-version/.configured</code>. If
501 you want to trigger only the recompilation, you need to remove
502 <code>output/build/zlib-version/libz.a</code>.</p>
504 <p>Note that most packages, if not all, will progressively be
505 ported over to the generic or autotools infrastructure, making it
506 much easier to rebuild individual packages.</p>
508 <h2 id="buildroot_innards">How Buildroot works</h2>
510 <p>As mentioned above, Buildroot is basically a set of Makefiles that
511 download, configure, and compile software with the correct options. It
512 also includes patches for various software packages — mainly the
513 ones involved in the cross-compilation tool chain (<code>gcc</code>,
514 <code>binutils</code> and <code>uClibc</code>).</p>
516 <p>There is basically one Makefile per software package, and they are
517 named with the <code>.mk</code> extension. Makefiles are split into
518 three main sections:</p>
521 <li><b>toolchain</b> (in the <code>toolchain/</code> directory) contains
522 the Makefiles and associated files for all software related to the
523 cross-compilation toolchain: <code>binutils</code>, <code>gcc</code>,
524 <code>gdb</code>, <code>kernel-headers</code> and <code>uClibc</code>.</li>
526 <li><b>package</b> (in the <code>package/</code> directory) contains the
527 Makefiles and associated files for all user-space tools that Buildroot
528 can compile and add to the target root filesystem. There is one
529 sub-directory per tool.</li>
531 <li><b>target</b> (in the <code>target</code> directory) contains the
532 Makefiles and associated files for software related to the generation of
533 the target root filesystem image. Four types of filesystems are supported:
534 ext2, jffs2, cramfs and squashfs. For each of them there is a
535 sub-directory with the required files. There is also a
536 <code>default/</code> directory that contains the target filesystem
540 <p>Each directory contains at least 2 files:</p>
543 <li><code>something.mk</code> is the Makefile that downloads, configures,
544 compiles and installs the package <code>something</code>.</li>
546 <li><code>Config.in</code> is a part of the configuration tool
547 description file. It describes the options related to the
551 <p>The main Makefile performs the following steps (once the
552 configuration is done):</p>
555 <li>Create all the output directories: <code>staging</code>,
556 <code>target</code>, <code>build</code>, <code>stamps</code>,
557 etc. in the output directory (<code>output/</code> by default,
558 another value can be specified using <code>O=</code>)</li>
560 <li>Generate all the targets listed in the
561 <code>BASE_TARGETS</code> variable. When an internal toolchain
562 is used, this means generating the cross-compilation
563 toolchain. When an external toolchain is used, this means checking
564 the features of the external toolchain and importing it into the
565 Buildroot environment.</li>
567 <li>Generate all the targets listed in the <code>TARGETS</code>
568 variable. This variable is filled by all the individual
569 components' Makefiles. Generating these targets will
570 trigger the compilation of the userspace packages (libraries,
571 programs), the kernel, the bootloader and the generation of the
572 root filesystem images, depending on the configuration.</li>
575 <h2 id="board_support"> Creating your own board support</h2>
577 <p>Creating your own board support in Buildroot allows users of a
578 particular hardware platform to easily build a system that is
581 <p>To do so, you need to create a normal Buildroot configuration
582 that builds a basic system for the hardware: toolchain, kernel,
583 bootloader, filesystem and a simple Busybox-only userspace. No
584 specific package should be selected: the configuration should be
585 as minimal as possible, and should only build a working basic
586 Busybox system for the target platform. You can of course use more
587 complicated configurations for your internal projects, but the
588 Buildroot project will only integrate basic board
589 configurations. This is because package selections are highly
590 application-specific.</p>
592 <p>Once you have a known working configuration, run <code>make
593 savedefconfig</code>. This will generate a
594 minimal <code>defconfig</code> file at the root of the Buildroot
595 source tree. Move this file into the <code>configs/</code>
596 directory, and rename it <code>MYBOARD_defconfig</code>.</p>
598 <p>It is recommended to use as much as possible upstream versions
599 of the Linux kernel and bootloaders, and to use as much as
600 possible default kernel and bootloader configurations. If they are
601 incorrect for your platform, we encourage you to send fixes to the
602 corresponding upstream projects.</p>
604 <p>However, in the mean time, you may want to store kernel or
605 bootloader configuration or patches specific to your target
606 platform. To do so, create a
607 directory <code>board/MANUFACTURER</code> and a
608 subdirectory <code>board/MANUFACTURER/BOARDNAME</code> (after
609 replacing, of course, MANUFACTURER and BOARDNAME with the
610 appropriate values, in lower case letters). You can then store
611 your patches and configurations in these directories, and
612 reference them from the main Buildroot configuration.</p>
614 <h2 id="using_toolchain">Using the generated toolchain outside Buildroot</h2>
616 <p>You may want to compile, for your target, your own programs or other
617 software that are not packaged in Buildroot. In order to do this you can
618 use the toolchain that was generated by Buildroot.</p>
620 <p>The toolchain generated by Buildroot is located by default in
621 <code>output/staging/</code>. The simplest way to use it is to add
622 <code>output/staging/usr/bin/</code> to your PATH environment variable and
623 then to use <code>ARCH-linux-gcc</code>, <code>ARCH-linux-objdump</code>,
624 <code>ARCH-linux-ld</code>, etc.</p>
626 <p>It is possible to relocate the toolchain — but
627 then <code>--sysroot</code> must be passed every time the compiler
628 is called to tell where the libraries and header files are.</p>
630 <p>It is also possible to generate the Buildroot toolchain in a
631 directory other than <code>output/staging</code> by using the <code>
632 Build options -> Toolchain and header file location</code> options.
633 This could be useful if the toolchain must be shared with other users.</p>
635 <h2 id="ccache-support">Using <code>ccache</code> in Buildroot</h2>
637 <p><a href="http://ccache.samba.org">ccache</a> is a compiler
638 cache. It stores the object files resulting from each compilation
639 process, and is able to skip future compilation of the same source
640 file (with same compiler and same arguments) by using the
641 pre-existing object files. When doing almost identical builds from
642 scratch a number of times, it can nicely speed up the build
645 <p><code>ccache</code> support is integrated in Buildroot. You
646 just have to enable <code>Enable compiler cache</code>
647 in <code>Build options</code>. This will automatically build
648 <code>ccache</code> and use it for every host and target
651 <p>The cache is located
652 in <code>$HOME/.buildroot-ccache</code>. It is stored outside of
653 Buildroot output directory so that it can be shared by separate
654 Buildroot builds. If you want to get rid of the cache, simply
655 remove this directory.</p>
657 <p>You can get statistics on the cache (its size, number of hits,
658 misses, etc.) by running <code>make ccache-stats</code>.</p>
660 <h2 id="downloaded_packages">Location of downloaded packages</h2>
662 <p>It might be useful to know that the various tarballs that are
663 downloaded by the Makefiles are all stored in the <code>DL_DIR</code>
664 which by default is the <code>dl</code> directory. It's useful, for
665 example, if you want to keep a complete version of Buildroot which is
666 known to be working with the associated tarballs. This will allow you to
667 regenerate the toolchain and the target filesystem with exactly the same
670 <p>If you maintain several Buildroot trees, it might be better to have a
671 shared download location. This can be accessed by creating a symbolic
672 link from the <code>dl</code> directory to the shared download location:</p>
675 $ ln -s <shared download location> dl
678 <p>Another way of accessing a shared download location is to
679 create the <code>BUILDROOT_DL_DIR</code> environment variable.
680 If this is set, then the value of DL_DIR in the project is
681 overridden. The following line should be added to
682 <code>"~/.bashrc"</code>.</p>
685 $ export BUILDROOT_DL_DIR <shared download location>
688 <h2 id="external_toolchain">Using an external toolchain</h2>
690 <p>Using an already existing toolchain is useful for different
694 <li>you already have a toolchain that is known to work for your
696 <li>you want to speed up the Buildroot build process by skipping
697 the long toolchain build part</li>
698 <li>the toolchain generation feature of Buildroot is not
699 sufficiently flexible for you (for example if you need to
700 generate a system with <i>glibc</i> instead of
704 <p>Buildroot supports using existing toolchains through a
705 mechanism called <i>external toolchain</i>. The external toolchain
706 mechanism is enabled in the <code>Toolchain</code> menu, by
707 selecting <code>External toolchain</code> in <code>Toolchain
710 <p>Then, you have three solutions to use an external
715 <li>Use a predefined external toolchain profile, and let
716 Buildroot download, extract and install the toolchain. Buildroot
717 already knows about a few CodeSourcery toolchains for ARM,
718 PowerPC, MIPS and SuperH. Just select the toolchain profile
719 in <code>Toolchain</code> through the available ones. This is
720 definitely the easiest solution.</li>
722 <li>Use a predefined external toolchain profile, but instead of
723 having Buildroot download and extract the toolchain, you can
724 tell Buildroot where your toolchain is already installed on your
725 system. Just select the toolchain profile
726 in <code>Toolchain</code> through the available ones,
727 unselect <code>Download toolchain automatically</code>, and fill
728 the <code>Toolchain path</code> text entry with the path to your
729 cross-compiling toolchain.</li>
731 <li>Use a completely custom external toolchain. This is
732 particularly useful for toolchains generated using
733 Crosstool-NG. To do this, select the <code>Custom
734 toolchain</code> solution in the <code>Toolchain</code>
735 list. You need to fill the <code>Toolchain
736 path</code>, <code>Toolchain prefix</code> and <code>External
737 toolchain C library</code> options. Then, you have to tell
738 Buildroot what your external toolchain supports. If your
739 external toolchain uses the <i>glibc</i> library, you only have
740 to tell whether your toolchain supports C++ or not. If your
741 external toolchain uses the <i>uclibc</i> library, then you have
742 to tell Buildroot if it supports largefile, IPv6, RPC,
743 wide-char, locale, program invocation, threads and C++. At the
744 beginning of the execution, Buildroot will tell you if the
745 selected options do not match the toolchain configuration.</li>
749 <p>Our external toolchain support has been tested with toolchains
750 from CodeSourcery, toolchains generated
751 by <a href="http://ymorin.is-a-geek.org/dokuwiki/projects/crosstool">Crosstool-NG</a>,
752 and toolchains generated by Buildroot itself. In general, all
753 toolchains that support the <i>sysroot</i> feature should
754 work. If not, do not hesitate to contact the developers.</p>
756 <p>We do not support toolchains from
757 the <a href="http://www.denx.de/wiki/DULG/ELDK">ELDK of Denx</a>,
762 <li>The ELDK does not contain a pure toolchain (i.e just the
763 compiler, binutils, the C and C++ libraries), but a toolchain
764 that comes with a very large set of pre-compiled libraries and
765 programs. Therefore, Buildroot cannot import the <i>sysroot</i>
766 of the toolchain, as it would contain hundreds of megabytes of
767 pre-compiled libraries that are normally built by
770 <li>The ELDK toolchains have a completely non-standard custom
771 mechanism to handle multiple library variants. Instead of using
772 the standard GCC <i>multilib</i> mechanism, the ARM ELDK uses
773 different symbolic links to the compiler to differentiate
774 between library variants (for ARM soft-float and ARM VFP), and
775 the PowerPC ELDK compiler uses a <code>CROSS_COMPILE</code>
776 environment variable. This non-standard behaviour makes it
777 difficult to support ELDK in Buildroot.</li>
781 <h2 id="add_packages">Adding new packages to Buildroot</h2>
783 <p>This section covers how new packages (userspace libraries or
784 applications) can be integrated into Buildroot. It also shows how existing
785 packages are integrated, which is needed for fixing issues or tuning their
789 <li><a href="#package-directory">Package directory</a></li>
790 <li><a href="#config-in-file"><code>Config.in</code> file</a></li>
791 <li><a href="#mk-file">The <code>.mk</code> file</a>
793 <li><a href="#generic-tutorial">Makefile for generic packages : tutorial</a></li>
794 <li><a href="#generic-reference">Makefile for generic packages : reference</a></li>
795 <li><a href="#autotools-tutorial">Makefile for autotools-based packages : tutorial</a></li>
796 <li><a href="#autotools-reference">Makefile for autotools-based packages : reference</a></li>
797 <li><a href="#cmake-tutorial">Makefile for CMake-based packages : tutorial</a></li>
798 <li><a href="#cmake-reference">Makefile for CMake-based packages : reference</a></li>
799 <li><a href="#manual-tutorial">Manual Makefile : tutorial</a></li>
802 <li><a href="#gettext-integration">Gettext integration and interaction with packages</a></li>
805 <h3 id="package-directory">Package directory</h3>
807 <p>First of all, create a directory under the <code>package</code>
808 directory for your software, for example <code>libfoo</code>.</p>
810 <p>Some packages have been grouped by topic in a sub-directory:
811 <code>multimedia</code>, <code>java</code>, <code>x11r7</code>, and
812 <code>games</code>. If your package fits in one of these
813 categories, then create your package directory in these.</p>
815 <h3 id="config-in-file"><code>Config.in</code> file</h3>
817 <p>Then, create a file named <code>Config.in</code>. This file
818 will contain the option descriptions related to our
819 <code>libfoo</code> software that will be used and displayed in the
820 configuration tool. It should basically contain :</p>
823 config BR2_PACKAGE_LIBFOO
826 This is a comment that explains what libfoo is.
828 http://foosoftware.org/libfoo/
831 <p>Of course, you can add other options to configure particular
832 things in your software. You can look at examples in other
833 packages. The syntax of the Config.in file is the same as the one
834 for the kernel Kconfig file. The documentation for this syntax is
836 <a href="http://lxr.free-electrons.com/source/Documentation/kbuild/kconfig-language.txt">http://lxr.free-electrons.com/source/Documentation/kbuild/kconfig-language.txt</a>
839 <p>Finally you have to add your new <code>libfoo/Config.in</code> to
840 <code>package/Config.in</code> (or in a category subdirectory if
841 you decided to put your package in one of the existing
842 categories). The files included there are <em>sorted
843 alphabetically</em> per category and are <em>NOT</em> supposed to
844 contain anything but the <em>bare</em> name of the package.</p>
847 source "package/libfoo/Config.in"
850 <h3 id="mk-file">The <code>.mk</code> file</h3>
852 <p>Finally, here's the hardest part. Create a file named
853 <code>libfoo.mk</code>. It describes how the package should be
854 downloaded, configured, built, installed, etc.</p>
856 <p>Depending on the package type, the <code>.mk</code> file must be
857 written in a different way, using different infrastructures:</p>
860 <li><b>Makefiles for generic packages</b> (not using autotools): These
861 are based on an infrastructure similar to the one used for
862 autotools-based packages, but requires a little more work from the
863 developer. They specify what should be done for the configuration,
864 compilation, installation and cleanup of the package. This
865 infrastructure must be used for all packages that do not use the
866 autotools as their build system. In the future, other specialized
867 infrastructures might be written for other build systems.<br/>We cover
868 them through a <a href="#generic-tutorial">tutorial</a> and a
869 <a href="#generic-reference">reference</a>.</li>
871 <li><b>Makefiles for autotools-based software</b> (autoconf, automake,
872 etc.): We provide a dedicated infrastructure for such packages, since
873 autotools is a very common build system. This infrastructure <i>must
874 </i> be used for new packages that rely on the autotools as their
875 build system.<br/>We cover them through a
876 <a href="#autotools-tutorial">tutorial</a> and a
877 <a href="#autotools-reference">reference</a>.</li>
879 <li><b>Manual Makefiles:</b> These are currently obsolete, and no new
880 manual Makefiles should be added. However, since there are still many
881 of them in the tree, we keep them documented in a
882 <a href="#manual-tutorial">tutorial</a>.</li>
885 <h4 id="generic-tutorial">Makefile for generic packages : tutorial</h4>
888 <span style="color: #000000">01:</span><span style="font-style: italic; color: #9A1900"> #############################################################</span>
889 <span style="color: #000000">02:</span><span style="font-style: italic; color: #9A1900"> #</span>
890 <span style="color: #000000">03:</span><span style="font-style: italic; color: #9A1900"> # libfoo</span>
891 <span style="color: #000000">04:</span><span style="font-style: italic; color: #9A1900"> #</span>
892 <span style="color: #000000">05:</span><span style="font-style: italic; color: #9A1900"> #############################################################</span>
893 <span style="color: #000000">06:</span><span style="color: #009900"> LIBFOO_VERSION</span> = 1.0
894 <span style="color: #000000">07:</span><span style="color: #009900"> LIBFOO_SOURCE</span> = libfoo-<span style="color: #009900">$(LIBFOO_VERSION)</span>.tar.gz
895 <span style="color: #000000">08:</span><span style="color: #009900"> LIBFOO_SITE</span> = http://www.foosoftware.org/download
896 <span style="color: #000000">09:</span><span style="color: #009900"> LIBFOO_INSTALL_STAGING</span> = YES
897 <span style="color: #000000">10:</span><span style="color: #009900"> LIBFOO_DEPENDENCIES</span> = host-libaaa libbbb
898 <span style="color: #000000">11:</span>
899 <span style="color: #000000">12:</span> define LIBFOO_BUILD_CMDS
900 <span style="color: #000000">13:</span> <span style="color: #009900">$(MAKE)</span> CC=<span style="color: #009900">$(TARGET_CC)</span> LD=<span style="color: #009900">$(TARGET_LD)</span> -C <span style="color: #009900">$(@D)</span> all
901 <span style="color: #000000">14:</span> endef
902 <span style="color: #000000">15:</span>
903 <span style="color: #000000">16:</span> define LIBFOO_INSTALL_STAGING_CMDS
904 <span style="color: #000000">17:</span> <span style="color: #009900">$(INSTALL)</span> -D -m 0755 <span style="color: #009900">$(@D)</span>/libfoo.a <span style="color: #009900">$(STAGING_DIR)</span>/usr/lib/libfoo.a
905 <span style="color: #000000">18:</span> <span style="color: #009900">$(INSTALL)</span> -D -m 0644 <span style="color: #009900">$(@D)</span>/foo.h <span style="color: #009900">$(STAGING_DIR)</span>/usr/include/foo.h
906 <span style="color: #000000">19:</span> <span style="color: #009900">$(INSTALL)</span> -D -m 0755 <span style="color: #009900">$(@D)</span>/libfoo.so* <span style="color: #009900">$(STAGING_DIR)</span>/usr/lib
907 <span style="color: #000000">20:</span> endef
908 <span style="color: #000000">21:</span>
909 <span style="color: #000000">22:</span> define LIBFOO_INSTALL_TARGET_CMDS
910 <span style="color: #000000">23:</span> <span style="color: #009900">$(INSTALL)</span> -D -m 0755 <span style="color: #009900">$(@D)</span>/libfoo.so* <span style="color: #009900">$(TARGET_DIR)</span>/usr/lib
911 <span style="color: #000000">24:</span> <span style="color: #009900">$(INSTALL)</span> -d -m 0755 <span style="color: #009900">$(TARGET_DIR)</span>/etc/foo.d
912 <span style="color: #000000">25:</span> endef
913 <span style="color: #000000">26:</span>
914 <span style="color: #000000">27:</span><span style="color: #009900"> $(eval $(call GENTARGETS,package,libfoo))</span>
917 <p>The Makefile begins on line 6 to 8 with metadata information: the
918 version of the package (<code>LIBFOO_VERSION</code>), the name of the
919 tarball containing the package (<code>LIBFOO_SOURCE</code>) and the
920 Internet location at which the tarball can be downloaded
921 (<code>LIBFOO_SITE</code>). All variables must start with the same prefix,
922 <code>LIBFOO_</code> in this case. This prefix is always the uppercased
923 version of the package name (see below to understand where the package
924 name is defined).</p>
926 <p>On line 9, we specify that this package wants to install something to
927 the staging space. This is often needed for libraries, since they must
928 install header files and other development files in the staging space.
929 This will ensure that the commands listed in the
930 <code>LIBFOO_INSTALL_STAGING_CMDS</code> variable will be executed.</p>
932 <p>On line 10, we specify the list of dependencies this package relies
933 on. These dependencies are listed in terms of lower-case package names,
934 which can be packages for the target (without the <code>host-</code>
935 prefix) or packages for the host (with the <code>host-</code>) prefix).
936 Buildroot will ensure that all these packages are built and installed
937 <i>before</i> the current package starts its configuration.</p>
939 <p>The rest of the Makefile defines what should be done at the different
940 steps of the package configuration, compilation and installation.
941 <code>LIBFOO_BUILD_CMDS</code> tells what steps should be performed to
942 build the package. <code>LIBFOO_INSTALL_STAGING_CMDS</code> tells what
943 steps should be performed to install the package in the staging space.
944 <code>LIBFOO_INSTALL_TARGET_CMDS</code> tells what steps should be
945 performed to install the package in the target space.</p>
947 <p>All these steps rely on the <code>$(@D)</code> variable, which
948 contains the directory where the source code of the package has been
951 <p>Finally, on line 27, we call the <code>GENTARGETS</code> which
952 generates, according to the variables defined previously, all the
953 Makefile code necessary to make your package working.</p>
955 <h4 id="generic-reference">Makefile for generic packages : reference</h4>
957 <p>The <code>GENTARGETS</code> macro takes three arguments:</p>
960 <li>The first argument is the package directory prefix. If your
961 package is in <code>package/libfoo</code>, then the directory prefix
962 is <code>package</code>. If your package is in
963 <code>package/editors/foo</code>, then the directory prefix must be
964 <code>package/editors</code>.</li>
966 <li>The second argument is the lower-cased package name. It must match
967 the prefix of the variables in the <code>.mk</code> file and must
968 match the configuration option name in the <code>Config.in</code>
969 file. For example, if the package name is <code>libfoo</code>, then the
970 variables in the <code>.mk</code> file must start with
971 <code>LIBFOO_</code> and the configuration option in the
972 <code>Config.in</code> file must be <code>BR2_PACKAGE_LIBFOO</code>.</li>
974 <li>The third argument is optional. It can be used to tell if the
975 package is a target package (cross-compiled for the target) or a host
976 package (natively compiled for the host). If unspecified, it is
977 assumed that it is a target package. See below for details.</li>
980 <p>For a given package, in a single <code>.mk</code> file, it is
981 possible to call GENTARGETS twice, once to create the rules to generate
982 a target package and once to create the rules to generate a host package:
986 $(eval $(call GENTARGETS,package,libfoo))
987 $(eval $(call GENTARGETS,package,libfoo,host))
990 <p>This might be useful if the compilation of the target package
991 requires some tools to be installed on the host. If the package name is
992 <code>libfoo</code>, then the name of the package for the target is also
993 <code>libfoo</code>, while the name of the package for the host is
994 <code>host-libfoo</code>. These names should be used in the DEPENDENCIES
995 variables of other packages, if they depend on <code>libfoo</code> or
996 <code>host-libfoo</code>.</p>
998 <p>The call to the <code>GENTARGETS</code> macro <b>must</b> be at the
999 end of the <code>.mk</code> file, after all variable definitions.</p>
1001 <p>For the target package, the <code>GENTARGETS</code> uses the
1002 variables defined by the .mk file and prefixed by the uppercased package
1003 name: <code>LIBFOO_*</code>. For the host package, it uses the
1004 <code>HOST_LIBFOO_*</code>. For <i>some</i> variables, if the
1005 <code>HOST_LIBFOO_</code> prefixed variable doesn't exist, the package
1006 infrastructure uses the corresponding variable prefixed by
1007 <code>LIBFOO_</code>. This is done for variables that are likely to have
1008 the same value for both the target and host packages. See below for
1011 <p>The list of variables that can be set in a <code>.mk</code> file to
1012 give metadata information is (assuming the package name is
1013 <code>libfoo</code>) :</p>
1016 <li><code>LIBFOO_VERSION</code>, mandatory, must contain the
1017 version of the package. Note that
1018 if <code>HOST_LIBFOO_VERSION</code> doesn't exist, it is assumed
1019 to be the same as <code>LIBFOO_VERSION</code>. It can also be a
1020 Subversion or Git branch or tag, for packages that are fetched
1021 directly from their revision control system.<br/>
1022 Example: <code>LIBFOO_VERSION = 0.1.2</code></li>
1024 <li><code>LIBFOO_SOURCE</code> may contain the name of the tarball of
1025 the package. If <code>HOST_LIBFOO_SOURCE</code> is not specified, it
1026 defaults to <code>LIBFOO_VERSION</code>. If none are specified, then
1027 the value is assumed to be
1028 <code>packagename-$(LIBFOO_VERSION).tar.gz</code>.<br/>Example:
1029 <code>LIBFOO_SOURCE = foobar-$(LIBFOO_VERSION).tar.bz2</code></li>
1031 <li><code>LIBFOO_PATCH</code> may contain the name of a patch, that
1032 will be downloaded from the same location as the tarball indicated in
1033 <code>LIBFOO_SOURCE</code>. If <code>HOST_LIBFOO_PATCH</code> is not
1034 specified, it defaults to <code>LIBFOO_PATCH</code>. Also note that
1035 another mechanism is available to patch a package: all files of the
1036 form <code>packagename-packageversion-description.patch</code> present
1037 in the package directory inside Buildroot will be applied to the
1038 package after extraction.</li>
1040 <li><code>LIBFOO_SITE</code> may contain the Internet location
1041 of the package. It can either be the HTTP or FTP location of a
1042 tarball, or the URL of a Git or Subversion repository
1043 (see <code>LIBFOO_SITE_METHOD</code>
1044 below). If <code>HOST_LIBFOO_SITE</code> is not specified, it
1045 defaults to <code>LIBFOO_SITE</code>. If none are specified,
1046 then the location is assumed to be
1047 <code>http://$$(BR2_SOURCEFORGE_MIRROR).dl.sourceforge.net/sourceforge/packagename</code>.
1049 <code>LIBFOO_SITE=http://www.libfoosoftware.org/libfoo</code><br/>
1050 <code>LIBFOO_SITE=http://svn.xiph.org/trunk/Tremor/</code></li>
1052 <li><code>LIBFOO_SITE_METHOD</code> may contain the method to
1053 fetch the package source code. It can either
1054 be <code>WGET</code> (for normal FTP/HTTP downloads of
1055 tarballs), <code>SVN</code> or <code>GIT</code>. When not
1056 specified, it is guessed from the URL given
1057 in <code>LIBFOO_SITE</code>: <code>git://</code>
1058 and <code>svn://</code> URLs will use the <code>GIT</code>
1059 and <code>SVN</code> methods respectively. All other URL-types
1060 will use the <code>WGET</code> method. So for example, in the
1061 case of a package whose source code is available through
1062 Subversion repository on HTTP, one <i>must</i>
1063 specifiy <code>LIBFOO_SITE_METHOD=SVN</code>. For <code>SVN</code>
1064 and <code>GIT</code> methods, what Buildroot does is a
1065 checkout/clone of the repository which is then tarballed and
1066 stored into the download cache. Next builds will not
1067 checkout/clone again, but will use the tarball
1068 directly. When <code>HOST_LIBFOO_SITE_METHOD</code> is not
1069 specified, it defaults to the value
1070 of <code>LIBFOO_SITE_METHOD</code>. See <code>package/multimedia/tremor/</code>
1071 for an example.</li>
1073 <li><code>LIBFOO_DEPENDENCIES</code> lists the dependencies (in terms
1074 of package name) that are required for the current target package to
1075 compile. These dependencies are guaranteed to be compiled and
1076 installed before the configuration of the current package starts. In a
1077 similar way, <code>HOST_LIBFOO_DEPENDENCIES</code> lists the
1078 dependency for the current host package.</li>
1080 <li><code>LIBFOO_INSTALL_STAGING</code> can be set to <code>YES</code>
1081 or <code>NO</code> (default). If set to <code>YES</code>, then the
1082 commands in the <code>LIBFOO_INSTALL_STAGING_CMDS</code> variables are
1083 executed to install the package into the staging directory.</li>
1085 <li><code>LIBFOO_INSTALL_TARGET</code> can be set to <code>YES</code>
1086 (default) or <code>NO</code>. If set to <code>YES</code>, then the
1087 commands in the <code>LIBFOO_INSTALL_TARGET_CMDS</code> variables are
1088 executed to install the package into the target directory.</li> </ul>
1090 <p>The recommended way to define these variables is to use the following
1094 LIBFOO_VERSION = 2.32
1097 <p>Now, the variables that define what should be performed at the
1098 different steps of the build process.</p>
1101 <li><code>LIBFOO_CONFIGURE_CMDS</code>, used to list the actions to be
1102 performed to configure the package before its compilation</li>
1104 <li><code>LIBFOO_BUILD_CMDS</code>, used to list the actions to be
1105 performed to compile the package</li>
1107 <li><code>HOST_LIBFOO_INSTALL_CMDS</code>, used to list the actions to
1108 be performed to install the package, when the package is a host
1109 package. The package must install its files to the directory given by
1110 <code>$(HOST_DIR)</code>. All files, including development files such
1111 as headers should be installed, since other packages might be compiled
1112 on top of this package.</li>
1114 <li><code>LIBFOO_INSTALL_TARGET_CMDS</code>, used to list the actions
1115 to be performed to install the package to the target directory, when
1116 the package is a target package. The package must install its files to
1117 the directory given by <code>$(TARGET_DIR)</code>. Only the files
1118 required for <i>documentation</i> and <i>execution</i> of the package
1119 should be installed. Header files should not be installed, they will
1120 be copied to the target, if the
1121 <code>development files in target filesystem</code> option is selected.
1124 <li><code>LIBFOO_INSTALL_STAGING_CMDS</code>, used to list the actions
1125 to be performed to install the package to the staging directory, when
1126 the package is a target package. The package must install its files to
1127 the directory given by <code>$(STAGING_DIR)</code>. All development
1128 files should be installed, since they might be needed to compile other
1131 <li><code>LIBFOO_CLEAN_CMDS</code>, used to list the actions to
1132 perform to clean up the build directory of the package.</li>
1134 <li><code>LIBFOO_UNINSTALL_TARGET_CMDS</code>, used to list the actions
1135 to uninstall the package from the target directory
1136 <code>$(TARGET_DIR)</code></li>
1138 <li><code>LIBFOO_UNINSTALL_STAGING_CMDS</code>, used to list the
1139 actions to uninstall the package from the staging directory
1140 <code>$(STAGING_DIR)</code>.</li>
1143 <p>The preferred way to define these variables is:</p>
1146 define LIBFOO_CONFIGURE_CMDS
1153 <p>In the action definitions, you can use the following variables:</p>
1156 <li><code>$(@D)</code>, which contains the directory in which the
1157 package source code has been uncompressed.</li>
1159 <li><code>$(TARGET_CC)</code>, <code>$(TARGET_LD)</code>, etc. to get
1160 the target cross-compilation utilities</li>
1162 <li><code>$(TARGET_CROSS)</code> to get the cross-compilation
1163 toolchain prefix</li>
1165 <li>Of course the <code>$(HOST_DIR)</code>, <code>$(STAGING_DIR)</code>
1166 and <code>$(TARGET_DIR)</code> variables to install the packages
1170 <p>The last feature of the generic infrastructure is the ability to add
1171 hooks. These define further actions to perform after existing steps.
1172 Most hooks aren't really useful for generic packages, since the
1173 <code>.mk</code> file already has full control over the actions
1174 performed in each step of the package construction. The hooks are more
1175 useful for packages using the autotools infrastructure described below.
1176 However, since they are provided by the generic infrastructure, they are
1177 documented here. The exception is <code>LIBFOO_POST_PATCH_HOOKS</code>.
1178 Patching the package is not user definable, so
1179 <code>LIBFOO_POST_PATCH_HOOKS</code> will be userful for generic packages.
1182 <p>The following hook points are available:</p>
1185 <li><code>LIBFOO_POST_PATCH_HOOKS</code></li>
1186 <li><code>LIBFOO_PRE_CONFIGURE_HOOKS</code></li>
1187 <li><code>LIBFOO_POST_CONFIGURE_HOOKS</code></li>
1188 <li><code>LIBFOO_POST_BUILD_HOOKS</code></li>
1189 <li><code>LIBFOO_POST_INSTALL_HOOKS</code> (for host packages only)</li>
1190 <li><code>LIBFOO_POST_INSTALL_STAGING_HOOKS</code> (for target packages only)</li>
1191 <li><code>LIBFOO_POST_INSTALL_TARGET_HOOKS</code> (for target packages only)</li>
1194 <p>These variables are <i>lists</i> of variable names containing actions
1195 to be performed at this hook point. This allows several hooks to be
1196 registered at a given hook point. Here is an example:</p>
1199 define LIBFOO_POST_PATCH_FIXUP
1204 LIBFOO_POST_PATCH_HOOKS += LIBFOO_POST_PATCH_FIXUP
1207 <h4 id="autotools-tutorial">Makefile for autotools-based packages : tutorial</h4>
1209 <p>First, let's see how to write a <code>.mk</code> file for an
1210 autotools-based package, with an example :</p>
1213 <span style="color: #000000">01:</span><span style="font-style: italic; color: #9A1900"> #############################################################</span>
1214 <span style="color: #000000">02:</span><span style="font-style: italic; color: #9A1900"> #</span>
1215 <span style="color: #000000">03:</span><span style="font-style: italic; color: #9A1900"> # libfoo</span>
1216 <span style="color: #000000">04:</span><span style="font-style: italic; color: #9A1900"> #</span>
1217 <span style="color: #000000">05:</span><span style="font-style: italic; color: #9A1900"> #############################################################</span>
1218 <span style="color: #000000">06:</span><span style="color: #009900"> LIBFOO_VERSION</span> = 1.0
1219 <span style="color: #000000">07:</span><span style="color: #009900"> LIBFOO_SOURCE</span> = libfoo-<span style="color: #009900">$(LIBFOO_VERSION)</span>.tar.gz
1220 <span style="color: #000000">08:</span><span style="color: #009900"> LIBFOO_SITE</span> = http://www.foosoftware.org/download
1221 <span style="color: #000000">09:</span><span style="color: #009900"> LIBFOO_INSTALL_STAGING</span> = YES
1222 <span style="color: #000000">10:</span><span style="color: #009900"> LIBFOO_INSTALL_TARGET</span> = YES
1223 <span style="color: #000000">11:</span><span style="color: #009900"> LIBFOO_CONF_OPT</span> = --enable-shared
1224 <span style="color: #000000">12:</span><span style="color: #009900"> LIBFOO_DEPENDENCIES</span> = libglib2 host-pkg-config
1225 <span style="color: #000000">13:</span>
1226 <span style="color: #000000">14:</span><span style="color: #009900"> $(eval $(call AUTOTARGETS,package,libfoo))</span>
1229 <p>On line 6, we declare the version of the package.</p>
1231 <p>On line 7 and 8, we declare the name of the tarball and the location
1232 of the tarball on the Web. Buildroot will automatically download the
1233 tarball from this location.</p>
1235 <p>On line 9, we tell Buildroot to install the package to the staging
1236 directory. The staging directory, located in <code>output/staging/</code>
1237 is the directory where all the packages are installed, including their
1238 development files, etc. By default, packages are not installed to the
1239 staging directory, since usually, only libraries need to be installed in
1240 the staging directory: their development files are needed to compile
1241 other libraries or applications depending on them. Also by default, when
1242 staging installation is enabled, packages are installed in this location
1243 using the <code>make install</code> command.</p>
1245 <p>On line 10, we tell Buildroot to also install the package to the
1246 target directory. This directory contains what will become the root
1247 filesystem running on the target. Usually, we try not to install header
1248 files and to install stripped versions of the binary. By default, target
1249 installation is enabled, so in fact, this line is not strictly
1250 necessary. Also by default, packages are installed in this location
1251 using the <code>make install</code> command.</p>
1253 <p>On line 11, we tell Buildroot to pass a custom configure option, that
1254 will be passed to the <code>./configure</code> script before configuring
1255 and building the package.</p>
1257 <p>On line 12, we declare our dependencies, so that they are built
1258 before the build process of our package starts.</p>
1260 <p>Finally, on line line 14, we invoke the <code>AUTOTARGETS</code>
1261 macro that generates all the Makefile rules that actually allows the
1262 package to be built.</p>
1264 <h4 id="autotools-reference">Makefile for autotools packages : reference</h4>
1266 <p>The main macro of the autotools package infrastructure is
1267 <code>AUTOTARGETS</code>. It has the same number of arguments and the
1268 same semantic as the <code>GENTARGETS</code> macro, which is the main
1269 macro of the generic package infrastructure. For autotools packages, the
1270 ability to have target and host packages is also available (and is
1271 actually widely used).</p>
1273 <p>Just like the generic infrastructure, the autotools infrastructure
1274 works by defining a number of variables before calling the
1275 <code>AUTOTARGETS</code> macro.</p>
1277 <p>First, all the package metadata information variables that exist in the
1278 generic infrastructure also exist in the autotools infrastructure:
1279 <code>LIBFOO_VERSION</code>, <code>LIBFOO_SOURCE</code>,
1280 <code>LIBFOO_PATCH</code>, <code>LIBFOO_SITE</code>,
1281 <code>LIBFOO_SUBDIR</code>, <code>LIBFOO_DEPENDENCIES</code>,
1282 <code>LIBFOO_INSTALL_STAGING</code>, <code>LIBFOO_INSTALL_TARGET</code>.</p>
1284 <p>A few additional variables, specific to the autotools infrastructure,
1285 can also be defined. Many of them are only useful in very specific
1286 cases, typical packages will therefore only use a few of them.</p>
1289 <li><code>LIBFOO_SUBDIR</code> may contain the name of a subdirectory
1290 inside the package that contains the configure script. This is useful,
1291 if for example, the main configure script is not at the root of the
1292 tree extracted by the tarball. If <code>HOST_LIBFOO_SUBDIR</code> is
1293 not specified, it defaults to <code>LIBFOO_SUBDIR</code>.</li>
1295 <li><code>LIBFOO_CONF_ENV</code>, to specify additional environment
1296 variables to pass to the configure script. By default, empty.</li>
1298 <li><code>LIBFOO_CONF_OPT</code>, to specify additional configure
1299 options to pass to the configure script. By default, empty.</li>
1301 <li><code>LIBFOO_MAKE</code>, to specify an alternate <code>make</code>
1302 command. This is typically useful when parallel make is enabled in
1303 the configuration (using <code>BR2_JLEVEL</code>) but that this
1304 feature should be disabled for the given package, for one reason or
1305 another. By default, set to <code>$(MAKE)</code>. If parallel building
1306 is not supported by the package, then it should be set to
1307 <code>LIBFOO_MAKE=$(MAKE1)</code>.</li>
1309 <li><code>LIBFOO_MAKE_ENV</code>, to specify additional environment
1310 variables to pass to make in the build step. These are passed before
1311 the <code>make</code> command. By default, empty.</li>
1313 <li><code>LIBFOO_MAKE_OPT</code>, to specify additional variables to
1314 pass to make in the build step. These are passed after the
1315 <code>make</code> command. By default, empty.</li>
1317 <li><code>LIBFOO_AUTORECONF</code>, tells whether the package should
1318 be autoreconfigured or not (i.e, if the configure script and
1319 Makefile.in files should be re-generated by re-running autoconf,
1320 automake, libtool, etc.). Valid values are <code>YES</code> and
1321 <code>NO</code>. By default, the value is <code>NO</code></li>
1323 <li><code>LIBFOO_AUTORECONF_OPT</code> to specify additional options
1324 passed to the <i>autoreconf</i> program if
1325 <code>LIBFOO_AUTORECONF=YES</code>. By default, empty.</li>
1327 <li><code>LIBFOO_LIBTOOL_PATCH</code> tells whether the Buildroot
1328 patch to fix libtool cross-compilation issues should be applied or
1329 not. Valid values are <code>YES</code> and <code>NO</code>. By
1330 default, the value is <code>YES</code></li>
1332 <li><code>LIBFOO_INSTALL_STAGING_OPT</code> contains the make options
1333 used to install the package to the staging directory. By default, the
1334 value is <code>DESTDIR=$$(STAGING_DIR) install</code>, which is
1335 correct for most autotools packages. It is still possible to override
1338 <li><code>LIBFOO_INSTALL_TARGET_OPT</code> contains the make options
1339 used to install the package to the target directory. By default, the
1340 value is <code>DESTDIR=$$(TARGET_DIR) install</code>. The default
1341 value is correct for most autotools packages, but it is still possible
1342 to override it if needed.</li>
1344 <li><code>LIBFOO_CLEAN_OPT</code> contains the make options used to
1345 clean the package. By default, the value is <code>clean</code>.</li>
1347 <li><code>LIBFOO_UNINSTALL_STAGING_OPT</code>, contains the make
1348 options used to uninstall the package from the staging directory. By
1349 default, the value is <code>DESTDIR=$$(STAGING_DIR) uninstall</code>.</li>
1351 <li><code>LIBFOO_UNINSTALL_TARGET_OPT</code>, contains the make
1352 options used to uninstall the package from the target directory. By
1353 default, the value is <code>DESTDIR=$$(TARGET_DIR) uninstall</code>.</li>
1356 <p>With the autotools infrastructure, all the steps required to build
1357 and install the packages are already defined, and they generally work
1358 well for most autotools-based packages. However, when required, it is
1359 still possible to customize what is done in any particular step:</p>
1362 <li>By adding a post-operation hook (after extract, patch, configure,
1363 build or install). See the reference documentation of the generic
1364 infrastructure for details.</li>
1366 <li>By overriding one of the steps. For example, even if the autotools
1367 infrastructure is used, if the package <code>.mk</code> file defines its
1368 own <code>LIBFOO_CONFIGURE_CMDS</code> variable, it will be used
1369 instead of the default autotools one. However, using this method
1370 should be restricted to very specific cases. Do not use it in the
1374 <h4 id="cmake-tutorial">Makefile for CMake-based packages : tutorial</h4>
1376 <p>First, let's see how to write a <code>.mk</code> file for a CMake-based
1377 package, with an example :</p>
1380 <span style="color: #000000">01:</span><span style="font-style: italic; color: #9A1900"> #############################################################</span>
1381 <span style="color: #000000">02:</span><span style="font-style: italic; color: #9A1900"> #</span>
1382 <span style="color: #000000">03:</span><span style="font-style: italic; color: #9A1900"> # libfoo</span>
1383 <span style="color: #000000">04:</span><span style="font-style: italic; color: #9A1900"> #</span>
1384 <span style="color: #000000">05:</span><span style="font-style: italic; color: #9A1900"> #############################################################</span>
1385 <span style="color: #000000">06:</span><span style="color: #009900"> LIBFOO_VERSION</span> = 1.0
1386 <span style="color: #000000">07:</span><span style="color: #009900"> LIBFOO_SOURCE</span> = libfoo-<span style="color: #009900">$(LIBFOO_VERSION)</span>.tar.gz
1387 <span style="color: #000000">08:</span><span style="color: #009900"> LIBFOO_SITE</span> = http://www.foosoftware.org/download
1388 <span style="color: #000000">09:</span><span style="color: #009900"> LIBFOO_INSTALL_STAGING</span> = YES
1389 <span style="color: #000000">10:</span><span style="color: #009900"> LIBFOO_INSTALL_TARGET</span> = YES
1390 <span style="color: #000000">11:</span><span style="color: #009900"> LIBFOO_CONF_OPT</span> = -DBUILD_DEMOS=ON
1391 <span style="color: #000000">12:</span><span style="color: #009900"> LIBFOO_DEPENDENCIES</span> = libglib2 host-pkg-config
1392 <span style="color: #000000">13:</span>
1393 <span style="color: #000000">14:</span><span style="color: #009900"> $(eval $(call CMAKETARGETS,package,libfoo))</span>
1396 <p>On line 6, we declare the version of the package.</p>
1398 <p>On line 7 and 8, we declare the name of the tarball and the location
1399 of the tarball on the Web. Buildroot will automatically download the
1400 tarball from this location.</p>
1402 <p>On line 9, we tell Buildroot to install the package to the staging
1403 directory. The staging directory, located in <code>output/staging/</code>
1404 is the directory where all the packages are installed, including their
1405 development files, etc. By default, packages are not installed to the
1406 staging directory, since usually, only libraries need to be installed in
1407 the staging directory: their development files are needed to compile
1408 other libraries or applications depending on them. Also by default, when
1409 staging installation is enabled, packages are installed in this location
1410 using the <code>make install</code> command.</p>
1412 <p>On line 10, we tell Buildroot to also install the package to the
1413 target directory. This directory contains what will become the root
1414 filesystem running on the target. Usually, we try not to install header
1415 files and to install stripped versions of the binary. By default, target
1416 installation is enabled, so in fact, this line is not strictly
1417 necessary. Also by default, packages are installed in this location
1418 using the <code>make install</code> command.</p>
1420 <p>On line 11, we tell Buildroot to pass custom options to CMake when it is
1421 configuring the package.</p>
1423 <p>On line 12, we declare our dependencies, so that they are built
1424 before the build process of our package starts.</p>
1426 <p>Finally, on line line 14, we invoke the <code>CMAKETARGETS</code>
1427 macro that generates all the Makefile rules that actually allows the
1428 package to be built.</p>
1430 <h4 id="cmake-reference">Makefile for CMake packages : reference</h4>
1432 <p>The main macro of the CMake package infrastructure is
1433 <code>CMAKETARGETS</code>. It has the same number of arguments and the
1434 same semantic as the <code>GENTARGETS</code> macro, which is the main
1435 macro of the generic package infrastructure. For CMake packages, the
1436 ability to have target and host packages is also available.</p>
1438 <p>Just like the generic infrastructure, the CMake infrastructure
1439 works by defining a number of variables before calling the
1440 <code>CMAKETARGETS</code> macro.</p>
1442 <p>First, all the package metadata information variables that exist in the
1443 generic infrastructure also exist in the CMake infrastructure:
1444 <code>LIBFOO_VERSION</code>, <code>LIBFOO_SOURCE</code>,
1445 <code>LIBFOO_PATCH</code>, <code>LIBFOO_SITE</code>,
1446 <code>LIBFOO_SUBDIR</code>, <code>LIBFOO_DEPENDENCIES</code>,
1447 <code>LIBFOO_INSTALL_STAGING</code>, <code>LIBFOO_INSTALL_TARGET</code>.</p>
1449 <p>A few additional variables, specific to the CMake infrastructure,
1450 can also be defined. Many of them are only useful in very specific
1451 cases, typical packages will therefore only use a few of them.</p>
1454 <li><code>LIBFOO_SUBDIR</code> may contain the name of a subdirectory
1455 inside the package that contains the main CMakeLists.txt file. This is
1456 useful, if for example, the main CMakeLists.txt file is not at the root
1457 of the tree extracted by the tarball. If <code>HOST_LIBFOO_SUBDIR</code>
1458 is not specified, it defaults to <code>LIBFOO_SUBDIR</code>.</li>
1460 <li><code>LIBFOO_CONF_ENV</code>, to specify additional environment
1461 variables to pass to CMake. By default, empty.</li>
1463 <li><code>LIBFOO_CONF_OPT</code>, to specify additional configure
1464 options to pass to CMake. By default, empty.</li>
1466 <li><code>LIBFOO_MAKE</code>, to specify an alternate <code>make</code>
1467 command. This is typically useful when parallel make is enabled in
1468 the configuration (using <code>BR2_JLEVEL</code>) but that this
1469 feature should be disabled for the given package, for one reason or
1470 another. By default, set to <code>$(MAKE)</code>. If parallel building
1471 is not supported by the package, then it should be set to
1472 <code>LIBFOO_MAKE=$(MAKE1)</code>.</li>
1474 <li><code>LIBFOO_MAKE_ENV</code>, to specify additional environment
1475 variables to pass to make in the build step. These are passed before
1476 the <code>make</code> command. By default, empty.</li>
1478 <li><code>LIBFOO_MAKE_OPT</code>, to specify additional variables to
1479 pass to make in the build step. These are passed after the
1480 <code>make</code> command. By default, empty.</li>
1482 <li><code>LIBFOO_INSTALL_STAGING_OPT</code> contains the make options
1483 used to install the package to the staging directory. By default, the
1484 value is <code>DESTDIR=$$(STAGING_DIR) install</code>, which is
1485 correct for most CMake packages. It is still possible to override
1488 <li><code>LIBFOO_INSTALL_TARGET_OPT</code> contains the make options
1489 used to install the package to the target directory. By default, the
1490 value is <code>DESTDIR=$$(TARGET_DIR) install</code>. The default
1491 value is correct for most CMake packages, but it is still possible
1492 to override it if needed.</li>
1494 <li><code>LIBFOO_CLEAN_OPT</code> contains the make options used to
1495 clean the package. By default, the value is <code>clean</code>.</li>
1498 <p>With the CMake infrastructure, all the steps required to build
1499 and install the packages are already defined, and they generally work
1500 well for most CMake-based packages. However, when required, it is
1501 still possible to customize what is done in any particular step:</p>
1504 <li>By adding a post-operation hook (after extract, patch, configure,
1505 build or install). See the reference documentation of the generic
1506 infrastructure for details.</li>
1508 <li>By overriding one of the steps. For example, even if the CMake
1509 infrastructure is used, if the package <code>.mk</code> file defines its
1510 own <code>LIBFOO_CONFIGURE_CMDS</code> variable, it will be used
1511 instead of the default CMake one. However, using this method
1512 should be restricted to very specific cases. Do not use it in the
1516 <h4 id ="manual-tutorial">Manual Makefile : tutorial</h4>
1518 <p><b>NOTE: new manual makefiles should not be created, and existing
1519 manual makefiles should be converted either to the generic, autotools
1520 or cmake infrastructure. This section is only kept to document the existing
1521 manual makefiles and to help understand how they work.</b></p>
1524 01: #############################################################
1528 05: #############################################################
1529 <span id="ex2line6">06: LIBFOO_VERSION:=1.0</span>
1530 07: LIBFOO_SOURCE:=libfoo-$(LIBFOO_VERSION).tar.gz
1531 08: LIBFOO_SITE:=http://www.foosoftware.org/downloads
1532 09: LIBFOO_DIR:=$(BUILD_DIR)/foo-$(FOO_VERSION)
1533 10: LIBFOO_BINARY:=foo
1534 11: LIBFOO_TARGET_BINARY:=usr/bin/foo
1536 <span id="ex2line13">13: $(DL_DIR)/$(LIBFOO_SOURCE):</span>
1537 14: $(call DOWNLOAD,$(LIBFOO_SITE),$(LIBFOO_SOURCE))
1539 <span id="ex2line16">16: $(LIBFOO_DIR)/.source: $(DL_DIR)/$(LIBFOO_SOURCE)</span>
1540 17: $(ZCAT) $(DL_DIR)/$(LIBFOO_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
1543 <span id="ex2line20">20: $(LIBFOO_DIR)/.configured: $(LIBFOO_DIR)/.source</span>
1544 21: (cd $(LIBFOO_DIR); rm -rf config.cache; \
1545 22: $(TARGET_CONFIGURE_OPTS) \
1546 23: $(TARGET_CONFIGURE_ARGS) \
1548 25: --target=$(GNU_TARGET_NAME) \
1549 26: --host=$(GNU_TARGET_NAME) \
1550 27: --build=$(GNU_HOST_NAME) \
1552 29: --sysconfdir=/etc \
1556 <span id="ex2line33">33: $(LIBFOO_DIR)/$(LIBFOO_BINARY): $(LIBFOO_DIR)/.configured</span>
1557 34: $(MAKE) CC=$(TARGET_CC) -C $(LIBFOO_DIR)
1559 <span id="ex2line36">36: $(TARGET_DIR)/$(LIBFOO_TARGET_BINARY): $(LIBFOO_DIR)/$(LIBFOO_BINARY)</span>
1560 37: $(MAKE) DESTDIR=$(TARGET_DIR) -C $(LIBFOO_DIR) install-strip
1561 38: rm -Rf $(TARGET_DIR)/usr/man
1563 <span id="ex2line40">40: libfoo: uclibc ncurses $(TARGET_DIR)/$(LIBFOO_TARGET_BINARY)</span>
1565 <span id="ex2line42">42: libfoo-source: $(DL_DIR)/$(LIBFOO_SOURCE)</span>
1567 <span id="ex2line44">44: libfoo-clean:</span>
1568 45: $(MAKE) prefix=$(TARGET_DIR)/usr -C $(LIBFOO_DIR) uninstall
1569 46: -$(MAKE) -C $(LIBFOO_DIR) clean
1571 <span id="ex2line48">48: libfoo-dirclean:</span>
1572 49: rm -rf $(LIBFOO_DIR)
1574 <span id="ex2line51">51: #############################################################</span>
1576 53: # Toplevel Makefile options
1578 55: #############################################################
1579 56: ifeq ($(BR2_PACKAGE_LIBFOO),y)
1584 <p>First of all, this Makefile example works for a package which
1585 comprises a single binary executable. For other software, such as
1586 libraries or more complex stuff with multiple binaries, it must be
1587 adapted. For examples look at the other <code>*.mk</code> files in the
1588 <code>package</code> directory.</p>
1590 <p>At lines <a href="#ex2line6">6-11</a>, a couple of useful variables are
1594 <li><code>LIBFOO_VERSION</code>: The version of <i>libfoo</i> that
1595 should be downloaded.</li>
1597 <li><code>LIBFOO_SOURCE</code>: The name of the tarball of <i>libfoo</i>
1598 on the download website or FTP site. As you can see
1599 <code>LIBFOO_VERSION</code> is used.</li>
1601 <li><code>LIBFOO_SITE</code>: The HTTP or FTP site from which
1602 <i>libfoo</i> archive is downloaded. It must include the complete path to
1603 the directory where <code>LIBFOO_SOURCE</code> can be found.</li>
1605 <li><code>LIBFOO_DIR</code>: The directory into which the software will
1606 be configured and compiled. Basically, it's a subdirectory of
1607 <code>BUILD_DIR</code> which is created upon decompression of the tarball.
1610 <li><code>LIBFOO_BINARY</code>: Software binary name. As said previously,
1611 this is an example for a package with a single binary.</li>
1613 <li><code>LIBFOO_TARGET_BINARY</code>: The full path of the binary inside
1614 the target filesystem.</li> </ul>
1616 <p>Lines <a href="#ex2line13">13-14</a> define a target that downloads
1617 the tarball from the remote site to the download directory
1618 (<code>DL_DIR</code>).</p>
1620 <p>Lines <a href="#ex2line16">16-18</a> define a target and associated
1621 rules that uncompress the downloaded tarball. As you can see, this
1622 target depends on the tarball file so that the previous target (lines
1623 <a href="#ex2line13">13-14</a>) is called before executing the rules of
1624 the current target. Uncompressing is followed by <i>touching</i> a
1625 hidden file to mark the software as having been uncompressed. This trick
1626 is used everywhere in a Buildroot Makefile to split steps (download,
1627 uncompress, configure, compile, install) while still having correct
1630 <p>Lines <a href="#ex2line20">20-31</a> define a target and associated
1631 rules that configure the software. It depends on the previous target
1632 (the hidden <code>.source</code> file) so that we are sure the software
1633 has been uncompressed. In order to configure the package, it basically
1634 runs the well-known <code>./configure</code> script. As we may be doing
1635 cross-compilation, <code>target</code>, <code>host</code> and
1636 <code>build</code> arguments are given. The prefix is also set to
1637 <code>/usr</code>, not because the software will be installed in
1638 <code>/usr</code> on your host system, but because the software will be
1639 installed in <code> /usr</code> on the target filesystem. Finally it
1640 creates a <code>.configured</code> file to mark the software as
1643 <p>Lines <a href="#ex2line33">33-34</a> define a target and a rule that
1644 compile the software. This target will create the binary file in the
1645 compilation directory and depends on the software being already
1646 configured (hence the reference to the <code>.configured</code> file).
1647 It basically runs <code>make</code> inside the source directory.</p>
1649 <p>Lines <a href="#ex2line36">36-38</a> define a target and associated
1650 rules that install the software inside the target filesystem. They
1651 depend on the binary file in the source directory to make sure the
1652 software has been compiled. They use the <code>install-strip</code>
1653 target of the software <code>Makefile</code> by passing a
1654 <code>DESTDIR</code> argument so that the <code>Makefile</code> doesn't
1655 try to install the software in the host <code>/usr</code> but rather in
1656 the target <code>/usr</code>. After the installation, the
1657 <code>/usr/man </code> directory inside the target filesystem is removed
1660 <p>Line <a href="#ex2line40">40</a> defines the main target of the
1661 software — the one that will eventually be used by the top level
1662 <code>Makefile</code> to download, compile, and then install this
1663 package. This target should first of all depend on all needed
1664 dependencies of the software (in our example, <i>uclibc</i> and
1665 <i>ncurses</i>) and also depend on the final binary. This last dependency
1666 will call all previous dependencies in the correct order.</p>
1668 <p>Line <a href="#ex2line42">42</a> defines a simple target that only
1669 downloads the code source. This is not used during normal operation of
1670 Buildroot, but is needed if you intend to download all required sources
1671 at once for later offline build. Note that if you add a new package,
1672 providing a <code>libfoo-source</code> target is <i>mandatory</i> to
1673 support users that wish to do offline-builds. Furthermore, it eases
1674 checking if all package-sources are downloadable.</p>
1676 <p>Lines <a href="#ex2line44">44-46</a> define a simple target to clean
1677 the software build by calling the Makefile with the appropriate options.
1678 The <code>-clean</code> target should run <code>make clean</code> on
1679 $(BUILD_DIR)/package-version and MUST uninstall all files of the package
1680 from $(STAGING_DIR) and from $(TARGET_DIR).</p>
1682 <p>Lines <a href="#ex2line48">48-49</a> define a simple target to
1683 completely remove the directory in which the software was uncompressed,
1684 configured and compiled. The <code>-dirclean</code> target MUST
1685 completely rm $(BUILD_DIR)/ package-version.</p>
1687 <p>Lines <a href="#ex2line51">51-58</a> add the target <code>libfoo</code>
1688 to the list of targets to be compiled by Buildroot, by first checking if
1689 the configuration option for this package has been enabled using the
1690 configuration tool. If so, it then "subscribes" this package
1691 to be compiled by adding the package to the TARGETS global variable.
1692 The name added to the TARGETS global variable is the name of this
1693 package's target, as defined on line <a href="#ex2line40">40</a>, which
1694 is used by Buildroot to download, compile, and then install this package.
1697 <h3 id="gettext-integration">Gettext integration and interaction with packages</h3>
1699 <p>Many packages that support internationalization use the gettext
1700 library. Dependencies for this library are fairly complicated and therefore,
1701 deserves some explanation.</p>
1703 <p>The <i>uClibc</i> C library doesn't implement gettext functionality,
1704 therefore with this C library, a separate gettext must be compiled. On
1705 the other hand, the <i>glibc</i> C library does integrate its own
1706 gettext, and in this case, the separate gettext library should not be
1707 compiled, because it creates various kinds of build failures.</p>
1709 <p>Additionally, some packages (such as libglib2) do require gettext
1710 unconditionally, while other packages (those who support
1711 <code>--disable-nls</code> in general) only require gettext when locale
1712 support is enabled.</p>
1714 <p>Therefore, Buildroot defines two configuration options:</p>
1717 <li><code>BR2_NEEDS_GETTEXT</code>, which is true as soon as the
1718 toolchain doesn't provide its own gettext implementation</li>
1720 <li><code>BR2_NEEDS_GETTEXT_IF_LOCALE</code>, which is true if the
1721 toolchain doesn't provide its own gettext implementation and if locale
1722 support is enabled</li> </ul>
1724 <p>Therefore, packages that unconditionally need gettext should:</p>
1727 <li>Use <code>select BR2_PACKAGE_GETTEXT if BR2_NEEDS_GETTEXT</code>
1728 and possibly <code>select BR2_PACKAGE_LIBINTL if BR2_NEEDS_GETTEXT</code>,
1729 if libintl is also needed</li>
1731 <li>Use <code>$(if $(BR2_NEEDS_GETTEXT),gettext)</code> in the package
1732 <code>DEPENDENCIES</code> variable</li>
1735 <p>Packages that need gettext only when locale support is enabled should:
1740 <code>select BR2_PACKAGE_GETTEXT if BR2_NEEDS_GETTEXT_IF_LOCALE</code>
1742 <code>select BR2_PACKAGE_LIBINTL if BR2_NEEDS_GETTEXT_IF_LOCALE</code>,
1743 if libintl is also needed</li>
1745 <li>Use <code>$(if $(BR2_NEEDS_GETTEXT_IF_LOCALE),gettext)</code> in
1746 the package <code>DEPENDENCIES</code> variable</li>
1751 <p>As you can see, adding a software package to Buildroot is simply a
1752 matter of writing a Makefile using an existing example and modifying it
1753 according to the compilation process required by the package.</p>
1755 <p>If you package software that might be useful for other people, don't
1756 forget to send a patch to Buildroot developers!</p>
1758 <h2 id="faq">Frequently asked questions</h2>
1761 <li><a href="#faq-boot-hangs">The boot hangs
1762 after <code>Starting network...</code></a></li>
1763 <li><a href="#module-init-tools-doesnt-build">module-init-tools
1764 fails to build with <code>cannot find -lc</code></a></li>
1767 <h3 id="faq-boot-hangs">The boot hangs after <code>Starting
1768 network...</code></h3>
1770 <p>If the boot process seems to hang after the following messages
1771 (messages not necessarly exactly similar, depending on the list of
1772 packages selected):</p>
1774 <pre>Freeing init memory: 3972K
1775 Initializing random number generator... done.
1777 Starting dropbear sshd: generating rsa key... generating dsa key... OK</pre>
1779 <p>then it means that your system is running, but didn't start a
1780 shell on the serial console. In order to have the system start a
1781 shell on your serial console, you have to go in the Buildroot
1782 configuration, <code>Target options</code>, enable <code>Generic
1783 serial port config</code>, and select the serial port and speed
1784 you would like to use for the shell. This will automatically tune
1785 the <code>/etc/inittab</code> file of the generated system so that
1786 a shell starts on the correct serial port.</p>
1788 <h3 id="module-init-tools-doesnt-build">module-init-tools
1789 fails to build with <code>cannot find -lc</code></h3>
1791 <p>If the build of <i>module-init-tools</i> for the host fails
1794 <pre>/usr/bin/ld: cannot find -lc </pre>
1796 <p>then probably you are running a Fedora (or similar)
1797 distribution, and you should install the <code>glibc-static</code>
1798 package. This is because the <i>module-init-tools</i> build
1799 process wants to link statically against the C library.</p>
1801 <h2 id="links">Resources</h2>
1803 <p>To learn more about Buildroot you can visit these websites:</p>
1806 <li><a href="http://www.uclibc.org/">http://www.uclibc.org/</a></li>
1807 <li><a href="http://www.busybox.net/">http://www.busybox.net/</a></li>