Part 5: Cross-Compiling Temporary Tools
Overview
Now that you have a cross-compiler, you'll build temporary tools needed for the final system. These are cross-compiled using the toolchain from Part 4.
Prerequisites
- Completed Part 4 (cross-toolchain)
- Still logged in as
lfsuser - Working directory:
$LFS/sources
Packages to Build (Chapter 6)
19 essential utilities that will be rebuilt later in the final system:
- M4-1.4.20
- Ncurses-6.5
- Bash-5.3
- Coreutils-9.7
- Diffutils-3.12
- File-5.46
- Findutils-4.10.0
- Gawk-5.3.2
- Grep-3.12
- Gzip-1.14
- Make-4.4.1
- Patch-2.8
- Sed-4.9
- Tar-1.35
- Xz-5.8.1
- Binutils-2.45 (Pass 2)
- GCC-15.2.0 (Pass 2)
Standard Build Pattern
Most packages follow this pattern:
cd $LFS/sources
tar -xf <package>.tar.xz
cd <package>
# Configure
./configure --prefix=/usr \
--host=$LFS_TGT \
--build=$(./config.guess)
# Build
make
# Install
make DESTDIR=$LFS install
# Cleanup
cd $LFS/sources
rm -rf <package>
1. M4-1.4.20
Purpose: Macro processor (needed for Bison)
cd $LFS/sources
tar -xf m4-1.4.20.tar.xz
cd m4-1.4.20
./configure --prefix=/usr \
--host=$LFS_TGT \
--build=$(build-aux/config.guess)
make
make DESTDIR=$LFS install
cd $LFS/sources
rm -rf m4-1.4.20
2. Ncurses-6.5
Purpose: Terminal handling library
cd $LFS/sources
tar -xf ncurses-6.5-20250809.tgz
cd ncurses-6.5-20250809
# Ensure gawk is found first
sed -i s/mawk// configure
# Build tic program
mkdir build
pushd build
../configure
make -C include
make -C progs tic
popd
./configure --prefix=/usr \
--host=$LFS_TGT \
--build=$(./config.guess) \
--mandir=/usr/share/man \
--with-manpage-format=normal \
--with-shared \
--without-normal \
--with-cxx-shared \
--without-debug \
--without-ada \
--disable-stripping
make
make DESTDIR=$LFS TIC_PATH=$(pwd)/build/progs/tic install
ln -sv libncursesw.so $LFS/usr/lib/libncurses.so
sed -e 's/^#if.*XOPEN.*$/#if 1/' \
-i $LFS/usr/include/curses.h
cd $LFS/sources
rm -rf ncurses-6.5-20250809
3. Bash-5.3
Purpose: Bourne-Again SHell
cd $LFS/sources
tar -xf bash-5.3.tar.gz
cd bash-5.3
./configure --prefix=/usr \
--build=$(sh support/config.guess) \
--host=$LFS_TGT \
--without-bash-malloc \
bash_cv_strtold_broken=no
make
make DESTDIR=$LFS install
# Create sh symlink
ln -sv bash $LFS/bin/sh
cd $LFS/sources
rm -rf bash-5.3
4. Coreutils-9.7
Purpose: Core utilities (ls, cp, mv, etc.)
cd $LFS/sources
tar -xf coreutils-9.7.tar.xz
cd coreutils-9.7
./configure --prefix=/usr \
--host=$LFS_TGT \
--build=$(build-aux/config.guess) \
--enable-install-program=hostname \
--enable-no-install-program=kill,uptime
make
make DESTDIR=$LFS install
# Move programs to correct location
mv -v $LFS/usr/bin/chroot $LFS/usr/sbin
mkdir -pv $LFS/usr/share/man/man8
mv -v $LFS/usr/share/man/man1/chroot.1 $LFS/usr/share/man/man8/chroot.8
sed -i 's/"1"/"8"/' $LFS/usr/share/man/man8/chroot.8
cd $LFS/sources
rm -rf coreutils-9.7
5. Diffutils-3.12
Purpose: File comparison utilities
cd $LFS/sources
tar -xf diffutils-3.12.tar.xz
cd diffutils-3.12
./configure --prefix=/usr \
--host=$LFS_TGT \
--build=$(./build-aux/config.guess)
make
make DESTDIR=$LFS install
cd $LFS/sources
rm -rf diffutils-3.12
6. File-5.46
Purpose: File type identification
cd $LFS/sources
tar -xf file-5.46.tar.gz
cd file-5.46
# Build on host for cross-compile
mkdir build
pushd build
../configure --disable-bzlib \
--disable-libseccomp \
--disable-xzlib \
--disable-zlib
make
popd
./configure --prefix=/usr --host=$LFS_TGT --build=$(./config.guess)
make FILE_COMPILE=$(pwd)/build/src/file
make DESTDIR=$LFS install
# Remove libtool archive
rm -v $LFS/usr/lib/libmagic.la
cd $LFS/sources
rm -rf file-5.46
7. Findutils-4.10.0
Purpose: File search utilities
cd $LFS/sources
tar -xf findutils-4.10.0.tar.xz
cd findutils-4.10.0
./configure --prefix=/usr \
--localstatedir=/var/lib/locate \
--host=$LFS_TGT \
--build=$(build-aux/config.guess)
make
make DESTDIR=$LFS install
cd $LFS/sources
rm -rf findutils-4.10.0
8. Gawk-5.3.2
Purpose: GNU AWK text processing
cd $LFS/sources
tar -xf gawk-5.3.2.tar.xz
cd gawk-5.3.2
# Ensure build doesn't look for installed gawk
sed -i 's/extras//' Makefile.in
./configure --prefix=/usr \
--host=$LFS_TGT \
--build=$(build-aux/config.guess)
make
make DESTDIR=$LFS install
cd $LFS/sources
rm -rf gawk-5.3.2
9. Grep-3.12
Purpose: Pattern matching utility
cd $LFS/sources
tar -xf grep-3.12.tar.xz
cd grep-3.12
./configure --prefix=/usr \
--host=$LFS_TGT \
--build=$(./build-aux/config.guess)
make
make DESTDIR=$LFS install
cd $LFS/sources
rm -rf grep-3.12
10. Gzip-1.14
Purpose: File compression
cd $LFS/sources
tar -xf gzip-1.14.tar.xz
cd gzip-1.14
./configure --prefix=/usr --host=$LFS_TGT
make
make DESTDIR=$LFS install
cd $LFS/sources
rm -rf gzip-1.14
11. Make-4.4.1
Purpose: Build automation
cd $LFS/sources
tar -xf make-4.4.1.tar.gz
cd make-4.4.1
./configure --prefix=/usr \
--without-guile \
--host=$LFS_TGT \
--build=$(build-aux/config.guess)
make
make DESTDIR=$LFS install
cd $LFS/sources
rm -rf make-4.4.1
12. Patch-2.8
Purpose: Apply diff patches
cd $LFS/sources
tar -xf patch-2.8.tar.xz
cd patch-2.8
./configure --prefix=/usr \
--host=$LFS_TGT \
--build=$(build-aux/config.guess)
make
make DESTDIR=$LFS install
cd $LFS/sources
rm -rf patch-2.8
13. Sed-4.9
Purpose: Stream editor
cd $LFS/sources
tar -xf sed-4.9.tar.xz
cd sed-4.9
./configure --prefix=/usr \
--host=$LFS_TGT \
--build=$(./build-aux/config.guess)
make
make DESTDIR=$LFS install
cd $LFS/sources
rm -rf sed-4.9
14. Tar-1.35
Purpose: Archive utility
cd $LFS/sources
tar -xf tar-1.35.tar.xz
cd tar-1.35
./configure --prefix=/usr \
--host=$LFS_TGT \
--build=$(build-aux/config.guess)
make
make DESTDIR=$LFS install
cd $LFS/sources
rm -rf tar-1.35
15. Xz-5.8.1
Purpose: XZ compression
cd $LFS/sources
tar -xf xz-5.8.1.tar.xz
cd xz-5.8.1
./configure --prefix=/usr \
--host=$LFS_TGT \
--build=$(build-aux/config.guess) \
--disable-static \
--docdir=/usr/share/doc/xz-5.8.1
make
make DESTDIR=$LFS install
# Remove libtool archives
rm -v $LFS/usr/lib/liblzma.la
cd $LFS/sources
rm -rf xz-5.8.1
16. Binutils-2.45 - Pass 2
Purpose: Final cross-compile of binutils
cd $LFS/sources
tar -xf binutils-2.45.tar.xz
cd binutils-2.45
# Apply sed for library path
sed '6009s/$add_dir//' -i ltmain.sh
mkdir -v build
cd build
../configure \
--prefix=/usr \
--build=$(../config.guess) \
--host=$LFS_TGT \
--disable-nls \
--enable-shared \
--enable-gprofng=no \
--disable-werror \
--enable-64-bit-bfd \
--enable-new-dtags \
--enable-default-hash-style=gnu
make
make DESTDIR=$LFS install
# Remove libtool archives
rm -v $LFS/usr/lib/lib{bfd,ctf,ctf-nobfd,opcodes,sframe}.la
cd $LFS/sources
rm -rf binutils-2.45
17. GCC-15.2.0 - Pass 2
Purpose: Final cross-compiler
Build Time: ~11 SBU Disk Space: ~4.9 GB
cd $LFS/sources
tar -xf gcc-15.2.0.tar.xz
cd gcc-15.2.0
# Extract prerequisites
tar -xf ../mpfr-4.2.2.tar.xz
mv -v mpfr-4.2.2 mpfr
tar -xf ../gmp-6.3.0.tar.xz
mv -v gmp-6.3.0 gmp
tar -xf ../mpc-1.3.1.tar.gz
mv -v mpc-1.3.1 mpc
# Fix library path for x86_64
case $(uname -m) in
x86_64)
sed -e '/m64=/s/lib64/lib/' \
-i.orig gcc/config/i386/t-linux64
;;
esac
# Fix directory structure
sed '/thread_header =/s/@.*@/gthr-posix.h/' \
-i libgcc/Makefile.in libstdc++-v3/include/Makefile.in
mkdir -v build
cd build
../configure \
--build=$(../config.guess) \
--host=$LFS_TGT \
--target=$LFS_TGT \
LDFLAGS_FOR_TARGET=-L$PWD/$LFS_TGT/libgcc \
--prefix=/usr \
--with-build-sysroot=$LFS \
--enable-default-pie \
--enable-default-ssp \
--disable-nls \
--disable-multilib \
--disable-libatomic \
--disable-libgomp \
--disable-libquadmath \
--disable-libsanitizer \
--disable-libssp \
--disable-libvtv \
--enable-languages=c,c++
make
make DESTDIR=$LFS install
# Create utility symlink
ln -sv gcc $LFS/usr/bin/cc
cd $LFS/sources
rm -rf gcc-15.2.0
Verification
Test the toolchain:
# Create test program
echo 'int main(){}' | $LFS_TGT-gcc -xc -
readelf -l a.out | grep ld-linux
# Should show:
# [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
rm a.out
Next Steps
Temporary tools complete! Proceed to:
- Part 6: Enter chroot and build additional tools
- Part 7: Build final system in chroot
Important Notes
- Build packages in the order listed
- Don't skip any packages
- Clean up after each build to save space
- Total build time: ~15-20 SBUs