08.构建临时编译环境(五)
时间:2006-11-17 来源:anima
八、构建临时编译环境(五)
11.GCC-4.0.3 – 第二遍
GCC 软件包包含 GNU 编译器集合,其中有C和C++编译器。
预计编译时间: 4.2 SBU
所需磁盘空间: 443 MB
重新安装GCC
测试 GCC 和 Binutils 所需的工具(Tcl, Expect, DejaGNU)已经安装好。现在 GCC 和 Binutils 将被重新编译,连接到新的 Glibc 并作适当测试(如果运行这章中的测试的话)。注意,这些测试套件受伪终端(PTY)的影响很大,这些伪终端通常是由宿主系统通过 devpts 文件系统实现的。你可以用下面的方法,来测试宿主系统中PTY是否设置正常:
lfs:/mnt/lfs/sources/dejagnu-1.4.4$ expect -c "spawn ls"
spawn ls
lfs:/mnt/lfs/sources/dejagnu-1.4.4$
如果你得到下面的回答:
The system has no more ptys.
Ask your system administrator to create more.
说明主系统的 PTY 没设置好。这种情况下,运行 GCC 和 Binutils 的测试套件就没什么意义了。你需要先解决主系统中的 PTY 设置问题。具体请参见 LFS 的 FAQ :http://www.linuxfromscratch.org/lfs/faq.html#no-ptys 。
在之前的“调整工具链”中提到过在 GCC 编译过程中会运行 fixincludes 脚本来扫描系统头文件目录,并找出需要修正的头文件,然后把修正后的头文件放到 GCC 专属头文件目录里。因为现在 GCC 和 Glibc 已经安装完毕,而且它们的头文件已知无需修正,所以这里并不需要 fixincludes 脚本。另外,由于 GCC 专属头文件目录会被优先搜索,结果就是 GCC 使用的头文件是宿主系统的头文件,而不是新安装的那个,从而导致编译环境被"污染"。因此必须通过下面的命令来禁止 fixincludes 脚本运行:
cp -v gcc/Makefile.in{,.orig} &&
sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in
lfs:/mnt/lfs/sources/dejagnu-1.4.4$ mkdir -v $LFS/sources/old
mkdir: created directory `/mnt/lfs/sources/old'
lfs:/mnt/lfs/sources/dejagnu-1.4.4$ mv $LFS/sources/gcc-4.0.3 $LFS/sources/old
lfs:/mnt/lfs/sources/dejagnu-1.4.4$ mv $LFS/sources/gcc-build $LFS/sources/old
lfs:/mnt/lfs/sources/dejagnu-1.4.4$ tar -jxvf $LFS/sources/gcc-4.0.3.tar.bz2 -C $LFS/sources
lfs:/mnt/lfs/sources/dejagnu-1.4.4$ cd $LFS/sources/gcc-4.0.3
lfs:/mnt/lfs/sources/gcc-4.0.3$ cp -v gcc/Makefile.in{,.orig} &&
> sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in
`gcc/Makefile.in' -> `gcc/Makefile.in.orig'
lfs:/mnt/lfs/sources/gcc-4.0.3$
在“GCC-4.0.3 - 第一遍”中进行的 bootstrap 编译使用了 -fomit-frame-pointer 选项,而非 bootstrap 编译则默认忽略了该选项,所以需要使用下面的 sed 命令来确保在非 bootstrap 编译时也同样使用 -fomit-frame-pointer 选项,以保持一致性:
cp -v gcc/Makefile.in{,.tmp} &&
sed 's/^XCFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in.tmp \
> gcc/Makefile.in
lfs:/mnt/lfs/sources/gcc-4.0.3$ cp -v gcc/Makefile.in{,.tmp} &&
> sed 's/^XCFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in.tmp \
> > gcc/Makefile.in
`gcc/Makefile.in' -> `gcc/Makefile.in.tmp'
lfs:/mnt/lfs/sources/gcc-4.0.3$
使用下面的补丁修改 GCC 的缺省动态连接器(通常是 ld-linux.so.2)的位置:
lfs:/mnt/lfs/sources/gcc-4.0.3$ patch -Np1 -i ../gcc-4.0.3-specs-1.patch
patching file gcc/config/alpha/linux-elf.h
patching file gcc/config/arm/linux-elf.h
Hunk #1 succeeded at 88 (offset 1 line).
patching file gcc/config/frv/linux.h
patching file gcc/config/i386/gnu.h
patching file gcc/config/i386/linux.h
patching file gcc/config/i386/linux64.h
patching file gcc/config/ia64/linux.h
patching file gcc/config/linux.h
patching file gcc/config/m32r/linux.h
patching file gcc/config/m68k/linux.h
patching file gcc/config/mips/linux.h
patching file gcc/config/mips/linux64.h
Hunk #1 succeeded at 47 (offset -13 lines).
patching file gcc/config/mn10300/linux.h
Hunk #1 succeeded at 37 with fuzz 1.
patching file gcc/config/pa/pa-linux.h
patching file gcc/config/rs6000/linux64.h
Hunk #1 succeeded at 355 (offset 4 lines).
patching file gcc/config/rs6000/sysv4.h
Hunk #1 succeeded at 1125 (offset -6 lines).
patching file gcc/config/s390/linux.h
patching file gcc/config/sh/linux.h
Hunk #1 succeeded at 71 (offset 1 line).
patching file gcc/config/sparc/linux.h
patching file gcc/config/sparc/linux64.h
patching file gcc/config/xtensa/linux.h
lfs:/mnt/lfs/sources/gcc-4.0.3$
上述补丁还把 /usr/include 从 GCC 的头文件搜索路径里删掉。现在预先打补丁而不是在安装 GCC 之后调整 specs 文件可以保证新的动态连接器在编译 GCC 的时候就用上。也就是说,随后的所有临时程序都会连接到新的 Glibc 上。
重要
上述补丁非常重要,为了成功编译,千万别忘了使用它们。
再次为编译创建一个单独目录:
lfs:/mnt/lfs/sources/gcc-4.0.3$ mkdir -v ../gcc-build
mkdir: created directory `../gcc-build'
lfs:/mnt/lfs/sources/gcc-4.0.3$ cd ../gcc-build
在开始编译前,别忘了 unset 任何优化相关的环境变量。[是不是应当省略这句?]
为编译 GCC 做准备:
lfs:/mnt/lfs/sources/gcc-build$ ../gcc-4.0.3/configure --prefix=/tools \
> --with-local-prefix=/tools --enable-clocale=gnu \
> --enable-shared --enable-threads=posix \
> --enable-__cxa_atexit --enable-languages=c,c++ \
> --disable-libstdcxx-pch
新配置选项的含义:
--enable-clocale=gnu 本参数确保 C++ 库在任何情况下都使用正确的 locale 模块。如果配置脚本查找到 de_DE 这个 locale ,它就会使用正确的 gnu locale 模块。然而,如果没有安装 de_DE ,就有可能创建出应用程序二进制接口(ABI)不兼容的 C++ 库文件,这是因为选择了错误的通用(generic) locale 模块。 --enable-threads=posix 使 C++ 异常能处理多线程代码。 --enable-__cxa_atexit 用 __cxa_atexit 代替 atexit 来登记 C++ 对象的本地静态和全局析构函数,这是为了完全符合标准对析构函数的处理规定。它还会影响到 C++ ABI ,因此生成的 C++ 共享库在其他的 Linux 发行版上也能使用。 --enable-languages=c,c++ 本参数编译 C 和 C++ 语言的编译器。 --disable-libstdcxx-pch 不为 libstdc++ 编译预编译头(PCH),它占用了很大空间,但是我们用不到它。
编译软件包:
lfs:/mnt/lfs/sources/gcc-build$ make && date +%c
[开始于2006年11月13日11:43:15]
……
……
……
make[4]: Leaving directory `/mnt/lfs/sources/gcc-build/i686-pc-linux-gnu/libmudflap'
make[3]: Leaving directory `/mnt/lfs/sources/gcc-build/i686-pc-linux-gnu/libmudflap'
make[2]: Leaving directory `/mnt/lfs/sources/gcc-build/i686-pc-linux-gnu/libmudflap'
make[1]: Leaving directory `/mnt/lfs/sources/gcc-build/i686-pc-linux-gnu/libmudflap'
Mon Nov 13 12:08:12 2006
lfs:/mnt/lfs/sources/gcc-build$
现在没必要用 bootstrap 作为 make 的目标,因为这里 GCC 是用相同版本的 GCC 来编译的,其实连源码都一模一样,就是在第一遍的时候安装的那个。
现在编译完成了,早先我们谈到过,本章中的临时工具的测试程序并不是必须运行的,如果您要运行 GCC 的测试程序,请输入下面的命令:
make -k check
-k 参数是让测试套件即使遇到错误,也继续运行,直到完成。GCC 的测试套件非常全面,所以基本上总是会出一些错的。
安装软件包:
lfs:/mnt/lfs/sources/gcc-build$ make install
小心
现在,需要停下来再一次确认新工具链的基本功能(编译和连接)是否按预期工作,运行下面的命令做一个简单的合理性检查:
echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep ': /tools'
如果一切正常,应该不会出错,而且最后一个命令的结果应当是:
[Requesting program interpreter: /tools/lib/ld-linux.so.2]
注意,/tools/lib 应该是动态连接器的前缀。
lfs:/mnt/lfs/sources/gcc-build$ echo 'main(){}' > dummy.c
lfs:/mnt/lfs/sources/gcc-build$ cc dummy.c
lfs:/mnt/lfs/sources/gcc-build$ readelf -l a.out | grep ': /tools'
[Requesting program interpreter: /tools/lib/ld-linux.so.2]
lfs:/mnt/lfs/sources/gcc-build$
如果输出不是像上面那样或者根本没有输出,那么就有大问题了。返回并检查前面的操作,找出问题,并改正过来。在改正之前,不要继续后面的部份,因为这样做没有意义。首先,再次上述合理性检查,用 gcc 代替 cc ,如果工作正常,那么是因为 /tools/bin/cc 这个符号链接丢失了。回头看看“GCC-4.0.3 - 第一遍”并建立符号链接。接下来,确保 PATH 正确。检查时,运行 echo $PATH 并检查 /tools/bin 是否在列表的最前面。如果 PATH 错误,可能时因为你没有以 lfs 用户登录,或者在“设置工作环境”部分出错了。另外一个原因可能是上面修正 specs 文件时出错,如果这样,重新修改 specs 文件,复制粘贴时小心。
在确定一切正常后,删除测试文件:
lfs:/mnt/lfs/sources/gcc-build$ rm -v dummy.c a.out
removed `dummy.c'
removed `a.out'
lfs:/mnt/lfs/sources/gcc-build$
12.Binutils-2.16.1
Binutils 是一组开发工具,包括连接器、汇编器和其他用于目标文件和档案的工具。
预计编译时间: 1.1 SBU
所需磁盘空间: 154 MB
重新安装Binutils
lfs:/mnt/lfs/sources/gcc-build$ mv $LFS/sources/binutils-2.16.1 $LFS/sources/old
lfs:/mnt/lfs/sources/gcc-build$ mv $LFS/sources/binutils-build $LFS/sources/old
lfs:/mnt/lfs/sources/gcc-build$ tar -jxvf $LFS/sources/binutils-2.16.1.tar.bz2 -C $LFS/sources
lfs:/mnt/lfs/sources/gcc-build$ cd $LFS/sources/binutils-2.16.1
再次为编译创建一个单独目录:
lfs:/mnt/lfs/sources/binutils-2.16.1$ mkdir -v ../binutils-build
mkdir: created directory `../binutils-build'
lfs:/mnt/lfs/sources/binutils-2.16.1$ cd ../binutils-build
为编译 Binutils 做准备:
lfs:/mnt/lfs/sources/binutils-build$ ../binutils-2.16.1/configure --prefix=/tools \
> --disable-nls --with-lib-path=/tools/lib
新配置选项的含义:
--with-lib-path=/tools/lib 这个选项指示 configure 脚本在 Binutils 编译过程中将传递给连接器的库搜索路径设为 /tools/lib ,以防止连接器搜索宿主系统的库目录。
编译软件包:
lfs:/mnt/lfs/sources/binutils-build$ make && date +%c [开始于2006年11月13日12:30:19]
……
……
……
rm -f ldver.texi
echo '@set VERSION 2.16.1' > ldver.texi
touch ld.1
perl ../../binutils-2.16.1/ld/../etc/texi2pod.pl -Dman < ../../binutils-2.16.1/ld/ld.texinfo > ld.pod
(pod2man --center="GNU Development Tools" --release="binutils-2.16.1" --section=1 ld.pod | \
sed -e '/^.if n .na/d' > ld.1.T$$ && \
mv -f ld.1.T$$ ld.1) || \
(rm -f ld.1.T$$ && exit 1)
rm -f ld.pod
make[3]: Leaving directory `/mnt/lfs/sources/binutils-build/ld'
make[2]: Leaving directory `/mnt/lfs/sources/binutils-build/ld'
make[1]: Leaving directory `/mnt/lfs/sources/binutils-build/ld'
Mon Nov 13 12:36:05 2006
lfs:/mnt/lfs/sources/binutils-build$
现在编译完成了,早先我们谈到过,本章中的临时工具的测试程序并不是必须运行的,如果您要运行 Binutils 的测试程序,请输入下面的命令:
make check
安装软件包:
lfs:/mnt/lfs/sources/binutils-build$ make install
现在,为下一章的"再次调整工具链"阶段配置连接器:
lfs:/mnt/lfs/sources/binutils-build$ make -C ld clean
lfs:/mnt/lfs/sources/binutils-build$ make -C ld LIB_PATH=/usr/lib:/lib
lfs:/mnt/lfs/sources/binutils-build$ cp -v ld/ld-new /tools/bin
`ld/ld-new' -> `/tools/bin/ld-new'
lfs:/mnt/lfs/sources/binutils-build$
13.Ncurses-5.5
Ncurses 提供独立于终端的字符终端处理库,含有功能键定义(快捷键)、屏幕绘制以及基于文本终端的图形互动功能。
预计编译时间: 0.7 SBU
所需磁盘空间: 30 MB
安装Ncurese
lfs:/mnt/lfs/sources/binutils-build$ tar -zxvf $LFS/sources/ncurses-5.5.tar.gz -C $LFS/sources
lfs:/mnt/lfs/sources/binutils-build$ cd $LFS/sources/ncurses-5.5
为编译 Ncurses 做准备:
lfs:/mnt/lfs/sources/ncurses-5.5$ ./configure --prefix=/tools --with-shared \
> --without-debug --without-ada –enable-overwrite
配置选项的含义:
--without-ada 这个选项让 Ncurses 在即使宿主系统上安装了 Ada 编译器的情况下也不要编译其 Ada 绑定。需要这样做的原因是一旦我们进入 chroot 环境,Ada 就不能使用了。 --enable-overwrite 这个选项让 Ncurses 把它的头文件安装到 /tools/include 目录,而不是 /tools/include/ncurses 目录,以确保其它软件包可以顺利找到 Ncurses 的头文件。
编译软件包:
lfs:/mnt/lfs/sources/ncurses-5.5$ make
这个软件包没有附带测试程序。
安装软件包:
lfs:/mnt/lfs/sources/ncurses-5.5$ make install
14.Bash-3.1
Bash 是 Bourne-Again Shell 的缩写,它在 UNIX 系统中作为 shell 被广泛使用。
预计编译时间: 0.4 SBU
所需磁盘空间: 22 MB
安装Bash
lfs:/mnt/lfs/sources/ncurses-5.5$ tar -zxvf $LFS/sources/bash-3.1.tar.gz -C $LFS/sources
lfs:/mnt/lfs/sources/ncurses-5.5$ cd $LFS/sources/bash-3.1
Bash-3.1 正式发布以后开发者们又修正了许多缺陷,下面的补丁包含了这些修正:
lfs:/mnt/lfs/sources/bash-3.1$ patch -Np1 -i ../bash-3.1-fixes-8.patch
为编译 Bash 做准备:
lfs:/mnt/lfs/sources/bash-3.1$ ./configure --prefix=/tools –without-bash-malloc
配置选项的含义:
--without-bash-malloc 这个选项禁用了 Bash 的内存分配函数(malloc),这个函数已知会造成段错误,通过设置这个选项,Bash 将使用更为稳定的 Glibc 里的 malloc 函数。
编译软件包:
lfs:/mnt/lfs/sources/bash-3.1$ make
要测试结果,请运行:make tests 。
安装软件包:
lfs:/mnt/lfs/sources/bash-3.1$ make install
为那些用 sh 作为 shell 的程序创建符号链接:
lfs:/mnt/lfs/sources/bash-3.1$ ln -vs bash /tools/bin/sh
create symbolic link `/tools/bin/sh' to `bash'
lfs:/mnt/lfs/sources/bash-3.1$
15.Bzip2-1.0.3
Bzip2 包含了对文件进行压缩和解压缩的工具,对于文本文件,bzip2 比传统的 gzip 拥有更高压缩比。
预计编译时间: 少于 0.1 SBU
所需磁盘空间: 4.2 MB
安装Bzip2
lfs:/mnt/lfs/sources/bash-3.1$ tar -zxvf $LFS/sources/bzip2-1.0.3.tar.gz -C $LFS/sources
lfs:/mnt/lfs/sources/bash-3.1$ cd $LFS/sources/bzip2-1.0.3
Bzip2 软件包没有 configure 脚本,用下面的命令直接编译:
lfs:/mnt/lfs/sources/bzip2-1.0.3$ make
安装软件包:
lfs:/mnt/lfs/sources/bzip2-1.0.3$ make PREFIX=/tools install
16.Coreutils-5.96
Coreutils 软件包包括一整套用于显示和设置基本系统特征的工具。
预计编译时间: 0.6 SBU
所需磁盘空间: 56.1 MB
安装Coreutils
lfs:/mnt/lfs/sources/bzip2-1.0.3$ tar -jxvf $LFS/sources/coreutils-5.96.tar.bz2 -C $LFS/sources
lfs:/mnt/lfs/sources/bzip2-1.0.3$ cd $LFS/sources/coreutils-5.96
为编译 Coreutils 做准备:
lfs:/mnt/lfs/sources/coreutils-5.96$ ./configure –prefix=/tools
编译软件包:
lfs:/mnt/lfs/sources/coreutils-5.96$ make
要测试结果,请运行:make RUN_EXPENSIVE_TESTS=yes check ,RUN_EXPENSIVE_TESTS=yes 参数让测试程序运行几个附加的测试,在某些平台上这些测试会耗费更多的 CPU 和内存,不过一般在 Linux 上不是什么问题。
安装软件包:
lfs:/mnt/lfs/sources/coreutils-5.96$ make install
17.Diffutils-2.8.1
Diffutils 软件包里的程序可以向你显示两个文件或目录的差异,常用来生成软件的补丁。
预计编译时间: 0.1 SBU
所需磁盘空间: 6.2 MB
安装Diffutils
lfs:/mnt/lfs/sources/coreutils-5.96$ tar -zxvf $LFS/sources/diffutils-2.8.1.tar.gz -C $LFS/sources
lfs:/mnt/lfs/sources/coreutils-5.96$ cd $LFS/sources/diffutils-2.8.1
为编译 Diffutils 做准备:
lfs:/mnt/lfs/sources/diffutils-2.8.1$ ./configure –prefix=/tools
编译软件包:
lfs:/mnt/lfs/sources/diffutils-2.8.1$ make
这个软件包没有附带测试程序。
安装软件包:
lfs:/mnt/lfs/sources/diffutils-2.8.1$ make install
18.Findutils-4.2.27
Findutils 软件包包含查找文件的工具,既能即时查找(递归的搜索目录,并可以显示、创建和维护文件),也能在数据库里查找(通常比递归查找快但是在数据库没有及时更新的情况下,结果并不可靠)。
预计编译时间: 0.2 SBU
所需磁盘空间: 12 MB
安装Findutils
lfs:/mnt/lfs/sources/diffutils-2.8.1$ tar -zxvf $LFS/sources/findutils-4.2.27.tar.gz -C $LFS/sources
lfs:/mnt/lfs/sources/diffutils-2.8.1$ cd $LFS/sources/findutils-4.2.27
为编译 Findutils 做准备:
lfs:/mnt/lfs/sources/findutils-4.2.27$ ./configure –prefix=/tools
编译软件包:
lfs:/mnt/lfs/sources/findutils-4.2.27$ make
要测试结果,请运行:make check 。
安装软件包:
lfs:/mnt/lfs/sources/findutils-4.2.27$ make install
19.Gawk-3.1.5
Gawk 是一个处理文本文件的工具包。
预计编译时间: 0.2 SBU
所需磁盘空间: 18.2 MB
安装Gawk
lfs:/mnt/lfs/sources/findutils-4.2.27$ tar -jxvf $LFS/sources/gawk-3.1.5.tar.bz2 -C $LFS/sources
lfs:/mnt/lfs/sources/findutils-4.2.27$ cd $LFS/sources/gawk-3.1.5
为编译 Gawk 做准备:
lfs:/mnt/lfs/sources/gawk-3.1.5$ ./configure --prefix=/tools
由于 configure 脚本的一个 bug ,Gawk 不能正确检测某些 Glibc 支持的 locale ,这将会导致一些问题,比如,Gettext 的测试程序会失败。修复这个 bug 的办法是在 config.h 文件结尾追加丢失的宏定义:
cat >>config.h <<"EOF"
#define HAVE_LANGINFO_CODESET 1
#define HAVE_LC_MESSAGES 1
EOF
lfs:/mnt/lfs/sources/gawk-3.1.5$ cat >>config.h <<"EOF"
> #define HAVE_LANGINFO_CODESET 1
> #define HAVE_LC_MESSAGES 1
> EOF (Ctrl + D :“EOF”)
lfs:/mnt/lfs/sources/gawk-3.1.5$
编译软件包:
lfs:/mnt/lfs/sources/gawk-3.1.5$ make
要测试结果,请运行:make check 。
安装软件包:
lfs:/mnt/lfs/sources/gawk-3.1.5$ make install
20.Gettext-0.14.5
Gettext 包含用于系统的国际化和本地化的工具,可以在编译程序的时候使用本国语言支持(NLS),可以使程序的输出使用用户设置的语言而不是英文。
预计编译时间: 0.4 SBU
所需磁盘空间: 43 MB
安装Gettext
lfs:/mnt/lfs/sources/gawk-3.1.5$ tar -zxvf $LFS/sources/gettext-0.14.5.tar.gz -C $LFS/sources
lfs:/mnt/lfs/sources/gawk-3.1.5$ cd $LFS/sources/gettext-0.14.5
对于临时工具链来说,我们只需要编译和安装 Gettext 中的一个二进制文件即可。
为编译 Gettext 做准备:
lfs:/mnt/lfs/sources/gettext-0.14.5$ cd gettext-tools
lfs:/mnt/lfs/sources/gettext-0.14.5/gettext-tools$ ./configure --prefix=/tools –disable-shared
配置选项的含义:
--disable-shared 当前我们不需要安装任何 Gettext 共享库,因此也就不需要编译它们。
编译软件包:
lfs:/mnt/lfs/sources/gettext-0.14.5/gettext-tools$ make -C lib
lfs:/mnt/lfs/sources/gettext-0.14.5/gettext-tools$ make -C src msgfmt
因为只编译了一个二进制文件,所以无法运行测试套件。并且我们也不推荐在此时运行测试。
安装编译好的二进制文件 msgfmt :
lfs:/mnt/lfs/sources/gettext-0.14.5/gettext-tools$ cp -v src/msgfmt /tools/bin
`src/msgfmt' -> `/tools/bin/msgfmt'
21.Grep-2.5.1a
Grep 可以按指定的匹配模式搜索文件中的内容。
预计编译时间: 0.1 SBU
所需磁盘空间: 4.8 MB
安装Grep
lfs:/mnt/lfs/sources/gettext-0.14.5/gettext-tools$ tar -jxvf $LFS/sources/grep-2.5.1a.tar.bz2 -C $LFS/sources
lfs:/mnt/lfs/sources/gettext-0.14.5/gettext-tools$ cd $LFS/sources/grep-2.5.1a
为编译 Grep 做准备:
lfs:/mnt/lfs/sources/grep-2.5.1a$ ./configure --prefix=/tools \
> --disable-perl-regexp
配置选项的含义:
--disable-perl-regexp 这个选项确保 grep 程序不连接可能在宿主系统上存在的 PCRE(Perl 兼容正则表达式)库,因为进入 chroot 环境后,它就不能使用了。
编译软件包:
lfs:/mnt/lfs/sources/grep-2.5.1a$ make
要测试结果,请运行:make check 。
安装软件包:
lfs:/mnt/lfs/sources/grep-2.5.1a$ make install
22.Gzip-1.3.5
Gzip 软件包包含了压缩和解压文件的程序。
预计编译时间: 少于 0.1 SBU
所需磁盘空间: 2.2 MB
安装Gzip
lfs:/mnt/lfs/sources/grep-2.5.1a$ tar -zxvf $LFS/sources/gzip-1.3.5.tar.gz -C $LFS/sources
lfs:/mnt/lfs/sources/grep-2.5.1a$ cd $LFS/sources/gzip-1.3.5
为编译 Gzip 做准备:
lfs:/mnt/lfs/sources/gzip-1.3.5$ ./configure –prefix=/tools
编译软件包:
lfs:/mnt/lfs/sources/gzip-1.3.5$ make
这个软件包没有附带测试程序。
安装软件包:
lfs:/mnt/lfs/sources/gzip-1.3.5$ make install
23.M4-1.4.4
M4 包含一个宏处理器。
预计编译时间: 少于 0.1 SBU
所需磁盘空间: 3 MB
安装M4
lfs:/mnt/lfs/sources/gzip-1.3.5$ tar -zxvf $LFS/sources/m4-1.4.4.tar.gz -C $LFS/sources
lfs:/mnt/lfs/sources/gzip-1.3.5$ cd $LFS/sources/m4-1.4.4
为编译M4做准备:
lfs:/mnt/lfs/sources/m4-1.4.4$ ./configure –prefix=/tools
编译软件包:
lfs:/mnt/lfs/sources/m4-1.4.4$ make
要测试结果,请运行:make check 。
安装软件包:
lfs:/mnt/lfs/sources/m4-1.4.4$ make install
24.Make-3.80
Make 软件包包含一个编译软件包的程序。
预计编译时间: 0.1 SBU
所需磁盘空间: 7.8 MB
安装Make
lfs:/mnt/lfs/sources/m4-1.4.4$ tar -jxvf $LFS/sources/make-3.80.tar.bz2 -C $LFS/sources
lfs:/mnt/lfs/sources/m4-1.4.4$ cd $LFS/sources/make-3.80
为编译Make做做准备:
lfs:/mnt/lfs/sources/make-3.80$ ./configure --prefix=/tools
编译软件包:
lfs:/mnt/lfs/sources/make-3.80$ make
要测试结果,请运行:make check 。
安装软件包:
lfs:/mnt/lfs/sources/make-3.80$ make install
25.Patch-2.5.4
Patch 软件包包含一个根据补丁文件来修改原文件的程序。补丁文件通常是用 diff 程序创建的。
预计编译时间: 少于 0.1 SBU
所需磁盘空间: 1.6 MB
安装Patch
lfs:/mnt/lfs/sources/make-3.80$ tar -zxvf $LFS/sources/patch-2.5.4.tar.gz -C $LFS/sources
lfs:/mnt/lfs/sources/make-3.80$ cd $LFS/sources/patch-2.5.4
为编译Patch做准备:
lfs:/mnt/lfs/sources/patch-2.5.4$ ./configure –prefix=/tools
编译软件包:
lfs:/mnt/lfs/sources/patch-2.5.4$ make
这个软件包没有附带测试程序。
安装软件包:
lfs:/mnt/lfs/sources/patch-2.5.4$ make install
26.Perl-5.8.8
Perl 是 Practical Extraction and Report Language的缩写。Perl 将 C, sed, awk 和 sh 的最佳特性集于一身,是一种强大的编程语言。
预计编译时间: 0.7 SBU
所需磁盘空间: 84 MB
安装Perl
lfs:/mnt/lfs/sources/patch-2.5.4$ tar -jxvf $LFS/sources/perl-5.8.8.tar.bz2 -C $LFS/sources
lfs:/mnt/lfs/sources/patch-2.5.4$ cd $LFS/sources/perl-5.8.8
首先应用下面的补丁,调整指向 C 库的硬连接路径:
lfs:/mnt/lfs/sources/perl-5.8.8$ patch -Np1 -i ../perl-5.8.8-libc-2.patch
patching file hints/linux.sh
lfs:/mnt/lfs/sources/perl-5.8.8$
准备编译 Perl(请正确输入下面命令中的"IO Fcntl POSIX"——全是字母):
lfs:/mnt/lfs/sources/perl-5.8.8$ ./configure.gnu --prefix=/tools -Dstatic_ext='Data/Dumper Fcntl IO POSIX'
配置选项的含义:
-Dstatic_ext='Data/Dumper Fcntl IO POSIX' 这个选项让 Perl 编译静态扩展的最小集,下一章安装和测试 Coreutils 软件包的时候需要用到。
仅需要编译这个软件包中的一小部分必要工具:
lfs:/mnt/lfs/sources/perl-5.8.8$ make perl utilities
尽管 Perl 附带测试程序,但我们不推荐在这里运行。由于只编译了一部分 Perl,现在运行 make test 会编译 Perl 的其余部分,而这里我们并不需要它们。如果想测试的话,可以到下一章再运行测试程序。
安装这些工具和库:
lfs:/mnt/lfs/sources/perl-5.8.8$ cp -v perl pod/pod2man /tools/bin
`perl' -> `/tools/bin/perl'
`pod/pod2man' -> `/tools/bin/pod2man'
lfs:/mnt/lfs/sources/perl-5.8.8$ mkdir -pv /tools/lib/perl5/5.8.8
mkdir: created directory `/tools/lib/perl5'
mkdir: created directory `/tools/lib/perl5/5.8.8'
lfs:/mnt/lfs/sources/perl-5.8.8$ cp -Rv lib/* /tools/lib/perl5/5.8.8
27.Sed-4.1.5
sed 是一个流编辑程序,在一个输入流(从一个文件或者一个管道的输入)上进行基本的文本编辑操作。
预计编译时间: 0.1 SBU
所需磁盘空间: 6.1 MB
安装Sed
lfs:/mnt/lfs/sources/perl-5.8.8$ tar -zxvf $LFS/sources/sed-4.1.5.tar.gz -C $LFS/sources
lfs:/mnt/lfs/sources/perl-5.8.8$ cd $LFS/sources/sed-4.1.5
为编译Sed做准备:
lfs:/mnt/lfs/sources/sed-4.1.5$ ./configure –prefix=/tools
编译软件包:
lfs:/mnt/lfs/sources/sed-4.1.5$ make
要测试结果,请运行:make check 。
安装软件包:
lfs:/mnt/lfs/sources/sed-4.1.5$ make install
28.Tar-1.15.1
Tar 软件包含有一个归档程序,用来保存文件到归档文件或者从给定的 tar 归档文件中释放文件。
预计编译时间: 0.2 SBU
所需磁盘空间: 13.7 MB
安装Tar
lfs:/mnt/lfs/sources/sed-4.1.5$ tar -jxvf $LFS/sources/tar-1.15.1.tar.bz2 -C $LFS/sources
lfs:/mnt/lfs/sources/sed-4.1.5$ cd $LFS/sources/tar-1.15.1
如果想运行测试套件则需要使用下面的补丁修正一些与 GCC-4.0.3 相关的问题:
lfs:/mnt/lfs/sources/tar-1.15.1$ patch -Np1 -i ../tar-1.15.1-gcc4_fix_tests-1.patch
patching file tests/genfile.c
lfs:/mnt/lfs/sources/tar-1.15.1$
为编译Tar做准备:
lfs:/mnt/lfs/sources/tar-1.15.1$ ./configure --prefix=/tools
编译软件包:
lfs:/mnt/lfs/sources/tar-1.15.1$ make
要测试结果,请运行:make check 。
安装软件包:
lfs:/mnt/lfs/sources/tar-1.15.1$ make install
29.Texinfo-4.8
Texinfo 软件包包含读取、写入和转换 Info 文档的程序,以提供系统文档。
预计编译时间: 0.2 SBU
所需磁盘空间: 16.3 MB
安装Texinfo
lfs:/mnt/lfs/sources/tar-1.15.1$ tar -jxvf $LFS/sources/texinfo-4.8.tar.bz2 -C $LFS/sources
lfs:/mnt/lfs/sources/tar-1.15.1$ cd $LFS/sources/texinfo-4.8
为编译Texinfo做准备:
lfs:/mnt/lfs/sources/texinfo-4.8$ ./configure --prefix=/tools
编译软件包:
lfs:/mnt/lfs/sources/texinfo-4.8$ make
要测试结果,请运行:make check 。
安装软件包:
lfs:/mnt/lfs/sources/texinfo-4.8$ make install
30.Util-linux-2.12r
Util-linux 软件包包含许多工具。其中比较重要的是加载、卸载、格式化、分区和管理驱动器,以及打开 tty 端口和处理消息。
预计编译时间: 少于 0.1 SBU
所需磁盘空间: 8.9 MB
安装Util-linux
lfs:/mnt/lfs/sources/texinfo-4.8$ tar -jxvf $LFS/sources/util-linux-2.12r.tar.bz2 -C $LFS/sources
lfs:/mnt/lfs/sources/texinfo-4.8$ cd $LFS/sources/util-linux-2.12r
Util-linux 默认不使用刚才安装在 /tools 目录下的头文件和库文件,我们更改配置脚本来修正这个问题:
lfs:/mnt/lfs/sources/util-linux-2.12r$ sed -i 's@/usr/include@/tools/include@g' configure
为编译 Util-linux 做准备:
lfs:/mnt/lfs/sources/util-linux-2.12r$ ./configure
configuring util-linux-2.12r
You have <scsi/scsi.h>
You have <linux/blkpg.h>
You have <linux/kd.h>
You have <locale.h>
You have <langinfo.h>
You have <sys/user.h>
You don't have <uuid/uuid.h>
You have <rpcsvc/nfs_prot.h>
You have <asm/types.h>
You have <linux/raw.h>
You have <stdint.h>
You have <sys/io.h>
You have inet_aton()
You have fsync()
You have getdomainname()
You have nanosleep()
You have personality()
You have updwtmp()
You have fseeko()
You have lchown()
You have rpmatch()
You have <term.h>
You have ncurses. Using <ncurses.h>.
You don't have termcap
You need -lcrypt
You have <libintl.h> and gettext()
You have __progname
You have <pty.h> and openpty()
You have wide character support
You have SYS_pivot_root
You have a tm_gmtoff field in struct tm
Your rpcgen seems to work
You don't have zlib
You don't have blkid
lfs:/mnt/lfs/sources/util-linux-2.12r$
编译一些支持例程:
lfs:/mnt/lfs/sources/util-linux-2.12r$ make -C lib
我们只需要这个软件包中的少数几个工具,因此只需要编译这几个工具就可以了:
lfs:/mnt/lfs/sources/util-linux-2.12r$ make -C mount mount umount
lfs:/mnt/lfs/sources/util-linux-2.12r$ make -C text-utils more
这个软件包没有附带测试程序。
把这些程序复制到临时工具目录:
lfs:/mnt/lfs/sources/util-linux-2.12r$ cp mount/{,u}mount text-utils/more /tools/bin
31.清理系统
本节的步骤是可选的,但如果 LFS 分区实在很小则除外;同时了解哪些东西是不必要的、可以删除的也是有好处的。到目前为止已经安装的可执行程序和库文件包含大约 70 MB 不必要的调试符号,运行下面的命令删除这些符号:
lfs:/mnt/lfs/sources/util-linux-2.12r$ strip --strip-debug /tools/lib/*
strip: Warning: '/tools/lib/expect5.43' is not an ordinary file
strip: Warning: '/tools/lib/gcc' is not an ordinary file
strip: Warning: '/tools/lib/gconv' is not an ordinary file
strip: /tools/lib/libbfd.la: File format not recognized
strip: /tools/lib/libc.so: File format not recognized
strip: /tools/lib/libmudflap.la: File format not recognized
strip: /tools/lib/libmudflapth.la: File format not recognized
strip: /tools/lib/libopcodes.la: File format not recognized
strip: /tools/lib/libpthread.so: File format not recognized
strip: /tools/lib/libstdc++.la: File format not recognized
strip: /tools/lib/libsupc++.la: File format not recognized
strip: unable to copy file '/tools/lib/libtcl8.4.so' reason: Permission denied
strip: Warning: '/tools/lib/perl5' is not an ordinary file
strip: Warning: '/tools/lib/tcl8.4' is not an ordinary file
strip: /tools/lib/tclConfig.sh: File format not recognized
strip: Warning: '/tools/lib/terminfo' is not an ordinary file
lfs:/mnt/lfs/sources/util-linux-2.12r$ strip --strip-unneeded /tools/{,s}bin/*
strip: /tools/bin/bashbug: File format not recognized
strip: /tools/bin/bzcmp: File format not recognized
strip: /tools/bin/bzdiff: File format not recognized
strip: /tools/bin/bzegrep: File format not recognized
strip: /tools/bin/bzfgrep: File format not recognized
strip: /tools/bin/bzgrep: File format not recognized
strip: /tools/bin/bzless: File format not recognized
strip: /tools/bin/bzmore: File format not recognized
strip: /tools/bin/catchsegv: File format not recognized
strip: /tools/bin/egrep: File format not recognized
strip: /tools/bin/fgrep: File format not recognized
strip: /tools/bin/gccbug: File format not recognized
strip: /tools/bin/groups: File format not recognized
strip: /tools/bin/gzexe: File format not recognized
strip: /tools/bin/igawk: File format not recognized
strip: /tools/bin/ldd: File format not recognized
strip: /tools/bin/mtrace: File format not recognized
strip: /tools/bin/pod2man: File format not recognized
strip: /tools/bin/runtest: File format not recognized
strip: unable to copy file '/tools/bin/strip' reason: Text file busy
strip: /tools/bin/texi2dvi: File format not recognized
strip: /tools/bin/texi2pdf: File format not recognized
strip: /tools/bin/tzselect: File format not recognized
strip: /tools/bin/updatedb: File format not recognized
strip: /tools/bin/xtrace: File format not recognized
strip: /tools/bin/zcmp: File format not recognized
strip: /tools/bin/zdiff: File format not recognized
strip: /tools/bin/zegrep: File format not recognized
strip: /tools/bin/zfgrep: File format not recognized
strip: /tools/bin/zforce: File format not recognized
strip: /tools/bin/zgrep: File format not recognized
strip: /tools/bin/zless: File format not recognized
strip: /tools/bin/zmore: File format not recognized
strip: /tools/bin/znew: File format not recognized
lfs:/mnt/lfs/sources/util-linux-2.12r$
上面的命令会跳过大约 20 个文件,报告不能识别这些文件格式,其中大多数是脚本而不是二进制文件。
千万不要在库文件上使用 --strip-unneeded ,否则会破坏其静态版本,这样你不得不又从头开始编译全部的工具链软件包。
删除文档还可以节省 20 MB 空间:
rm -rf /tools/{info,man}
现在 $LFS 上有多于 850 MB 剩余空间,可以在下一章编译安装 Glibc 。如果有足够空间编译安装 Glibc ,那编译安装其它的软件包也就没有问题了。
32.改变所有者
注意
本书剩余部分的命令必须以 root 用户登陆后执行而不再使用 lfs 用户了。同样,有必要再一次检查 root 用户环境下的 $LFS 环境变量是否被正确的设置了。
lfs:/mnt/lfs/sources/util-linux-2.12r$ echo $LFS
/mnt/lfs
lfs:/mnt/lfs/sources/util-linux-2.12r$ exit
exit
[root@fish lfs-packages-6.2]# echo $LFS
/mnt/lfs
[root@fish lfs-packages-6.2]#
目前,$LFS/tools 目录的所有者是仅存在于宿主环境中的 lfs 用户。如果保留该目录,那么该目录内文件的所有者的 user ID 就没有对应的账号。这会带来安全上的问题,在以后创建一个用户帐号的时候,如果该用户帐号的 user ID 刚好与目录 $LFS/tools 所有者的 user ID 相同,那么该目录下的文件就会面临被恶意操作的危险。
为了避免这个问题,在后面建立 LFS 系统的时候,在创建 /etc/passwd 文件时添加与宿主系统的 user ID 和 group ID相同的 lfs 用户。另外一个更好的办法是通过下面的指令把 $LFS/tools 目录以及其中文件的所有者改为 root 用户:
chown -R root:root $LFS/tools
[root@fish lfs-packages-6.2]# ls /mnt/lfs/tools/
bin etc i686-pc-linux-gnu include info lib libexec man sbin share var
[root@fish lfs-packages-6.2]# chown -R root:root $LFS/tools
虽然在 LFS 系统完成的时候,可以把 $LFS/tools 目录删除,但是它还可以再用来建立多个相同版本的 LFS 系统,所以很多人会选择保留该目录。如何以最好的方法备份 $LFS/tools 目录取决于个人喜好,我们把这个任务留给读者作为练习。