此处在宿主机以lfs用户运行,将软件安装在LFS目录下
本部分属于原书第六章内容
第二次编译耗时6h,以下需要安装16个包,GCC需要安装两次
以下的工具编译到目标位置,但是不能使用,需要在chroot环境下链接使用
1)安装M4
M4 软件包包含一个宏处理器
tar xvf m4-1.4.19.tar.xz cd m4-1.4.19 ./configure --prefix=/usr \ --host=$LFS_TGT \ --build=$(build-aux/config.guess) make -j4 make DESTDIR=$LFS install cd .. rm -rf m4-1.4.19
2)安装Ncurses-6.2
Ncurses 软件包包含使用时不需考虑终端特性的字符屏幕处理函数库
tar xvf ncurses-6.2.tar.gz cd ncurses-6.2 sed -i s/mawk// configure 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-debug \ --without-ada \ --without-normal \ --enable-widec make -j4 make DESTDIR=$LFS TIC_PATH=$(pwd)/build/progs/tic install echo "INPUT(-lncursesw)" > $LFS/usr/lib/libncurses.so cd .. rm -rf ncurses-6.2
3)安装Bash
这个软件包为系统提供一个 LSB core 要求的 Bourne Shell 接口
tar xvf bash-5.1.8.tar.gz cd bash-5.1.8 ./configure --prefix=/usr \ --build=$(support/config.guess) \ --host=$LFS_TGT \ --without-bash-malloc make -j4 make DESTDIR=$LFS install ln -sv bash $LFS/bin/sh cd $LFS/sources rm -rf bash-5.1.8
4)安装Coreutils
这个软件包包含一些用于查看和操作文件和目录的基本程序
tar xvf coreutils-8.32.tar.xz cd coreutils-8.32 ./configure --prefix=/usr \ --host=$LFS_TGT \ --build=$(build-aux/config.guess) \ --enable-install-program=hostname \ --enable-no-install-program=kill,uptime make -j4 make DESTDIR=$LFS install 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-8.32
5)安装Diffutils
这个软件包包含用于显示文件或目录之间的差异的程序
tar xvf diffutils-3.8.tar.xz cd diffutils-3.8 ./configure --prefix=/usr --host=$LFS_TGT make -j4 make DESTDIR=$LFS install cd .. rm -rf diffutils-3.8
6)安装File
这个软件包包含用于判定给定文件类型的工具
tar xvf file-5.40.tar.gz cd file-5.40 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 cd .. rm -rf file-5.40
7)安装Findutils
这个软件包包含用于在文件系统中寻找文件的程序
tar xvf findutils-4.8.0.tar.xz cd findutils-4.8.0 ./configure --prefix=/usr \ --localstatedir=/var/lib/locate \ --host=$LFS_TGT \ --build=$(build-aux/config.guess) make -j4 make DESTDIR=$LFS install cd .. rm -rf findutils-4.8.0
8)安装Gawk
这个软件包包含用于操作文本文件的程序
tar xvf gawk-5.1.0.tar.xz cd gawk-5.1.0 sed -i 's/extras//' Makefile.in ./configure --prefix=/usr \ --host=$LFS_TGT \ --build=$(./config.guess) make -j4 make DESTDIR=$LFS install cd .. rm -rf gawk-5.1.0
9)安装grep
这个软件包包含在文本中搜索指定模式的程序
tar xvf grep-3.7.tar.xz cd grep-3.7 ./configure --prefix=/usr \ --host=$LFS_TGT make -j4 make DESTDIR=$LFS install cd .. rm -rf grep-3.7
10)安装Gzip
这个软件包包含用于压缩和解压缩文件的程序
tar xvf gzip-1.10.tar.xz cd gzip-1.10 ./configure --prefix=/usr --host=$LFS_TGT make -j4 make DESTDIR=$LFS install cd .. rm -rf gzip-1.10
11)安装Make
这个软件包包含用于指导软件包编译过程的程序
tar xvf make-4.3.tar.gz cd make-4.3 ./configure --prefix=/usr \ --without-guile \ --host=$LFS_TGT \ --build=$(build-aux/config.guess) make -j4 make DESTDIR=$LFS install cd .. rm -rf make-4.3
12)安装Patch
这个软件包包含一个通过 补丁 文件修改或创建文件的程序
tar xvf patch-2.7.6.tar.xz cd patch-2.7.6 ./configure --prefix=/usr \ --host=$LFS_TGT \ --build=$(build-aux/config.guess) make -j4 make DESTDIR=$LFS install cd .. rm -rf patch-2.7.6
13)安装Sed
这个软件包可以在没有文本编辑器的情况下编辑文本文件
tar xvf sed-4.8.tar.xz cd sed-4.8 ./configure --prefix=/usr \ --host=$LFS_TGT \ --build=$(build-aux/config.guess) make -j4 make DESTDIR=$LFS install cd .. rm -rf sed-4.8
14)安装Tar
这个软件包提供存档和提取功能
tar xvf tar-1.34.tar.xz cd tar-1.34 ./configure --prefix=/usr \ --host=$LFS_TGT \ --build=$(build-aux/config.guess) make -j4 make DESTDIR=$LFS install cd .. rm -rf tar-1.34
15)安装Xz
这个软件包包含用于压缩和解压缩文件的程序
tar xvf xz-5.2.5.tar.xz cd xz-5.2.5 ./configure --prefix=/usr \ --host=$LFS_TGT \ --build=$(build-aux/config.guess) \ --disable-static \ --docdir=/usr/share/doc/xz-5.2.5 make -j4 make DESTDIR=$LFS install cd .. rm -rf xz-5.2.5
16)再次安装Binutils
该软件包包含链接器、汇编器,以及其他处理目标文件的工具
tar xvf binutils-2.37.tar.xz cd binutils-2.37 mkdir -v build cd build ../configure \ --prefix=/usr \ --build=$(../config.guess) \ --host=$LFS_TGT \ --disable-nls \ --enable-shared \ --disable-werror \ --enable-64-bit-bfd make -j4 make DESTDIR=$LFS install -j1 install -vm755 libctf/.libs/libctf.so.0.0.0 $LFS/usr/lib cd .. cd .. rm -rf binutils-2.37
17)再次安装GCC
这个软件包是 GNU 编译器的集合
tar xvf gcc-11.2.0.tar.xz cd gcc-11.2.0 tar -xf ../mpfr-4.1.0.tar.xz mv -v mpfr-4.1.0 mpfr tar -xf ../gmp-6.2.1.tar.xz mv -v gmp-6.2.1 gmp tar -xf ../mpc-1.2.1.tar.gz mv -v mpc-1.2.1 mpc case $(uname -m) in x86_64) sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64 ;; esac mkdir -v build cd build mkdir -pv $LFS_TGT/libgcc ln -s ../../../libgcc/gthr-posix.h $LFS_TGT/libgcc/gthr-default.h ../configure \ --build=$(../config.guess) \ --host=$LFS_TGT \ --prefix=/usr \ CC_FOR_TARGET=$LFS_TGT-gcc \ --with-build-sysroot=$LFS \ --enable-initfini-array \ --disable-nls \ --disable-multilib \ --disable-decimal-float \ --disable-libatomic \ --disable-libgomp \ --disable-libquadmath \ --disable-libssp \ --disable-libvtv \ --disable-libstdcxx \ --enable-languages=c,c++ make -j4 make DESTDIR=$LFS install ln -sv gcc $LFS/usr/bin/cc cd .. cd .. rm -rf gcc-11.2.0
此处需要检查所有的工具链,避免安装不完整。
参考资料:
- https://bf.mengyan1223.wang/lfs/zh_CN/11.0/chapter06/introduction.html
- https://www.linuxfromscratch.org/lfs/view/stable-systemd/chapter06/introduction.html