1 AUTHOR: Ted Bullock <tbullock at Canada.com>
5 LICENSE: GNU General Public License
7 SYNOPSIS: How to build LFS for different sub-architectures.
10 http://www.comlore.com/i386-pc-linux-gnu
13 Additive instructions on how to cross-build a LFS-system for different x86 sub-architectures.
16 The command-replacements are applicable for LFS 6.1+SVN20051009. Similar changes will probably work
17 fine on other versions of the book; however your mileage may vary since the resources to
18 build a Linux system are under constant revision and replacement. You should probably have
19 either completed a run through the book already or at least read the procedures before you
22 Note: There is a nicely formatted pdf and MS *.doc file available at the webpage listed above.
23 Please forgive my horrible web design aesthetics and meaningless babble on that webpage,
24 but the hint is available there so go take a peek!
29 This hint is originally written by Nicholas Dille <webmaster at rakshas.de>.
30 Later it was updated and maintained by Daniel Baumann.
31 Now maintenance is done by Theodore Bullock <tbullock at Canada.com>
35 The GNU Compiler Collection (GCC) can build binaries for multiple platforms.
37 It is not especially complicated to cross-compile between different sub-architectures, for
38 example, to build i386 binary executables on an i686 computer. On the other hand, to cross-
39 compile between totally different architectures, for example, building PowerPC binary
40 executables on an i386 machine, an entirely different tool-chain is required and is beyond the
43 Ideally, all packages should get their information about the target from autoconf configuration
44 parameters and compiler flags. Unfortunately this is not the reality. Some packages use
45 different flags and a few packages, (notably GCC and Glibc), need other trickery to fake their
46 auto-detection in place of flags.
48 Additionally, if you are trying to build LFS on a very old 386 then there is an extra trick to
49 completing the procedure.
51 This hint does not cover building LFS onto i286 or older machines as these processors lack
52 some critical functionality to handle modern memory management. For information on that
53 topic search the internet for embedded Linux solutions.
57 As with $LFS, we will use the variable $CHOST to specify the type of computer we are
58 compiling on. To cross-compile you have to replace $CHOST with a value matching for your
61 If your target machine is currently running a flavour of Linux then you can get the correct
62 value from your target computer with
66 If you have not already a running Linux system on the target machine, use the corresponding
67 value from this list instead:
71 Intel Pentium 1 and MMX: i586
72 Intel Pentium Pro, 2, 3, 4 and M: i686
73 AMD K5, K6-1, K6-2 and K6-3: i586
74 AMD Athlon 1, 2, 3, 4 and 5: i686
75 IDT WinChip-C6, WinChip2: i486
78 The rest of the hint assumes you have set $CHOST as an environment variable, for example
80 # export CHOST="i386-pc-linux-gnu"
82 1.3. About $CFLAGS and $CXXFLAGS
84 $CFLAGS and $CXXFLAGS are environment variable that pass user flags to GCC and G++
85 respectively. Often, they are used to set the optimization level (-On, where n is an integer).
86 For details about optimization, please refer to the optimization hint. Here, we force GCC to
87 compile for the desired sub-architecture using -march.
89 Choose from this list:
93 Intel Pentium 1: pentium
94 Intel Pentium MMX: pentium-mmx
95 Intel Pentium Pro: pentiumpro
96 Intel Pentium 2: pentium2
97 Intel Pentium 3: pentium3
98 Intel Pentium 4 and M: pentium4
104 AMD Athlon 1 (Classic): athlon
105 AMD Athlon 2 (Thunderbird): athlon-tbird
106 AMD Athlon 3 (XP): athlon-xp
107 AMD Athlon 4 (Palomino): athlon-4
108 AMD Athlon 5 (MP): athlon-mp
110 IDT WinChip-C6: winchip-c6
111 IDT WinChip-2: winchip2
114 The rest of the hint assumes you have set $CFLAGS and $CXXFLAGS as environment
115 variables, for example:
117 export CFLAGS="-march=i386"
118 export CXXFLAGS="-march=i386"
120 1.3.1. ATTENTION REGARDING OPTIMIZATION
122 If you use optimization, in the majority of cases the binaries can only be used on the target
123 machine. This means, sharing self-generated binary-packages between different hosts is not
128 The following sections are ordered as a skeleton of the information in the LFS book
129 2.1. Chapter 4: Final Preparations
134 export CHOST="<value>"
135 export CFLAGS="<value>"
136 export CXXFLAGS="<value>"
138 Note: Please replace <value> with the proper strings as was discussed earlier
142 2.2. Chapter 5: Constructing a Temporary System
144 2.2.1. Binutils-2.16.1
148 ../binutils-2.16.1/configure --prefix=/tools --disable-nls
151 ../binutils-2.16.1/configure --host="$CHOST" --target="$CHOST" \
152 --prefix=/tools --disable-nls
154 2.2.2. GCC-4.0.2 - Pass 1
157 ../gcc-4.0.2/configure --prefix=/tools \
158 --libexecdir=/tools/lib --with-local-prefix=/tools \
159 --disable-nls --enable-shared --enable-languages=c
162 ../gcc-4.0.2/configure --host="$CHOST" --target="$CHOST" \
163 --prefix=/tools --libexecdir=/tools/lib \
164 --with-local-prefix=/tools --disable-nls \
165 --enable-shared --enable-languages=c
171 make BOOT_CFLAGS="$CFLAGS" bootstrap
173 2.2.3. Linux-Libc-Headers-2.6.12.0
175 No changes - we are just copying the header files here.
179 Ok, this one is a bit trickier and what you put here can have some important ramifications
180 later. If your target machine is a 486 or higher you should follow the (>=486) instructions
181 otherwise you should follow the (386) instructions. The reason for this is that the basic 386
182 instruction set is missing one of the atomic instructions important to multi-threading with the
183 NPTL threading system. Instead you will use the linuxthreads library which does not require
188 ../glibc-2.3.5/configure --prefix=/tools \
189 --disable-profile --enable-add-ons \
190 --enable-kernel=2.6.0 --with-binutils=/tools/bin \
191 --without-gd --with-headers=/tools/include \
195 ../glibc-2.3.5/configure --host="$CHOST" --target="$CHOST" \
196 --prefix=/tools --disable-profile --enable-kernel=2.6.0 \
197 --with-binutils=/tools/bin --without-gd \
198 --with-headers=/tools/include --without-selinux
201 ../glibc-2.3.5/configure --host="$CHOST" --target="$CHOST" \
202 --prefix=/tools --disable-profile --enable-add-ons=linuxthreads \
203 --with-tls --without-__thread --enable-kernel=2.6.0 \
204 --with-binutils=/tools/bin --without-gd \
205 --with-headers=/tools/include --without-selinux
207 Since glibc needs to be compiled with some level of optimization we need to add an
208 optimization flag to $CFLAGS. Please change this to suit your needs.
215 make CFLAGS="$CFLAGS -O2"
221 make CFLAGS="$CFLAGS -O2" cross-compiling=no install
223 2.2.5. Adjusting the tool-chain
225 No changes - we are using preconfigured code.
230 ./configure --prefix=/tools
233 ./configure --host="$CHOST" --target="$CHOST" --prefix=/tools
238 ./configure --prefix=/tools --with-tcl=/tools/lib --with-x=no \
239 --with-tclinclude=$TCLPATH
242 ./configure --host="$CHOST" --target="$CHOST" \
243 --prefix=/tools --with-tcl=/tools/lib --with-x=no \
244 --with-tclinclude=$TCLPATH
248 No need to do anything, just installing a script.
250 2.2.9. GCC-4.0.2- Pass 2
253 ../gcc-4.0.2/configure --prefix=/tools \
254 --libexecdir=/tools/lib --with-local-prefix=/tools \
255 --enable-clocale=gnu --enable-shared \
256 --enable-threads=posix --enable-__cxa_atexit \
257 --enable-languages=c,c++ --disable-libstdcxx-pch
260 ../gcc-4.0.2/configure --host="$CHOST" --target="$CHOST" \
261 --prefix=/tools --libexecdir=/tools/lib \
262 --with-local-prefix=/tools --enable-clocale=gnu \
263 --enable-shared --enable-threads=posix \
264 --enable-__cxa_atexit --enable-languages=c,c++ \
265 --disable-libstdcxx-pch
271 make BOOT_CFLAGS="$CFLAGS" BOOT_CXXFLAGS="$CXXFLAGS"
273 2.2.10. Binutils-2.16.1 - Pass 2
276 ../binutils-2.16.1/configure --prefix=/tools \
277 --enable-shared --with-lib-path=/tools/lib \
281 ../binutils-2.16.1/configure --host="$CHOST" --target="$CHOST" \
282 --prefix=/tools --enable-shared --with-lib-path=/tools/lib \
288 ./configure --prefix=/tools
291 ./configure --host="$CHOST" --target="$CHOST" --prefix=/tools
293 2.2.12. Coreutils-5.2.1
296 DEFAULT_POSIX2_VERSION=199209 ./configure --prefix=/tools
299 DEFAULT_POSIX2_VERSION=199209 ./configure \
300 --host="$CHOST" --target="$CHOST" --prefix=/tools
305 cp Makefile Makefile.backup &&
306 sed -e 's%$(BIGFILES)%$(BIGFILES) $(OPT)%' \
307 Makefile.backup > Makefile &&
308 cp Makefile-libbz2_so Makefile-libbz2_so.backup &&
309 sed -e 's%$(BIGFILES)%$(BIGFILES) $(OPT)%' \
310 Makefile-libbz2_so.backup > Makefile-libbz2_so
316 make OPT="$CFLAGS" PREFIX=/tools
319 make PREFIX=/tools install
322 make OPT="$CFLAGS" PREFIX=/tools install
327 ./configure --prefix=/tools
330 ./configure --host="$CHOST" --target="$CHOST" --prefix=/tools
332 2.2.15. Diffutils-2.8.1
335 ./configure --prefix=/tools
338 ./configure --host="$CHOST" --target="$CHOST" --prefix=/tools
340 2.2.16. Findutils-4.2.25
343 ./configure --prefix=/tools
346 ./configure --host="$CHOST" --target="$CHOST" --prefix=/tools
351 ./configure --prefix=/tools
354 ./configure --host="$CHOST" --target="$CHOST" --prefix=/tools
359 ./configure --prefix=/tools --disable-perl-regex
362 ./configure --host="$CHOST" --target="$CHOST" --prefix=/tools \
363 --disable-perl-regexp
368 ./configure --prefix=/tools
371 ./configure --host="$CHOST" --target="$CHOST" --prefix=/tools
373 2.2.20. Gettext-0.14.5
376 ./configure --prefix=/tools --disable-libasprintf \
380 ./configure --host="$CHOST" --target="$CHOST" --prefix=/tools \
381 --disable-libasprintf --without-csharp
386 ./configure --prefix=/tools --with-shared \
387 --without-debug --without-ada --enable-overwrite
390 ./configure --host="$CHOST" --target="$CHOST" \
391 --prefix=/tools --with-shared \
392 --without-debug --without-ada --enable-overwrite
397 CPPFLAGS=-D_GNU_SOURCE ./configure --prefix=/tools
400 CPPFLAGS=-D_GNU_SOURCE ./configure \
401 --host="$CHOST" --target="$CHOST" --prefix=/tools
406 ./configure --prefix=/tools
409 ./configure --host="$CHOST" --target="$CHOST" --prefix=/tools
414 ./configure --prefix=/tools
417 ./configure --host="$CHOST" --target="$CHOST" --prefix=/tools
422 ./configure --prefix=/tools --without-bash-malloc
425 ./configure --host="$CHOST" --target="$CHOST" --prefix=/tools \
426 --without-bash-malloc
431 ./configure --prefix=/tools
434 ./configure --host="$CHOST" --target="$CHOST" --prefix=/tools
436 2.2.27. Util-linux-2.12r
442 ./configure --host="$CHOST" --target="$CHOST"
447 ./configure.gnu --prefix=/tools -Dstatic_ext='IO Fcntl POSIX'
451 -Dhost="$CHOST" -Dtarget="$CHOST" -Darchname="$CHOST" \
452 --prefix=/tools -Dstatic_ext='IO Fcntl POSIX'
455 2.3. Chapter 6: Installing Basic System Software
457 2.3.1. Entering the chroot environment
460 chroot "$LFS" /tools/bin/env -i \
461 HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
462 PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
463 /tools/bin/bash --login +h
466 export CHOST="i386-pc-linux-gnu" &&
467 export CFLAGS="-march=i386" &&
468 export CXXFLAGS="-march=i386"
470 Note: Please replace i386 with the proper strings according to the introduction.
472 2.3.2. Linux-Libc-Headers-2.6.12.0
474 No changes - we are just copying the header files here.
476 2.3.3. Man-pages-2.08
478 No changes - we are just copying the man-pages here.
482 Ok, this one is a bit trickier and what you put here can have some important ramifications
483 later. If your target machine is a 486 or higher you should follow the (>=486) instructions
484 otherwise you should follow the (386) instructions. The reason for this is that the basic 386
485 instruction set is missing one of the atomic instructions important to multi-threading with the
486 NPTL threading system. Instead you will use the linuxthreads library which does not require
491 ../glibc-2.3.5/configure --prefix=/usr \
492 --disable-profile --enable-add-ons \
493 --enable-kernel=2.6.0 --libexecdir=/usr/lib/glibc
496 ../glibc-2.3.5/configure --host="$CHOST" --target="$CHOST" \
497 --prefix=/usr --disable-profile --enable-add-ons=nptl \
498 --with-tls --with-__thread --enable-kernel=2.6.0 \
499 --libexecdir=/usr/lib/glibc
502 ../glibc-2.3.5/configure --host="$CHOST" --target="$CHOST" \
503 --prefix=/usr --disable-profile --enable-add-ons=linuxthreads \
504 --with-tls --without-__thread --enable-kernel=2.6.0 \
505 --libexecdir=/usr/lib/glibc
507 Since glibc needs to be compiled with optimization, we have to modify our $CFLAGS
508 environment variable. Change this to suite your own needs.
514 make CFLAGS="$CFLAGS -O2"
520 make CFLAGS="$CFLAGS -O2" cross-compiling=no install
522 Note: This does not affect cross compiling for sub-architectures (it prevents Glibc to look for a
523 cross compiler and uses the native one).
525 2.3.5. Re-adjusting the toolchain
527 No changes - we are using preconfigured code.
529 2.3.6. Binutils-2.16.1
533 ../binutils-2.16.1/configure --prefix=/usr --enable-shared
536 ../binutils-2.16.1/configure --host="$CHOST" --target="$CHOST" \
537 --prefix=/usr --enable-shared
542 ../gcc-4.0.2/configure --prefix=/usr \
543 --libexecdir=/usr/lib --enable-shared \
544 --enable-threads=posix --enable-__cxa_atexit \
545 --enable-clocale=gnu --enable-languages=c,c++
548 ../gcc-4.0.2/configure --host="$CHOST" --target="$CHOST" \
550 --libexecdir=/usr/lib --enable-shared \
551 --enable-threads=posix --enable-__cxa_atexit \
552 --enable-clocale=gnu --enable-languages=c,c++
558 make BOOT_CFLAGS="$CFLAGS" BOOT_CXXFLAGS="$CXXFLAGS"
560 2.3.8. Coreutils-5.2.1
563 DEFAULT_POSIX2_VERSION=199209 ./configure --prefix=/usr
566 DEFAULT_POSIX2_VERSION=199209 ./configure \
567 --host="$CHOST" --target="$CHOST" --prefix=/usr
571 No need to change anything!
575 ./configure --prefix=/usr --with-libc
578 ./configure --host="$CHOST" --target="$CHOST" \
579 --prefix=/usr --with-libc
581 2.3.11. Iana-Etc-2.00
583 No changes - we are just copying files.
585 2.3.12. Findutils-4.2.25
588 ./configure --prefix=/usr --libexecdir=/usr/lib/locate \
589 --localstatedir=/var/lib/locate
592 ./configure --host="$CHOST" --target="$CHOST" \
593 --prefix=/usr --libexecdir=/usr/lib/locate \
594 --localstatedir=/var/lib/locate
599 ./configure --prefix=/usr --libexecdir=/usr/lib
602 ./configure --host="$CHOST" --target="$CHOST" \
603 --prefix=/usr --libexecdir=/usr/lib
608 ./configure --prefix=/usr --with-shared --without-debug
611 ./configure --host="$CHOST" --target="$CHOST" \
612 --prefix=/usr --with-shared --without-debug
617 ./configure --prefix=/usr --libdir=/lib
620 ./configure --prefix=/usr --libdir=/lib --host="$CHOST" --target="$CHOST"
625 ./configure --prefix=/usr --enable-multibyte
629 ./configure --host="$CHOST" --target="$CHOST" \
630 --enable-multibyte --prefix=/usr
635 ./configure --prefix=/usr
638 ./configure --host="$CHOST" --target="$CHOST" --prefix=/usr
643 ./configure --prefix=/usr
646 ./configure --host="$CHOST" --target="$CHOST" --prefix=/usr
651 ./configure --prefix=/usr --bindir=/bin --sysconfdir=/etc
654 ./configure --host="$CHOST" --target="$CHOST" \
655 --prefix=/usr --bindir=/bin --sysconfdir=/etc
660 PAGE=letter ./configure --prefix=/usr
663 PAGE=letter ./configure --host="$CHOST" --target="$CHOST" \
669 ./configure --prefix=/usr --bindir=/bin
672 ./configure --host="$CHOST" --target="$CHOST" \
673 --prefix=/usr --bindir=/bin
678 ./configure --prefix=/usr
681 ./configure --host="$CHOST" --target="$CHOST" --prefix=/usr
683 2.3.23. Gettext-0.14.5
686 ./configure --prefix=/usr
689 ./configure --host="$CHOST" --target="$CHOST" --prefix=/usr
691 2.3.24. Inetutils-1.4.2
693 Assuming CFLAGS are set, don?t change anything.
694 2.3.25. IPRoute2-051007
700 mv Makefile Makefile.backup &&
701 sed 's/$(CCOPTS)/$(CCOPTS) $(OPT)/' Makefile.backup > Makefile
707 make SBINDIR=/sbin OPT="$CFLAGS"
712 ./configure.gnu --prefix=/usr -Dpager="/bin/less -isR"
715 ./configure.gnu --prefix=/usr -Dpager="/bin/less -isR" \
716 -Dhost="$CHOST" -Dtarget="$CHOST" -Darchname="$CHOST"
721 ./configure --prefix=/usr
724 ./configure --host="$CHOST" --target="$CHOST" --prefix=/usr
726 2.3.28. Autoconf-2.59
728 Uses Perl and M4 to do stuff so no need to do anything!
729 2.3.29. Automake-1.9.6
731 Uses Perl and M4 to do stuff so no need to do anything!
735 ./configure --prefix=/usr --bindir=/bin
738 ./configure --host="$CHOST" --target="$CHOST" \
739 --prefix=/usr --bindir=/bin --with-bash-malloc --with-installed-readline
744 ./configure --prefix=/usr
747 ./configure --host="$CHOST" --target="$CHOST" --prefix=/usr
749 2.3.32. Libtool-1.5.20
752 ./configure --prefix=/usr
755 ./configure --host="$CHOST" --target="$CHOST" --prefix=/usr
760 cp Makefile Makefile.backup
761 sed -e 's%$(BIGFILES)%$(BIGFILES) $(OPT)%' \
762 Makefile.backup > Makefile
763 cp Makefile-libbz2_so Makefile-libbz2_so.backup
764 sed -e 's%CFLAGS=-fpic%CFLAGS=$(OPT) -fpic%' \
765 Makefile-libbz2_so.backup > Makefile-libbz2_so
768 make -f Makefile-libbz2_so
771 make OPT="$CFLAGS" -f Makefile-libbz2_so
779 2.3.34. Diffutils-2.8.1
782 ./configure --prefix=/usr
785 ./configure --host="$CHOST" --target="$CHOST" --prefix=/usr
793 make CFLAGS="$CFLAGS"
795 2.3.36. E2fsprogs-1.38
798 ../e2fsprogs-1.35/configure --prefix=/usr --with-root-prefix="" \
799 --enable-elf-shlibs --disable-evms
802 ../e2fsprogs-1.35/configure --host="$CHOST" --target="$CHOST" \
803 --prefix=/usr --with-root-prefix="" \
804 --enable-elf-shlibs --disable-evms
809 ./configure --prefix=/usr --bindir=/bin \
810 --with-included-regex
813 ./configure --host="$CHOST" --target="$CHOST" \
814 --prefix=/usr --bindir=/bin
818 ./configure --prefix=/usr
821 ./configure --host="$CHOST" --target="$CHOST" --prefix=/usr
826 ./configure --prefix=/usr
829 ./configure --host="$CHOST" --target=$CHOST --prefix=/usr
834 cp man2html/Makefile.in man2html/Makefile.in.backup
835 sed -e "s/CFLAGS = /CFLAGS = $CFLAGS /" \
836 man2html/Makefile.in.backup > man2html/Makefile.in
841 ./configure --prefix=/usr
844 ./configure --host="$CHOST" --target="$CHOST" --prefix=/usr
846 2.3.42. Module-Init-Tools-3.1
849 ./configure --prefix="" --enable-zlib
852 ./configure --prefix="" --enable-zlib --host="$CHOST" --target="$CHOST"
857 CPPFLAGS=-D_GNU_SOURCE ./configure --prefix=/usr
860 CPPFLAGS=-D_GNU_SOURCE ./configure \
861 --host="$CHOST" --target="$CHOST" --prefix=/usr
869 make CFLAGS="$CFLAGS"
871 Note: The build process will fail if your $CFLAGS does not contain the -On switch. If that is
872 the case, please use the line
874 make CFLAGS="$CFLAGS -O2"
881 ./configure --prefix=/usr --exec-prefix=/
884 ./configure --host="$CHOST" --target="$CHOST" \
885 --prefix=/usr --exec-prefix=""
887 2.3.46. Shadow-4.0.12
890 ./configure --libdir=/usr/lib --enable-shared
893 ./configure --host="$CHOST" --target="$CHOST" \
894 --libdir=/usr/lib --enable-shared
896 2.3.47. Sysklogd-1.4.1
902 make RPM_OPT_FLAGS="$CFLAGS"
904 2.3.48. Sysvinit-2.86
910 make CFLAGS="-Wall -D_GNU_SOURCE $CFLAGS" -C src
915 ./configure --prefix=/usr --bindir=/bin --libexecdir=/usr/sbin
918 ./configure --host="$CHOST" --target="$CHOST" \
919 --prefix=/usr --bindir=/bin --libexecdir=/usr/sbin
923 No changes should be necessary assuming that the CFLAGS is set appropriately as discussed
924 in Section 1.3 About $CFLAGS and $CXXFLAGS
926 2.3.51. Util-linux-2.12r
932 ./configure --host="$CHOST" --target="$CHOST"
934 2.4. Chapter 7: Setting up System Bootscripts
936 2.4.1. LFS-Bootscripts-3.2.1
938 No changes - we are just copying the scripts here.
940 2.5. Chapter 8: Making the LFS system bootable
942 2.5.1. Linux-2.6.13.1
944 Select your processor under 'Processor family' in the 'Processor type and features' menu.
949 It may be a good idea to keep the compiler flags for future use
951 echo "export CFLAGS=\"$(echo $CFLAGS)\"" >> /etc/profile
952 echo "export CXXFLAGS=\"$(echo $CXXFLAGS)\"" >> /etc/profile
955 * Daniel Baumann <daniel.baumann at panthera-systems.net> for updating and
956 maintaining the hint to LFS 5.1.1
957 * Nicholas Dille <webmaster at rakshas.de> for the original hint
958 * Tommy Wareing for the uname hack
959 * Christophe Devine <devine at cr0.net> for the uname kernel-module
960 * Yann Guidon <whygee at f-cpu.org> for extending the uname kernel-module
967 * Updated hint to SVN-20051009 (LFS-6.1+)
968 * Fixed multiple typographic errors
970 * Fixed typographic mistakes
973 * Added 386 specific commands to glibc
974 * Fixed typographic mistakes and extended some explanation
976 * Updated to LFS-5.1.1
977 * Glibc-command revised (Thanks to Kevin White <kwhite at kevbo.org>
978 * Typographic mistakes corrected
980 * Typographic mistakes corrected
982 * Updated to LFS 5.1.
983 * Minor text changes.
985 * Updated to LFS 5.0.
987 * Major text changes.