1 AUTHOR: Robert Connolly <robert@linuxfromscratch.org>
7 SYNOPSIS: uClibc C/C++ library
10 The uClibc libraries are designed to be small, for embeded systems, while having
11 most of the features of Glibc so that most software will be able to use uClibc, even
12 Xorg and KDE. uClibc also features a menuconfig similar to the Linux kernel, so that
13 features can be configured to talior the library for your specific needs. uClibc is an
14 excelent choice for any small system, but can be used for desktops as well.
17 http://www.uclibc.org/
18 http://cxx.uclibc.org/
19 http://www.linuxfromscratch.org/hlfs/view/unstable/uclibc/
21 http://buildroot.uclibc.org/
23 PREREQUISITES: Sed version 4 (or higher)
27 # This hint will show how to install uClibc either as part of an LFS build, or beside
28 # an existing system. If you choose to install to an existing system then you will
29 # simply need to change your CC and CXX environment variables to use it.
31 # This hint may be a bit hard to follow because it covers two installation types. Be
32 # sure to take your time, to make sure you follow the parts relevant to you. Plan on
33 # botching the first try (like any typical LFS build).
37 # http://www.uclibc.org/downloads/uClibc-0.9.28.tar.bz2
41 # http://www.uclibc.org/downloads/uClibc-locale-030818.tgz
43 # The uClibc C++ library (optional):
45 # http://cxx.uclibc.org/src/uClibc++-0.1.11.tbz2
49 # http://www.linuxfromscratch.org/patches/downloads/uClibc/uClibc-0.9.28-config-1.patch
50 # http://www.linuxfromscratch.org/patches/downloads/uClibc/\
51 # uClibc-0.9.28-libc_stack_end-1.patch
52 # http://www.linuxfromscratch.org/patches/downloads/binutils/\
53 # binutils-2.16.1-uClibc_conf-1.patch
54 # http://www.linuxfromscratch.org/patches/downloads/gcc/gcc-3.4.4-uClibc_conf-1.patch
55 # http://www.linuxfromscratch.org/patches/downloads/gcc/gcc-3.4.4-no_fixincludes-1.patch
56 # http://www.linuxfromscratch.org/patches/downloads/gcc/gcc-3.4.4-specs_x86-1.patch
58 # For g++ (not uClibc++):
59 # http://www.linuxfromscratch.org/patches/downloads/gcc/\
60 # gcc-3.4.3-uClibc_libstdc++-1.patch
61 # http://www.linuxfromscratch.org/patches/downloads/gcc/gcc-3.4.3-uClibc_conf-1.patch
62 # http://www.linuxfromscratch.org/patches/downloads/gcc/gcc-3.4.3-uClibc_locale-1.patch
64 # To use the uClibc support for SSP (optional):
65 # Also see: http://www.linuxfromscratch.org/hints/downloads/files/ssp.txt
66 # http://www.linuxfromscratch.org/patches/downloads/linux-libc-headers/\
67 # linux-libc-headers-2.6.11.2-pseudo_random-1.patch
68 # http://www.linuxfromscratch.org/patches/downloads/gcc/gcc-3.4.4-ssp-1.patch
69 # http://www.linuxfromscratch.org/patches/downloads/uClibc/\
70 # uClibc-0.9.28-arc4random-2.patch
71 # http://www.linuxfromscratch.org/patches/downloads/linux/\
72 # linux-2.6.11.12-pseudo_random-1.patch
75 # http://www.linuxfromscratch.org/patches/downloads/sed/sed-4.1.4-uClibc-1.patch
76 # http://www.linuxfromscratch.org/patches/downloads/shadow/shadow-4.0.13-uClibc-1.patch
77 # http://www.linuxfromscratch.org/patches/hlfs/svn/psmisc-21.6-rpmatch-1.patch
80 # Do not expect many package testsuites to pass.
82 # If you are installing to an existing system then add a uclibc user and a dedicated
83 # uclibc directory. After installation this user can be removed. If you are installing
84 # a new LFS then ignore this. If you want to install a i386 or i486 toolchain, then
85 # use "i386-pc-linux-uclibc" or "i486-pc-linux-uclibc". Compiling for i386 makes smaller
89 useradd -g uclibc -s /bin/bash -d /home/uclibc -m uclibc &&
90 install -d -o uclibc /usr/i386-pc-linux-uclibc/
92 # If you are installing beside an existing system then you are probably planning to
93 # use the uClibc libraries on another system, like a floppy disk or cdrom. It's best
94 # to link to / instead of /usr/i386-pc-linux-uclibc/lib, because the later is clumsy.
95 # To do this, without messing up our existing system, we will symlink
96 # /usr/i386-pc-linux-uclibc/lib to /ulib. Header files, the compiler, and linker will
97 # be installed in /usr/i386-pc-linux-uclibc, but the compiler will link to /ulib. This
98 # will allow us to build and test packages linked to uClibc, without a chroot.
100 # I decided not to try symlinking /usr/i386-pc-linux-uclibc/lib/ld-uClibc.so.0 to /lib
101 # so it does not conflict with my host system, which is also uClibc.
103 ln -s /usr/i386-pc-linux-uclibc/lib /ulib
105 # If you are installing LFS-uClibc then su to user lfs and don't adjust the $PATH.
106 # if you are installing to an existing system, then su to user uclibc:
109 export PATH=/usr/i386-pc-linux-uclibc/bin:$PATH
111 # We will use the $prefix variable in this hint. If you are installing to an existing
112 # system then it will point to /usr. We also set the ldso directory to /ulib:
114 export prefix=/usr/i386-pc-linux-uclibc &&
115 export ldso_dir=/ulib
117 # If you are installing a new LFS system then the $prefix will be /tools, and the ldso
118 # directory will be /tools/lib:
120 export prefix=/tools &&
121 export ldso_dir=/tools/lib
123 # We will also use the $target variable. This is the same regardless of where you are
126 export target=i386-pc-linux-uclibc
128 # Now we start the installation.
132 # First install the linux-libc-headers:
134 # If you plan to use SSP, apply this patch:
136 patch -Np1 -i ../linux-libc-headers-2.6.11.2-pseudo_random-1.patch
138 # Then install the kernel headers:
140 install -d ${prefix}/include &&
141 cp -R include/asm-i386 ${prefix}/include/asm &&
142 cp -R include/linux ${prefix}/include
144 # Secondly we install the uClibc headers:
146 patch -Np1 -i ../uClibc-0.9.28-config-1.patch &&
147 make KERNEL_SOURCE=${prefix} headers &&
148 rm include/{asm,asm-generic,linux} &&
149 make DEVEL_PREFIX=${prefix}/ install_dev
151 # Don't worry about the "lib/: No such file or directory" message.
153 # Thirdly, install the Binutils Cross Linker:
155 patch -Np1 -i ../binutils-2.16.1-uClibc_conf-1.patch &&
156 mkdir ../binutils-build &&
157 cd ../binutils-build &&
158 ../binutils-2.16.1/configure --prefix=${prefix} \
159 --disable-shared --disable-nls --target=${target} &&
163 make -C ld LIB_PATH=${ldso_dir}
165 # Do not remove the binutils-2.16.1/ and binutils-build/ directories yet.
167 # Fourthly, install the GCC Cross Compiler (C only):
169 # GCC will try to use ${prefix}/${target}/include because GCC is a cross compiler. Fix
170 # that with this command:
172 sed -e "s@\(^CROSS_SYSTEM_HEADER_DIR =\).*@\1 ${prefix}/include@g" \
175 # Add this patch so we can specify where our ld.so library will be:
177 patch -Np1 -i ../gcc-3.4.4-specs_x86-1.patch
179 # GCC will default to use ${prefix}/${target}/lib for the startfile prefix because GCC
180 # is a cross compiler here. Fix that with this command:
183 #undef STARTFILE_PREFIX_SPEC
184 #define STARTFILE_PREFIX_SPEC \"${prefix}/lib/\"" >> gcc/config/linux.h
186 # Build and install GCC:
188 patch -Np1 -i ../gcc-3.4.4-uClibc_conf-1.patch &&
189 touch ${ldso_dir}/ld-uClibc.so.0 &&
190 mkdir ../gcc-build &&
192 ../gcc-3.4.4/configure --prefix=${prefix} --target=${target} \
193 --disable-nls --disable-shared --enable-languages=c \
194 --with-dynamic-linker=${ldso_dir}/ld-uClibc.so.0 --with-nostdinc &&
198 # Now install uClibc:
202 patch -Np1 -i ../uClibc-0.9.28-arc4random-2.patch
204 # If you want locales:
206 install -m444 ../uClibc-locale-030818.tgz extra/locale/
208 # Add a config file (with just enough enabled to be able to build any package):
210 patch -Np1 -i ../uClibc-0.9.28-config-1.patch
212 # This patch is needed to fix a bug in this version of uClibc. It is only needed in
213 # the first uClibc build (stage 1 of bootstrap):
215 patch -Np1 -i ../uClibc-0.9.28-libc_stack_end-1.patch
217 # Reset the installation paths:
219 sed -e "s@.*SHARED_LIB_LOADER_P.*@SHARED_LIB_LOADER_PREFIX=\"${prefix}/lib\"@g" \
221 sed -e "s@.*RUNTIME_PREFIX.*@RUNTIME_PREFIX=\"${prefix}\"@g" \
223 sed -e "s@.*DEVEL_PREFIX.*@DEVEL_PREFIX=\"${prefix}/\"@g" \
225 sed -e "s@.*KERNEL_SOURCE.*@KERNEL_SOURCE=\"${prefix}\"@g" -i .config
227 # Now you can run "make menuconfig". The defaults from the config patch will let
228 # you build almost anything. If you do not want locales you should disable:
229 # UCLIBC_HAS_LOCALE under "String and Stdio Support".
230 # If you do not want to use SSP, then disable:
231 # UCLIBC_HAS_SSP under "uClibc security related options".
233 # If you are installing beside an existing system, and you modified the config, you
234 # should save the .config file for later, because make menuconfig won't work without
235 # ncurses. If you're installing a new LFS, make menuconfig will work in chapter 6.
239 make CROSS=${target}- all
241 # And install uClibc (after removing some symlinks):
243 rm include/{asm,asm-generic,linux} &&
246 # uClibc does not supply a libintl.so. If you installed locales then you should install
247 # Gettext's libintl too:
249 cd gettext-runtime/ &&
250 env CC=${target}-gcc \
251 ./configure --prefix=${prefix} --with-included-gettext \
252 --without-csharp --disable-libasprintf &&
254 make -C intl/ install
256 # Then make GCC link everything to libintl (this fixes bugs in several packages). To
257 # disable this linking on specific packages, use CFLAGS="-nointl":
259 sed -e 's/%{shared:-lc}/%{!nointl: -lintl} &/' \
260 -i `${target}-gcc --print-file specs`
262 # Now adjust the toolchain:
264 install ld/ld-new ${prefix}/bin/${target}-ld
265 ln -f ${prefix}/bin/${target}-ld ${prefix}/${target}/bin/ld
269 echo 'main(){}' | ${prefix}/bin/${target}-gcc -x c -
270 readelf -l a.out | grep ": ${prefix}"
272 # This should return:
273 # Requesting program interpreter: /usr/i386-pc-linux-uclibc/lib/ld-uClibc.so.0]
275 # Requesting program interpreter: /tools/lib/ld-uClibc.so.0]
277 # Now remove the binutils-2.16.1/ and binutils-build/ directories.
279 # If you are installing LFS-uclibc, then install TCL, Expect, and DejaGNU.
281 # Binutils Native Linker:
283 patch -Np1 -i ../binutils-2.16.1-uClibc_conf-1.patch &&
284 mkdir ../binutils-build &&
285 cd ../binutils-build &&
286 env CC=${target}-gcc \
287 ../binutils-2.16.1/configure --prefix=${prefix} \
288 --host=${target} --build=${target} --target=${target} \
289 --enable-shared --with-lib-path=${ldso_dir} &&
293 make -C ld LIB_PATH=/usr/lib:/lib
295 # If you're installing LFS-uClibc, then do not remove the binutils-2.16.1/ and
296 # binutils-build directories, until readjusting in chapter 6. If you're installing
297 # beside an existing system, then these directories can be removed.
299 # GCC Native Compiler (C and C++):
303 patch -Np1 -i ../gcc-3.4.4-ssp-1.patch &&
304 sed -e 's@gcc.gnu.org/bugs.html@bugs.linuxfromscratch.org/@' \
305 -e 's/3.4.4/3.4.4 (ssp)/' -i gcc/version.c
307 # To link libintl to everything:
309 sed -e 's/%{shared:-lc}/%{!nointl: -lintl} &/' \
310 -i gcc/config/linux.h
312 # Now patch, build, and install GCC:
314 patch -Np1 -i ../gcc-3.4.4-uClibc_conf-1.patch &&
315 patch -Np1 -i ../gcc-3.4.4-uClibc_libstdc++-1.patch &&
316 patch -Np1 -i ../gcc-3.4.4-uClibc_locale-1.patch &&
317 patch -Np1 -i ../gcc-3.4.4-specs_x86-1.patch &&
318 patch -Np1 -i ../gcc-3.4.4-no_fixincludes-1.patch &&
319 mkdir ../gcc-build &&
321 env CC=${target}-gcc \
322 ../gcc-3.4.4/configure --prefix=${prefix} \
323 --host=${target} --build=${target} --target=${target} \
324 --libexecdir=${ldso_dir} --with-local-prefix=${prefix} \
325 --enable-shared --enable-threads=posix \
326 --enable-__cxa_atexit --enable-languages=c,c++ \
327 --disable-libstdcxx-pch --enable-clocale \
328 --with-dynamic-linker=${ldso_dir}/ld-uClibc.so.0 --with-nostdinc \
329 --enable-multilib=no &&
332 ln -s gcc ${prefix}/bin/cc
334 # To enable SSP by default, and test it, see section 5.12.2 and 5.12.3 of:
335 # http://www.linuxfromscratch.org/hlfs/view/unstable/uclibc/chapter05/gcc.html
337 # If you are building LFS-uclibc, finish building chapter 5 normally, starting after
338 # the second GCC build.
340 # If you have installed uClibc beside an existing system, then rebuild uClibc now so
341 # that it becomes bootstraped. The libc_stack_end patch shouldn't be needed anymore.
345 patch -Np1 -i ../uClibc-0.9.28-arc4random-2.patch
349 install -m444 ../uClibc-locale-030818.tgz extra/locale/
351 # Add the config patch (or copy the one you saved before):
353 patch -Np1 -i ../uClibc-0.9.28-config-1.patch
355 # Reset the installation paths:
357 sed -e "s@.*SHARED_LIB_LOADER_P.*@SHARED_LIB_LOADER_PREFIX=\"${prefix}/lib\"@g" \
359 sed -e "s@.*RUNTIME_PREFIX.*@RUNTIME_PREFIX=\"${prefix}\"@g" \
361 sed -e "s@.*DEVEL_PREFIX.*@DEVEL_PREFIX=\"${prefix}/\"@g" \
363 sed -e "s@.*KERNEL_SOURCE.*@KERNEL_SOURCE=\"${prefix}\"@g" -i .config
365 # Make uClibc a little smaller and faster:
367 sed -e 's/^OPTIMIZATION:=.*$/& -fomit-frame-pointer/' -i Rules.mak
369 # The build and reinstall uClibc:
371 make CROSS=${target}- all &&
372 rm include/{asm,asm-generic,linux} &&
375 # If you want ldconfig installed too:
378 make CC="gcc -Wl,--dynamic-linker,${ldso_dir}/ld-uClibc.so.0 ${ldso_dir}/libc.so.0" \
380 make -C utils install
382 # Then relocate ldconfig:
384 mv ${prefix}/sbin/ldconfig ${prefix}/bin &&
385 rmdir ${prefix}/sbin/
387 # And reinstall Gettext too (the uClibc reinstall removed the libintl.h header):
389 cd gettext-runtime/ &&
390 env CC=${target}-gcc \
391 ./configure --prefix=${prefix} --with-included-gettext \
392 --without-csharp --disable-libasprintf &&
394 make -C intl/ install
396 # If you're installing beside an existing system, you're almost finished. Skip the
397 # Chapter 6 section below, and start reading from "Installing uClibc++".
400 (Installing a new LFS-uClibc system)
402 # Install Linux-libc-headers:
404 patch --no-backup-if-mismatch -Np1 -i \
405 ../linux-libc-headers-2.6.11.2-pseudo_random-1.patch &&
406 cp -R include/asm-i386 /usr/include/asm &&
407 cp -R include/linux /usr/include &&
408 chown -R root:root /usr/include/{asm,linux} &&
409 find /usr/include/{asm,linux} -type d -exec chmod 755 {} \; &&
410 find /usr/include/{asm,linux} -type f -exec chmod 644 {} \;
412 # Install Man-pages...
418 patch -Np1 -i ../uClibc-0.9.28-arc4random-2.patch &&
419 install -m644 libc/stdlib/man/arc4random.3 /usr/share/man/man3
423 install -m444 ../uClibc-locale-030818.tgz extra/locale/
425 # Patch the config file:
427 patch -Np1 -i ../uClibc-0.9.28-config-1.patch
429 # Run menuconfig if you want:
433 # Fix the installation paths (this installs to /):
435 sed -e 's@.*SHARED_LIB_LOADER_PREFIX.*@SHARED_LIB_LOADER_PREFIX="/lib"@g' \
437 sed -e 's@.*RUNTIME_PREFIX.*@RUNTIME_PREFIX="/"@g' -i .config &&
438 sed -e 's@.*DEVEL_PREFIX.*@DEVEL_PREFIX="/usr/"@g' -i .config &&
439 sed -e 's@.*KERNEL_SOURCE.*@KERNEL_SOURCE="/usr"@g' -i .config
441 # Make uClibc a little smaller and faster:
443 sed -e 's/^OPTIMIZATION:=.*$/& -fomit-frame-pointer/' -i Rules.mak
445 # Then make and install uClibc:
448 rm include/{asm,asm-generic,linux} &&
451 make CC="gcc -Wl,--dynamic-linker,/lib/ld-uClibc.so.0 /lib/libc.so.0" \
453 make -C utils install &&
454 echo "/usr/local/lib" > ld.so.conf.new &&
455 install -m644 ld.so.conf.new /etc/ld.so.conf
457 # Adjust your timezone:
458 # Also see: http://leaf.sourceforge.net/doc/guide/buci-tz.html#id25991
460 echo "EST5EDT" > TZ.new
461 install -m644 TZ.new /etc/TZ
463 # If you installed uClibc with locales support, install Gettext now:
466 ./configure --prefix=/usr --libdir=/lib --with-included-gettext \
467 --disable-static --enable-relocatable --disable-rpath
469 make -C intl/ install &&
470 rm /lib/libintl.so &&
471 ln -sf ../../lib/libintl.so.3 /usr/lib/libintl.so
473 # Readjust the toolchain:
475 install ld/ld-new /tools/bin/ld &&
476 perl -pi -e 's: /tools/lib/ld-uClibc.so.0: /lib/ld-uClibc.so.0:g;' \
477 -e 's@\*startfile_prefix_spec:\n@$_/usr/lib/@g;' \
478 $(gcc --print-file specs)
482 echo 'main(){}' > dummy.c
484 readelf -l a.out | grep ': /lib'
488 patch -Np1 -i ../binutils-2.16.1-uClibc_conf-1.patch &&
489 mkdir ../binutils-build &&
490 cd ../binutils-build &&
491 ../binutils-2.16.1/configure --prefix=/usr --enable-shared \
492 --host=i386-pc-linux-uclibc --build=i386-pc-linux-uclibc \
493 --target=i386-pc-linux-uclibc &&
495 make tooldir=/usr install &&
496 install -m644 ../binutils-2.16.1/include/libiberty.h /usr/include
502 patch -Np1 -i ../gcc-3.4.4-ssp-1.patch &&
503 sed -e 's@gcc.gnu.org/bugs.html@bugs.linuxfromscratch.org/@' \
504 -e 's/3.4.4/3.4.4 (ssp)/' -i gcc/version.c
508 patch -Np1 -i ../gcc-3.4.4-uClibc_conf-1.patch &&
509 patch -Np1 -i ../gcc-3.4.4-uClibc_libstdc++-1.patch &&
510 patch -Np1 -i ../gcc-3.4.4-uClibc_locale-1.patch &&
511 patch -Np1 -i ../gcc-3.4.4-specs_x86-1.patch &&
512 patch -Np1 -i ../gcc-3.4.4-no_fixincludes-1.patch &&
513 patch -Np1 -i ../gcc-3.4.4-linkonce-1.patch &&
514 sed -e 's/install_to_$(INSTALL_DEST) //' -i libiberty/Makefile.in &&
515 mkdir ../gcc-build &&
517 ../gcc-3.4.4/configure --prefix=/usr --host=i386-pc-linux-uclibc \
518 --build=i386-pc-linux-uclibc --target=i386-pc-linux-uclibc \
519 --libexecdir=/usr/lib --enable-threads=posix \
520 --enable-shared --enable-__cxa_atexit \
521 --with-dynamic-linker=/lib/ld-uClibc.so.0 --enable-clocale \
522 --enable-languages=c,c++ --enable-multilib=no &&
525 ln -s ../usr/bin/cpp /lib &&
526 ln -s gcc /usr/bin/cc
528 # If you are using SSP, then rerun /tools/bin/hardened-specs.sh and redo the tests.
530 # Now the rest of Chapter 6 can be built normally, and/or install uClibc++ now.
532 ### Installing uClibc++ ###
538 # To install beside an existing system leave $prefix alone.
540 # LFS-uClibc can run 'make menuconfig'. If you installed beside an existing system,
541 # then your ncurses library will not be found in ${prefix}, so only make config will
544 # To enable everything:
548 # Then fix the installation path:
550 sed -e "s@.*UCLIBCXX_RUNTIME_PREFIX.*@UCLIBCXX_RUNTIME_PREFIX=\"${prefix}\"@g" \
553 # The build and install uClibc++:
558 # If you're installing beside an existing system, then make "g++-uc" link to /ulib:
560 sed -e 's@/usr/i386-pc-linux-uclibc/lib/@/ulib@g' -i ${prefix}/bin/g++-uc
562 # To use gcc++-uc, run:
566 # uClibc++ may not work with all packages, try it out and see. Also, uClibc++ depends
567 # on g++, so it is unable to bootstrap itself.
569 # If you installed beside an existing system, then also run:
571 export CC="/usr/i386-pc-linux-uclibc/bin/i386-pc-linux-uclibc-gcc"
573 # If you installed uClibc beside an existing system, you can now remove the uclibc user
574 # and change the ownership of /usr/i386-pc-linux-uclibc.
576 chown -R 0:0 /usr/i386-pc-linux-uclibc
578 # Anything else you need to know should be covered by other documentation, such as
579 # the "Boot Disk Howto", etc.
581 # Send me comments or questions if you like.
584 * Thanks to the uClibc team for creating this software.