Typo
[linux_from_scratch_hints.git] / OLD / uclibc-lfs.txt
blob8232b22700565da1e535c400916cc22fa4e83f67
1 TITLE:          uclibc-lfs
2 LFS VERSION:    N/A
3 AUTHOR:         MichaĆ«l Tousignant <evanidus@videotron.ca>
5 SYNOPSIS:
6         How to build a uClibc based, base LFS system.
8 HINT:
10 HINT VERSION:   0.3r4 (20020816)
12 CHANGELOG:
13         0.3r3 -> 0.3r4
14                 - Updated the faulty reiserfsprogs install instructions
15         0.3r2 -> 0.3r3
16                 - Added static gcc 2.95.3-2 installation commands.
17                 - Added gcc 2.95.3 tarball download location.
18         0.3r1 -> 0.3r2
19                 - Added a changelog
20                 - Added notes about GCC 3.x and static perl 5.6.1
21                 - Added gcc 2.95.3-2 note about LFS chapter 5.
22         0.3   -> 0.3r1
23                 - Fixed url for patches
24         0.2r1 -> 0.3
25                 - Added patch to compile GCC's C++ compiler and libraries
26                 - Removed man2cat instructions
27                 - Removed static groff compilation, added it shared.
28                 - Removed file and ncurses' tic workarounds, added patches.
29                 - Removed nasm
30                 - Updated packages versions
31                 - Did some cleanups.
32         0.2   -> 0.2r1
33                 - Small modifications to make the hint more LFS hints 
34                   standards compilant.
35         0.2
36                 - Initial public release.
38 Before trying to build a uClibc system, you should ask yourself if you
39 really want to because it means:
40     - No modutils (Unless if you don't mind using a glibc static modutils)
41     - No support (for now) for installing non-LFS packages (good luck)
42     - This hint was made/tested using gcc 2.95.3-2 on x86 only. If you are 
43       using gcc 3.x.x or different arch, you 'might' encounter new problems. 
44       (good luck)
45 Be sure to check the uClibc website (http://www.uclibc.org/) and docs to see 
46 what it support and what it don't.
48 =======================
49 0. Table of Content
50 =======================
52 1. Prerequisites
53 2. System preparations
54 3. Building the system
55 4. F.A.Q.
57 =======================
58 1. Prerequisites
59 =======================
61 Prerequisites (Before starting LFS chapter6):
62     - A complete LFS chapter 5
63       (keep chap 5 & 6 separated (/static style) is very recommended moreover 
64        since this hint will assume you are using it.)
65     - gcc 2.95.3 tarball         (ftp://ftp.gnu.org/gnu/gcc/)
66     - perl-5.6.1 tarball         (http://www.perl.org/)
67     - (optional) modutils tarball(ftp://ftp.kernel.org/pub/linux/utils/kernel/)
69 Prerequisites (To complete LFS chapter6)
70     - All LFS chapter6 packages tarballs and patches except:
71         1. psmisc 20.2+
72         2. modutils
73         3. gcc 3.x+
74         4. glibc
76     - uClibc-0.9.14 tarball             (http://www.uclibc.org/)
77     - psmisc-20.1 tarball               (http://psmisc.sourceforge.net/)
79     - Various patches (their functions are explained later) that can be found
80       under: ftp://ftp.linuxfromscratch.org/lfs-hints/patches/ from the file 
81       named "uclibc-lfs-patches-0.3.tar.bz2"
83     - The LFS book, 3.3+ recommended.   (http://www.linuxfromscratch.org/)
85 =======================
86 2. System preparations
87 =======================
89 Before starting chapter6 in the book, we'll need to add some extras to the 
90 chapter5 static utilities:
92 Note: Every commands are expected to be run inside the freshly extracted 
93       clean source of the package.
95 - static gcc 2.95.3-2
96     If the LFS Chapter 5 static utilities you are going to use have gcc 3.x 
97     rather than gcc 2.95.3. Here is the instructions to replace it (if you 
98     already have gcc 2.95.3-2 ready, you may skip this step):
100     patch -Np1 -i ../uclibc-lfs-patches/gcc-2.95.3-2.patch &&
101     mkdir ../gcc-build &&
102     cd ../gcc-build &&
103     ../gcc-2.95.3/configure --prefix=/static --enable-languages=c \
104             --disable-nls --disable-shared --enable-threads=posix &&
105     make BOOT_LDFLAGS=-static bootstrap &&
106     make prefix=$LFS/static install &&
107     ln -s gcc $LFS/static/bin/cc
109 - static perl (tested with 5.6.1)
110     GCC 3.x notice: If the host compiler you are using is gcc 3.x, you might 
111     encounter problems compiling a static perl 5.6.1. If this is the case, 
112     use perl 5.8.0 instead.
114     Perl is needed to execute a script during uClibc compilation
115     It can be installed by running the following commands:
117     ./Configure -Dprefix=/static -Dinstallprefix=$LFS/static -Dso=none \
118                 -Dldflags=-static -Uinstallusrbinperl -Uusedl -Dman1dir=none \
119                 -d -e &&
120     make &&
121     make install
123     Note: Don't bother configuring perl properly (i.e. the way you want it)
124           because it'll be normally reinstalled in chapter6, defaults will do.
126 - optional static modutils (tested with 2.4.16)
127     For still unknown reasons, utils from modutils tends to segfault when 
128     doing certain operations when linked against uClibc making them unusable.
130     If, for you, modules are important (you can always build a modules-free 
131     kernel), you'll need to build a static glibc modutils by running the 
132     following commands:
134     ./configure --prefix=$LFS/usr --exec-prefix=$LFS \
135                 --mandir=$LFS/usr/share/man &&
136     make LDFLAGS=-static &&
137     make install
139 =======================
140 3. Building the system
141 =======================
143     Now, let's start the LFS chapter6. Do everything the LFS book tell you to 
144     do until you reach the first package (usualy linux headers or glibc)
146     First, extract the uclibc-lfs-patches package inside the same directories
147     as other packages.
149     If not already done, (some versions of the book do it while building glibc,
150     some do it before and some run MAKEDEV itself before which do it), also do:
152     mknod -m 0666 /dev/null c 1 3
154     From here on, every commands are expected to be run inside the freshly 
155     extracted clean source of the package we are working on.    
157     Note: You can install things in the same order of the book or whichever 
158           order you prefer except for the followings 'should' be installed in 
159           this order:
161         1. linux source and headers
162         2. uClibc 0.9.14
163         3. GCC 2.95.3-2
165            Some packages uses utilities like 'chown' and 'id' which might need
166            to resolve user and group names. Since our chapter 5 is glibc based,
167            they won't be able to resolve them even after uClibc is installed so
168            we must recompile/install them first.
170         3. fileutils
171         4. sh-utils
173         5. MAKEDEV (Creating Devices)
174           -> This might be already done based on book version, if so, skip.
176         6. ncurses
177         7. bash
179         For other packages, you can use the order you want but the one stated 
180         in this hint is prefered since it is with what it was tested.
182         Instructions to install packages are found further down.
184 - Linux source and headers (tested 2.4.19)
185     Some versions of the book do this in chapter 5 and some others before 
186     glibc in chapter 6. uClibc will need the kernel source to be around.
188     If you didn't install the headers in chapter 5, run the commands in 
189     the book (near start of chapter 6) and keep the source.
191     If you installed the headers in chapter 5 and did not keep the source,
192     run the following commands (ignore symlinks errors):
193         ln -s ../static/bin/pwd /bin/pwd
194         ln -s ../static/bin/bash /bin/sh
195         make mrproper &&
196         make include/linux/version.h &&
197         make symlinks
199 - uClibc 0.9.14
200     Instead of glibc (which we won't install at all), we'll now install 
201     uClibc-0.9.14.
203     We'll first need some symbolic links. Some of these might already exist 
204     so you can ignore errors (Note: if any binaries were installed in 
205     /static/usr/bin rather than /static/bin, you'll need to update the links):
207     ln -s ../static/bin/bash /bin/sh
208     ln -s ../static/bin/pwd /bin
209     ln -s ../../static/bin/perl /usr/bin
210     ln -s ../static/bin/true /bin
212     Note: These were not created before because some version of the book 
213           create and delete the pwd symlink installing linux headers. So we 
214           ensure we got everything here.
216     You can now compile/install uClibc by running the following commands 
217     for which explanations are found further down:
219     Note: It is strongly recommended to use the default optimizations
220           suggested by uClibc. This includes -march=
222     In the following commands, replace '/usr/src/linux-2.4.19' to the path 
223     where the kernel source is (if needed).
225     patch -Np1 < ../uclibc-lfs-patches/uClibc-0.9.14.patch &&
226     ln -s extra/Configs/Config.i386 Config &&
227     make DOSHAREDMAIN=true DO_C99_MATH=true HAS_SHADOW=true DOLFS=true \ 
228          INCLUDE_RPC=true KERNEL_SOURCE=/usr/src/linux-2.4.19 all install
230     /dev/pty* notes: uClibc can be configured to use /dev/pty* devices 
231          rather than devpts/devfs's /dev/pts directory; but to use these, 
232          the 'pt_chown' program is needed and is not provided by uClibc.
233          If you really need /dev/pty* support, you'll need to grab the 
234          pt_chown source from glibc, compile it with uClibc and put it in
235          /sbin as set-uid root. - I strongly advise everyone to use devpts 
236          or devfs instead (the LFS book explains how to setup devpts)
238     Commands explanation:
239         patch -Np1 < ../uclibc-lfs-patches/uclibc-0.9.14.patch
240           -> This adds "DOSHAREDMAIN=true" support to Makefiles which allow 
241              us to install uClibc while no o1ther libc is present and as 
242              "main" libc. (e.g. use /lib, /usr/{lib,include} etc.. rather than
243              all under /usr/<arch>-linux-uclibc/). It also removes the need 
244              of a gcc/ld wrapper and add a small flag in uClibc_stdio.h which 
245              will help with GCC's C++ compilation.
247         ln -s extra/Configs/Config.i386 Config
248           -> Simply gets the default configs for Config.<arch>. If you are 
249              using a non-x86 system you'll need to adjust this. (Sadly, this 
250              hint was made/tested by using x86 only, but good luck.)
251                
252         make DOSHAREDMAIN=true DO_C99_MATH=true HAS_SHADOW=true DOLFS=true 
253              INCLUDE_RPC=true all install \
254           -> Will build/install uClibc, the different variables set will do:
255                - DOSHAREDMAIN=true
256                  -> Activate our patch (install uClibc as main libc)
257                - DO_C99_MATH=true
258                  -> Provide a full set of C99 math features for the math 
259                     library (libm) Many recent packages using libm needs this.
260                - HAS_SHADOW=true
261                  -> Add shadow password support (which a normal LFS use)
262                - DOLFS=true
263                  -> Add Large File Support (2GB+), although you can disable 
264                     the use of this on most packages if you don't need it. 
265                     Some (such as recent e2fsprogs) just won't compile without
266                     it. So best to enable it.
267                     Note: the kernel will also need to support large files
268                - INCLUDE_RPC=true
269                  -> RPC is not used by much things besides NFS (network file 
270                     system). Yet, some packages like shadow will try to use 
271                     a function provided by this. So we enable it by default.
272                - KERNEL_SOURCE=/usr/src/linux-2.4.19
273                  -> Simply tells uClibc where the kernel source is.
275         Note: If you need a full set of RPC functions, you can also supply 
276               "INCLUDE_FULL_RPC=true". Most people shouldn't need this, NFS 
277               mounts works fine without it.
279 ----------------------
281     To install the following packages, just follow the LFS book instructions 
282     in chapter6 and apply the modifications/additions to these commands 
283     mentioned below (if any) while doing so:
285     Note: Exact commands won't be given to increase compatibility with the LFS 
286           book version you are using and make this hint be easier to keep up 
287           to date.
289 - man-pages (tested with 1.52)
291 - GCC 2.95.3-2
292     Since gcc 2.95.3 is being made obsolete in recent LFS books (replaced
293     by gcc 3.1+), we'll give the exact commands.
295     GCC's libstdc++ library use libio which is normaly avaible within glibc
296     and fail to properly detect missing functions and create proper headers.
298     The following commands will solve the problem and build/install GCC's C
299     and C++ compiler (Note: the fix is still experimental, might not work
300     for everyone.)
302     patch -Np1 < ../uclibc-lfs-patches/gcc-2.95.3-2.patch &&
303     patch -Np1 < ../uclibc-lfs-patches/gcc-2.95.3-uClibc.patch &&
304     cp ../uclibc-lfs-patches/_G_config.h /usr/include &&
305     mkdir ../gcc-build &&
306     cd ../gcc-build &&
307     ../gcc-2.95.3/configure --prefix=/usr --enable-shared --disable-nls \
308           --enable-languages=c,c++ --enable-threads=posix &&
309     make bootstrap &&
310     make install &&
311     ln -sf ../usr/bin/cpp /lib &&
312     ln -sf ../bin/cpp /usr/lib &&
313     ln -sf gcc /usr/bin/cc &&
314     rmdir /usr/*-gnu/include &&
315     rmdir /usr/*-gnu
317 - fileutils (tested with 4.1)
318     append to ./configure flags: --disable-nls
319     
320 - sh-utils (tested with 2.0)
321     run before starting: rm -f /bin/{true,pwd}
322     append to ./configure flags: --disable-nls
323     
324 - MAKEDEV (tested with 1.5)
326 - ncurses (tested with 5.2)
327     run before starting: 
328         patch -Np1 < ../uclibc-lfs-patches/ncurses-5.2-uClibc.patch
330       -> Solve a obscure problem (probably caused by faultly is* (ctype)
331          in uClibc)
332     append before ./configure: CXX="g++ -D_ISOC99_SOURCE"
333       -> This will declare vsscanf in stdio.h which is normaly not with uClibc 
334          headers.
336 - bash (tested with 2.05a)
337     run before starting: ln -s ../static/bin/cat /bin
338        -> Bash will use /bin/cat for some operations and since we still didn't 
339           install textutils, this symbolic link will be needed.
340           
341 - zlib (tested with 1.1.4)
342     Only recents LFS book (CVS only at this momment) gives zlib installation 
343     commands. Because of this, we also include them here:
345     ./configure --prefix=/usr &&
346     make libz.a &&
347     cp libz.a /usr/lib &&
348     chmod -x /usr/lib/libz.a &&
349     ./configure --shared --prefix=/usr --libdir=/lib &&
350     make clean all &&
351     make install &&
352     rm -f /lib/libz.so &&
353     ln -sf ../../lib/libz.so.1 /usr/lib/libz.so &&
354     cp zlib.3 /usr/share/man/man3
356     Commands explanations:
357         zlib build only either a the static or shared copy of itself. Since it
358         is often preferred to get both, we do so by building it twice.
360         [...] --libdir=/lib
361           -> Since a few programs that use zlib will be installed in /sbin
362              we install libz in /lib rather than /usr/lib so that it'll
363              always be available for them even if /usr is not mounted.
365         make clean all
366           -> code build from the first build could be re-used but cleaning
367              let zlib be build with preferred compiler flags for shared
368              libraries (-fPIC) rather than those chosen for the static one.
370         rm -f /lib/libz.so &&
371         ln -sf ../../lib/libz.so.1 /usr/bin/libz.so
372           -> libz.so is not needed in /lib, while it is in /usr/lib, this is
373              only used as information for the linker to help it find the
374              library. (No programs will directly be linked against libz.so,
375              they will use /lib/libz.so.1)
377 - ViM (tested with 6.1)
378     Note: --disable-nls shouldn't be needed (auto-detected)
380 - findutils (tested with 4.1)
382 - gawk (tested with 3.1.1)
383     append to ./configure flags: --disable-nls    
385 - bison (tested with 1.35)
386     append to ./configure flags: --disable-nls
388 - less (tested with 374)
390 - groff (tested with 1.17.2)
392 - textutils (tested with 2.1)
393     run: rm -f /bin/cat
394       -> We made that symbolic link when building bash, we only remove it 
395          because recent LFS books expect /bin/cat to be inexistent.
396     append to ./configure flags: --disable-nls
398 - sed (tested with 3.02)
400 - flex (tested with 2.5.4a)
402 - binutils (tested with 2.13)
403     append to ./configure flags: --disable-nls
405 - gettext
406     Skip this package for now because it'll make some packages think we want 
407     NLS support. (Will save us work if they don't) - If you need gettext for 
408     other reasons  (such as running 'aclocal' in a source that support gettext 
409     and without problems) Do it at the end of this hint, you'll also find
410     instructions there.
412 - net-tools (tested with 1.60)
413     Two protocols (enabled by default) won't compile because of missing 
414     includes/functions missing in uClibc.
415     These are, AX25 and NET/ROM (Packet Radio) which are unused and safe to 
416     disable for 'most' people.
418     If you configure net-tools 'without' using 'yes "" | make', just say 'n' 
419     each time it mention them (AX25 and NET/ROM) and install it normally. 
420     Otherwise, use these commands instead of those in the LFS book:
422         yes "" | make config &&
423         mv config.h config.h~ &&
424         sed -e /AX25/s/1/0/ -e /NETROM/s/1/0/ < config.h~ > config.h &&
425         make &&
426         make update
428 - m4 (tested with 1.4)
429     run before starting: patch -Np1 < ../uclibc-lfs-patches/m4-1.4-uClibc.patch
430       -> m4 needs some functions missing in uClibc, this patch provides them.
431     append in front of ./configure:
432         CPPFLAGS='-D__FORCE_NOGLIBC -D_ISOC99_SOURCE'
434       -> -D__FORCE_NOGLIBC tells configure/m4 we don't have glibc so that it'll
435          define its own obstack functions which aren't avaible in uClibc. 
436          -D_ISOC99_SOURCE is needed to properly compiles our added functions 
437          from the patch.
439 - texinfo (tested with 4.2)
440     append to ./configure flags: --disable-nls
442 - autoconf (tested with 2.53)
444 - automake (tested with 1.6.2)
446 - file (tested with 3.39)
447     run before starting:
448         patch -Np1 < ../uclibc-lfs-patches/file-3.39-uClibc.patch
450       -> Solve a obscure problem (probably caused by faultly is* (ctype)
451          in uClibc)
453 - libtool (tested with 1.4.2)
455 - bin86 (tested with 0.16.3)
457 - bzip2 (tested with 1.0.2)
459 - ed (tested with 0.2)
461 - kbd (tested with 1.06)
463 - diffutils (tested with 2.8.1)
464     append to ./configure flags: --disable-nls
466 - e2fsprogs (tested with 1.27)
467     Note: --disable-nls shouldn't be needed (auto-detected)
469 - grep (tested with 2.5)
470     append to ./configure flags: --disable-nls
472 - gzip (tested with 1.2.4a)
474 - man (tested with 1.5k)
475     append to make flags: CFLAGS='-DNONLS'
476       -> Remove native language support which fix compilation.
477          Note: CFLAGS is a empty var for man's makefiles, setting it will not 
478                remove any C compiler flags it already use.
480 - lilo (tested with 22.2)
482 - make 3.79.1
483     append to ./configure flags: --disable-nls
485 - modutils
486     Skip this package, it will compile but will segfault on many operations 
487     making it unusable. Either use a modules-less kernel or get a static 
488     modutils (until the problem is solved). This was explained earlier in 
489     section 2.
491 - netkit-base (tested with 0.17)
493 - patch (tested with 2.5.4)
495 - procinfo (tested with 18)
497 - procps (tested with 2.0.7)
498     run before starting:
499          patch -Np1 < ../uclibc-lfs-patches/procps-2.0.7-uClibc.patch
501       -> This patch stop top.c from using an include + function not provided 
502          by uClibc related to locales in order to have it build properly. 
504 - psmisc (tested with 20.1)
505     Note: psmisc 20.2 and 21 has incomplete '--disable-nls' support and won't 
506           compile with uClibc without modifications. Since psmisc 20.1 programs
507           works properly and do not have NLS support at all, we will install 
508           it instead. (You can do so by using the same commands as in the LFS
509           book)
511 - reiserfsprogs (tested with 3.6.3)
512     Note: reiserfsprogs was removed from recent LFS books, yet since many 
513           are probably using it and that there is a problem compiling it with
514           uClibc, we includes it here with the fix. If you don't use reiserfs,
515           just skip this package.
517     run before starting:
518         patch -Np1 < ../uclibc-lfs-patches/reiserfsprogs-3.6.3-uClibc.patch
520       -> provide the (missing in uClibc) obstack functions and include 
521          needed by reiserfs.
523     Instructions to install reiserfsprogs should be avaible in the BLFS book
524     (http://beyond.linuxfromscratch.org). But since they arn't in the LFS book 
525     itself anymore, we also give them:
526         ./configure --prefix=/usr --exec-prefix= &&
527         make &&
528         make install
530 - shadow (tested with 4.0.3)
531     run before starting: 
532          patch -Np1 < ../uclibc-lfs-patches/shadow-4.0.3-uClibc.patch
534       -> Shadow tries to use the putgrent function missing in uClibc, this 
535          patch will provide it. It also try to use 'innetgr' a NIS related 
536          function which is not supported by uClibc at all so disable it.
537     append to ./configure flags: --disable-nls
539 - sysklogd (tested with 1.4.1)
541 - sysvinit (tested with 2.84)
543 - tar (tested with 1.13)
544     append to ./configure flags: --disable-nls
546 - util-linux (tested with 2.11o)
547     omit from the 'make' and 'make install' flags: HAVE_SLN=yes
548       -> The LFS book use this because glibc already provide a sln (static ln)
549          Since uClibc don't, we should get the util-linux one.
550          
551 - perl (tested with 5.6.1)
552     Note: perl will compile with uClibc but "make test" will fail on some
553           tests. Yet, there's a good chance you'll never need these features so
554           you shouldn't pay attention to it.
556 - gettext (tested with 0.11.5)
557     Note: You should only install this packages if you need it for other 
558           purposes than native language support. (like running aclocal in 
559           a source supporting gettext) If you install it, you should consider 
560           installing it under a different prefix than /usr (like /opt/gettext 
561           for instance)
562     append to ./configure flags: --disable-nls
564 - Chapter 7+ of the LFS book 
565     Can be completed without any modifications at the exception of the 
566     /etc/localtime symlink which should be ommited, it's over for the hint; yet
567     you might want to have a look at section 4 (F.A.Q) if not already done.
569 =======================
570 4. F.A.Q.
571 =======================
573 Q: This hint mention "keep chap 5 & 6 separated", "/static" style, and often
574    use some /static directory. What is that? How do I make one?
575 A: LFS 4.0 (currently only in CVS as this is written) will use a special
576    directory ($LFS/static) to install all the statically compiled utilities 
577    of chapter5. This is an implementation of the "keep_chap5_and_chap6_sep.txt"
578    hint. If you wish to do the same, see that hint or build a chapter5 
579    based on LFS CVS/4.0+ instructions. (Note: LFS CVS/4.0+ also use gcc 3.1+.
580    If you wish to keep using gcc 2.95.3-2, just use the instructions from the
581    LFS 3.3 book and replace the occurences of "/usr" by "/static" for chapter5)
583 Q: Do I really need to build a static perl?
584 A: For now yes, uClibc need it to run one perl script required for the 
585    build process. It should be easily rewritable using AWK however; if you 
586    wish to do so, you'll find the script at "extra/scripts/initfini.pl" inside
587    the uClibc source. Patches are welcome (and in this case, it should be sent 
588    to uClibc peoples directly)
590 Q: With many packages, I keep on seeing: "the 'setlocale' function supports 
591    only C|POSIX locales" - Is this bad?
592 A: No. uClibc could be compiled with locales support (i.e. support other 
593    locales than C/POSIX locales), but this is a "horrible hack" using parts 
594    from glibc. I strongly recommend you don't bother about this.
596 Q: Why is '--disable-nls' used for so many packages? Some packages compile just 
597    fine with native language support.
598 A: Even if it compile, the NLS won't be usable. It will just make the compiled 
599    binaries and files use a little more disk space/RAM for nothing.
601 Q: Will I be able to use XFree86?
602 A: You can, but this hint don't explain how. (Expect troubles)
604 Q: This hint told me how to make a normal LFS system with uClibc, but I was 
605    interested in uClibc to make a minimal system, which packages should I 
606    remove?
607 A: A "minimal system" is very relative on what you want the system to do.
608    The thing is that you can have a linux system work with only a kernel and 
609    one thing to do such as running a shell.
610      - Do you need it to be able to compile binaries? (development)
611      - Do you need to be able to login on it?
612      - Do you need documentation?
613      - Do you need a specific interpreted language?
614      - etc...
615    Hint: You should look at the busybox package (http://www.busybox.net/)
617 =======================
618   End of Hint
619 =======================