七. 構建臨時系統
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 View Code3. 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 View Code4. 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 View Code5. 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 View Code6. 確認新工具鏈的基本功能(編譯和鏈接)都是像預期的那樣正常工作。運行下面的命令進行全面的檢查:
echo 'main(){}' > dummy.c $LFS_TGT-gcc dummy.c readelf -l a.out | grep ': /tools' View Code如果一切工作正常的話,這裡應該沒有錯誤,最後一個命令的輸出形式會是:
[Requesting program interpreter: /tools/lib/ld-linux.so.2] View Code 注意 /tools/lib
、或者 64 位機器的 /tools/lib64
會以動態鏈接器的前綴出現。
一旦一切都順利,清理測試文件:
rm -v dummy.c a.out View Code7. 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 View Code8. 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 View Code9. 現在,為接下來的“再調整”階段准備鏈接器:
make -C ld clean make -C ld LIB_PATH=/usr/lib:/lib cp -v ld/ld-new /tools/bin View Code10. 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 View Code11. 確認新工具鏈的基本功能(編譯和鏈接)都是像預期的那樣正常工作。運行下面的命令進行全面的檢查:
echo 'main(){}' > dummy.c cc dummy.c readelf -l a.out | grep ': /tools' View Code如果一切工作正常的話,這裡應該沒有錯誤,最後一個命令的輸出形式會是:
[Requesting program interpreter: /tools/lib/ld-linux.so.2] View Code 注意 /tools/lib
、或者 64 位機器的 /tools/lib64
會以動態鏈接器的前綴出現。
一旦一切都順利,清理測試文件:
rm -v dummy.c a.out View Code12. 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 View Code13. 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 View Code14. 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 View Code15. 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 View Code16. 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 View Code17. 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 View Code18. 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 View Code19. 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 View Code20. 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 View Code21. 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 View Code22. 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 View Code23. 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 View Code24. 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 View Code25. 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 View Code26. 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 View Code27. 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 View Code28. 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 View Code29. 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 View Code30. 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 View Code31. 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 View Code32. 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 View Code33. 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 View Code34. 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 View Code35. 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 View Code36. 清理無用內容
此步驟是可選的,但如果你的 LFS 分區容量比較小,知道有些不必要的內容可以被刪除也是挺好的。
cd ~ strip --strip-debug /tools/lib/* /usr/bin/strip --strip-unneeded /tools/{,s}bin/* rm -rf /tools/{,share}/{info,man,doc} View Code37. 改變屬主
以後部分的命令都必須以 root
用戶身份執行而不再是 lfs
用戶。當前,$LFS/tools
目錄屬於 lfs
用戶,
通過下面的命令將 $LFS/tools
目錄的屬主改為 root
用戶:
38. 備份$LFS/tools
目錄
可用於構建額外的相同版本 LFS 系統。後面的指令將對當前的工具做些調整,導致在構建新系統時會失效。
http://xxxxxx/Linuxjc/1141591.html TechArticle