标签:
七. 构建临时系统
1. 通用编译指南
a. 确认是否正确设置了 LFS
环境变量
echo $LFS
b. 假定你已经正确地设置了宿主系统的符号链接:
1)shell 使用的是 bash。
2)sh 是到 bash 的符号链接。
3)/usr/bin/awk 是到 gawk 的符号链接。
4)/usr/bin/yacc 是到 bison 的符号链接或者一个执行 bison 的小脚本。
c. 构建临时系统中,确保解压软件包时你使用的是 lfs 用户。
d. 除非特别说明,删除解压出来的目录和所有编译过程中生成的
目录。<package>
-build
2. Binutils-2.25 - 第一遍
cd $LFS/sources
tar -jxf binutils-2.25.tar.bz2
cd binutils-2.25
mkdir -v ../binutils-build # 建议在源码目录之外一个专门的编译目录里面编译
cd ../binutils-build
../binutils-2.25/configure \
--prefix=/tools \
--with-sysroot=$LFS \
--with-lib-path=/tools/lib \
--target=$LFS_TGT \
--disable-nls \
--disable-werror
make
# 如果是在 x86_64 上编译,创建符号链接,以确保工具链的完整性
case $(uname -m) in
x86_64) mkdir -v /tools/lib && ln -sv lib /tools/lib64 ;;
esac
make install
rm -rf $LFS/sources/binutils-build
rm -rf $LFS/sources/binutils-2.25
3. GCC-4.9.2 - 第一遍
cd $LFS/sources
tar -jxf gcc-4.9.2.tar.bz2
cd gcc-4.9.2
tar -xf ../mpfr-3.1.2.tar.xz
mv -v mpfr-3.1.2 mpfr
tar -xf ../gmp-6.0.0a.tar.xz
mv -v gmp-6.0.0 gmp
tar -xf ../mpc-1.0.2.tar.gz
mv -v mpc-1.0.2 mpc
for file in $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
cp -uv $file{,.orig}
sed -e ‘s@/lib\(64\)\?\(32\)\?/ld@/tools&@g‘ \
-e ‘s@/usr@/tools@g‘ $file.orig > $file
echo ‘
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
#define STANDARD_STARTFILE_PREFIX_2 ""‘ >> $file
touch $file.orig
done
sed -i ‘/k prot/agcc_cv_libc_provides_ssp=yes‘ gcc/configure
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-4.9.2/configure \
--target=$LFS_TGT \
--prefix=/tools \
--with-sysroot=$LFS \
--with-newlib \
--without-headers \
--with-local-prefix=/tools \
--with-native-system-header-dir=/tools/include \
--disable-nls \
--disable-shared \
--disable-multilib \
--disable-decimal-float \
--disable-threads \
--disable-libatomic \
--disable-libgomp \
--disable-libitm \
--disable-libquadmath \
--disable-libsanitizer \
--disable-libssp \
--disable-libvtv \
--disable-libcilkrts \
--disable-libstdc++-v3 \
--enable-languages=c,c++
make
make install
rm -rf $LFS/sources/gcc-build
rm -rf $LFS/sources/gcc-4.9.2
4. Linux-3.19 API 头文件
cd $LFS/sources
tar -Jxf linux-3.19.tar.xz
cd linux-3.19
make mrproper
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /tools/include
rm -rf $LFS/sources/linux-3.19
5. Glibc-2.21
cd $LFS/sources
tar -Jxf glibc-2.21.tar.xz
cd glibc-2.21
if [ ! -r /usr/include/rpc/types.h ]; then
su -c ‘mkdir -pv /usr/include/rpc‘
su -c ‘cp -v sunrpc/rpc/*.h /usr/include/rpc‘
fi
sed -e ‘/ia32/s/^/1:/‘ \
-e ‘/SSE2/s/^1://‘ \
-i sysdeps/i386/i686/multiarch/mempcpy_chk.S
mkdir -v ../glibc-build
cd ../glibc-build
../glibc-2.21/configure \
--prefix=/tools \
--host=$LFS_TGT \
--build=$(../glibc-2.21/scripts/config.guess) \
--disable-profile \
--enable-kernel=2.6.32 \
--with-headers=/tools/include \
libc_cv_forced_unwind=yes \
libc_cv_ctors_header=yes \
libc_cv_c_cleanup=yes
make
make install
rm -rf $LFS/sources/glibc-build
rm -rf $LFS/sources/glibc-2.21
6. 确认新工具链的基本功能(编译和链接)都是像预期的那样正常工作。运行下面的命令进行全面的检查:
echo ‘main(){}‘ > dummy.c
$LFS_TGT-gcc dummy.c
readelf -l a.out | grep ‘: /tools‘
如果一切工作正常的话,这里应该没有错误,最后一个命令的输出形式会是:
[Requesting program interpreter: /tools/lib/ld-linux.so.2]
注意 /tools/lib
、或者 64 位机器的 /tools/lib64
会以动态链接器的前缀出现。
一旦一切都顺利,清理测试文件:
rm -v dummy.c a.out
7. Libstdc++-4.9.2
cd $LFS/sources
tar -jxf gcc-4.9.2.tar.bz2
cd gcc-4.9.2
mkdir -pv ../gcc-build
cd ../gcc-build
../gcc-4.9.2/libstdc++-v3/configure \
--host=$LFS_TGT \
--prefix=/tools \
--disable-multilib \
--disable-shared \
--disable-nls \
--disable-libstdcxx-threads \
--disable-libstdcxx-pch \
--with-gxx-include-dir=/tools/$LFS_TGT/include/c++/4.9.2
make
make install
rm -rf $LFS/sources/gcc-build
rm -rf $LFS/sources/gcc-4.9.2
8. Binutils-2.25 - 第2遍
cd $LFS/sources
tar -jxf binutils-2.25.tar.bz2
cd binutils-2.25
mkdir -v ../binutils-build
cd ../binutils-build
CC=$LFS_TGT-gcc \
AR=$LFS_TGT-ar \
RANLIB=$LFS_TGT-ranlib ../binutils-2.25/configure \
--prefix=/tools \
--disable-nls \
--disable-werror \
--with-lib-path=/tools/lib \
--with-sysroot
make
make install
rm -rf $LFS/sources/binutils-build
rm -rf $LFS/sources/binutils-2.25
9. 现在,为接下来的“再调整”阶段准备链接器:
make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib
cp -v ld/ld-new /tools/bin
10. GCC-4.9.2 - 第2遍
cd $LFS/sources
tar -jxf gcc-4.9.2.tar.bz2
cd gcc-4.9.2
cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
`dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include-fixed/limits.h
for file in $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
cp -uv $file{,.orig}
sed -e ‘s@/lib\(64\)\?\(32\)\?/ld@/tools&@g‘ \
-e ‘s@/usr@/tools@g‘ $file.orig > $file
echo ‘
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
#define STANDARD_STARTFILE_PREFIX_2 ""‘ >> $file
touch $file.orig
done
tar -xf ../mpfr-3.1.2.tar.xz
mv -v mpfr-3.1.2 mpfr
tar -xf ../gmp-6.0.0a.tar.xz
mv -v gmp-6.0.0 gmp
tar -xf ../mpc-1.0.2.tar.gz
mv -v mpc-1.0.2 mpc
mkdir -v ../gcc-build
cd ../gcc-build
CC=$LFS_TGT-gcc \
CXX=$LFS_TGT-g++ \
AR=$LFS_TGT-ar \
RANLIB=$LFS_TGT-ranlib ../gcc-4.9.2/configure \
--prefix=/tools \
--with-local-prefix=/tools \
--with-native-system-header-dir=/tools/include \
--enable-languages=c,c++ \
--disable-libstdcxx-pch \
--disable-multilib \
--disable-bootstrap \
--disable-libgomp
make
make install
ln -sv gcc /tools/bin/cc
rm -rf $LFS/sources/gcc-build
rm -rf $LFS/sources/gcc-4.9.2
11. 确认新工具链的基本功能(编译和链接)都是像预期的那样正常工作。运行下面的命令进行全面的检查:
echo ‘main(){}‘ > dummy.c
cc dummy.c
readelf -l a.out | grep ‘: /tools‘
如果一切工作正常的话,这里应该没有错误,最后一个命令的输出形式会是:
[Requesting program interpreter: /tools/lib/ld-linux.so.2]
注意 /tools/lib
、或者 64 位机器的 /tools/lib64
会以动态链接器的前缀出现。
一旦一切都顺利,清理测试文件:
rm -v dummy.c a.out
12. Tcl-8.6.3
此软件包和后面三个包(Expect、DejaGNU 和 Check)用来为 GCC 和 Binutils 还有其他的一些软件包的
测试套件提供运行支持。
cd $LFS/sources
tar -zxf tcl8.6.3-src.tar.gz
cd tcl8.6.3
cd unix
./configure --prefix=/tools
make
make install
chmod -v u+w /tools/lib/libtcl8.6.so
make install-private-headers
ln -sv tclsh8.6 /tools/bin/tclsh
rm -rf $LFS/sources/tcl8.6.3
13. Expect-5.45
cd $LFS/sources
tar -zxf expect5.45.tar.gz
cd expect5.45
cp -v configure{,.orig}
sed ‘s:/usr/local/bin:/bin:‘ configure.orig > configure
./configure --prefix=/tools \
--with-tcl=/tools/lib \
--with-tclinclude=/tools/include
make
make SCRIPTS="" install
rm -rf $LFS/sources/expect5.45
14. DejaGNU-1.5.2
cd $LFS/sources
tar -zxf dejagnu-1.5.2.tar.gz
cd dejagnu-1.5.2
./configure --prefix=/tools
make install
rm -rf $LFS/sources/dejagnu-1.5.2
15. Check-0.9.14
cd $LFS/sources
tar -zxf check-0.9.14.tar.gz
cd check-0.9.14
PKG_CONFIG= ./configure --prefix=/tools
make
make install
rm -rf $LFS/sources/check-0.9.14
16. Ncurses-5.9
cd $LFS/sources
tar -zxf ncurses-5.9.tar.gz
cd ncurses-5.9
./configure --prefix=/tools \
--with-shared \
--without-debug \
--without-ada \
--enable-widec \
--enable-overwrite
make
make install
rm -rf $LFS/sources/ncurses-5.9
17. Bash-4.3.30
cd $LFS/sources
tar -zxf bash-4.3.30.tar.gz
cd bash-4.3.30
./configure --prefix=/tools --without-bash-malloc
make
make install
ln -sv bash /tools/bin/sh
rm -rf $LFS/sources/bash-4.3.30
18. Bzip2-1.0.6
cd $LFS/sources
tar -zxf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
make
make PREFIX=/tools install
rm -rf $LFS/sources/bzip2-1.0.6
19. Coreutils-8.23
cd $LFS/sources
tar -Jxf coreutils-8.23.tar.xz
cd coreutils-8.23
./configure --prefix=/tools --enable-install-program=hostname
make
make install
rm -rf $LFS/sources/coreutils-8.23
20. Diffutils-3.3
cd $LFS/sources
tar -Jxf diffutils-3.3.tar.xz
cd diffutils-3.3
./configure --prefix=/tools
make
make install
rm -rf $LFS/sources/diffutils-3.3
21. File-5.22
cd $LFS/sources
tar -zxf file-5.22.tar.gz
cd file-5.22
./configure --prefix=/tools
make
make install
rm -rf $LFS/sources/file-5.22
22. Findutils-4.4.2
cd $LFS/sources
tar -zxf findutils-4.4.2.tar.gz
cd findutils-4.4.2
./configure --prefix=/tools
make
make install
rm -rf $LFS/sources/findutils-4.4.2
23. Gawk-4.1.1
cd $LFS/sources
tar -Jxf gawk-4.1.1.tar.xz
cd gawk-4.1.1
./configure --prefix=/tools
make
make install
rm -rf $LFS/sources/gawk-4.1.1
24. Gettext-0.19.4
cd $LFS/sources
tar -zxf gettext-0.19.4.tar.xz
cd gettext-0.19.4
cd gettext-tools
EMACS="no" ./configure --prefix=/tools --disable-shared
make -C gnulib-lib
make -C intl pluralx.c
make -C src msgfmt
make -C src msgmerge
make -C src xgettext
cp -v src/{msgfmt,msgmerge,xgettext} /tools/bin
rm -rf $LFS/sources/gettext-0.19.4
25. Grep-2.21
cd $LFS/sources
tar -Jxf grep-2.21.tar.xz
cd grep-2.21
./configure --prefix=/tools
make
make install
rm -rf $LFS/sources/grep-2.21
26. Gzip-1.6
cd $LFS/sources
tar -Jxf gzip-1.6.tar.xz
cd gzip-1.6
./configure --prefix=/tools
make
make install
rm -rf $LFS/sources/gzip-1.6
27. M4-1.4.17
cd $LFS/sources
tar -jxf m4-1.4.17.tar.xz
cd m4-1.4.17
./configure --prefix=/tools
make
make install
rm -rf $LFS/sources/m4-1.4.17
28. Make-4.1
cd $LFS/sources
tar -jxf make-4.1.tar.bz2
cd make-4.1
./configure --prefix=/tools --without-guile
make
make install
rm -rf $LFS/sources/make-4.1
29. Patch-2.7.4
cd $LFS/sources
tar -Jxf patch-2.7.4.tar.xz
cd patch-2.7.4
./configure --prefix=/tools
make
make install
rm -rf $LFS/sources/patch-2.7.4
30. Perl-5.20.2
cd $LFS/sources
tar -jxf perl-5.20.2.tar.bz2
cd perl-5.20.2
sh Configure -des -Dprefix=/tools -Dlibs=-lm
make
cp -v perl cpan/podlators/pod2man /tools/bin
mkdir -pv /tools/lib/perl5/5.20.2
cp -Rv lib/* /tools/lib/perl5/5.20.2
rm -rf $LFS/sources/perl-5.20.2
31. Sed-4.2.2
cd $LFS/sources
tar -jxf sed-4.2.2.tar.bz2
cd sed-4.2.2
./configure --prefix=/tools
make
make install
rm -rf $LFS/sources/sed-4.2.2
32. Tar-1.28
cd $LFS/sources
tar -jxf tar-1.28.tar.xz
cd tar-1.28
./configure --prefix=/tools
make
make install
rm -rf $LFS/sources/tar-1.28
33. Texinfo-5.2
cd $LFS/sources
tar -Jxf texinfo-5.2.tar.xz
cd texinfo-5.2
./configure --prefix=/tools
make
make install
rm -rf $LFS/sources/texinfo-5.2
34. Util-linux-2.26
cd $LFS/sources
tar -Jxf util-linux-2.26.tar.xz
cd util-linux-2.26
./configure --prefix=/tools \
--without-python \
--disable-makeinstall-chown \
--without-systemdsystemunitdir \
PKG_CONFIG=""
make
make install
rm -rf $LFS/sources/util-linux-2.26
35. Xz-5.2.0
cd $LFS/sources
tar -Jxf xz-5.2.0.tar.xz
cd xz-5.2.0
./configure --prefix=/tools
make
make install
rm -rf $LFS/sources/xz-5.2.0
36. 清理无用内容
此步骤是可选的,但如果你的 LFS 分区容量比较小,知道有些不必要的内容可以被删除也是挺好的。
cd ~
strip --strip-debug /tools/lib/*
/usr/bin/strip --strip-unneeded /tools/{,s}bin/*
rm -rf /tools/{,share}/{info,man,doc}
37. 改变属主
以后部分的命令都必须以 root
用户身份执行而不再是 lfs
用户。当前,$LFS/tools
目录属于 lfs
用户,
通过下面的命令将 $LFS/tools
目录的属主改为 root
用户:
exit
chown -R root:root $LFS/tools
38. 备份$LFS/tools
目录
可用于构建额外的相同版本 LFS 系统。后面的指令将对当前的工具做些调整,导致在构建新系统时会失效。
Linux From Scratch(从零开始构建Linux系统,简称LFS)- Version 7.7(二)
标签:
原文地址:http://www.cnblogs.com/Mr-kevin/p/5667085.html