[转载]完全手工打造自定义的LINUX(二)

二:构建临时编译环境。 这里的总体目标是提供一个临时环境,您可以 chroot 到这个环境,在里面构建一个干净、没有问题的目标 LFS 系统。为了尽量的与宿主系统分开,我们创建了一个自包含、自依靠的工具链。

1:Binutils第一遍 大家可以注重到后面所有的解包命令均使用tar xvf来完成,而不管文件的压缩方式是bz2还是gz,这是因为较新的tar程序都具有自动识别后缀名并自动调用相应的解压缩工具的能力,所以可以不需要 指定压缩方式因LFS的LiveCD中提供的tar版本比较新,后面制作的tar版本也比较新,因此支持自动识别的能力,同时为了使文章的解压命令 看起来比较统一方便维护(同样对于想制作成脚本的朋友也会比较方便)因此后面统一使用tar xvf来解压。

 

tar xvf /lfs-sources/binutils-2.17.tar.bz2
cd binutils-2.17/
mkdir -v ../binutils-build
cd ../binutils-build/
CC="gcc -B/usr/bin/" ../binutils-2.17/configure --prefix=/tools --disable-nls --disable-werror
make
make install
make -C ld clean
make -C ld LIB_PATH=/tools/lib/
cp -v ld/ld-new /tools/bin
cd ..
rm -rf binutils-build/
rm -rf binutils-2.17/

2:GCC第一遍

tar xvf /lfs-sources/gcc-4.1.2.tar.bz2
mkdir -v gcc-build
cd gcc-build/
CC="gcc -B/usr/bin/" ../gcc-4.1.2/configure --prefix=/tools “
--with-local-prefix=/tools --disable-nls --enable-shared --enable-languages=c
make bootstrap
make install
ln -sv gcc /tools/bin/cc
cd ..
rm -rf gcc-build/
rm -rf gcc-4.1.2/

3:Linux-2.6.22.5 API Headers

tar xvf /lfs-sources/linux-2.6.22.5.tar.bz2
cd linux-2.6.22.5/
make mrproper
make headers_check
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/ /tools/include
cd ..
rm -rf linux-2.6.22.5

4:Glibc

tar xvf /lfs-sources/glibc-2.5.1.tar.bz2
cd glibc-2.5.1
mkdir -v ../glibc-build
cd ../glibc-build/
../glibc-2.5.1/configure --prefix=/tools --disable-profile “
--enable-add-ons --enable-kernel=2.6.0 --with-binutils=/tools/bin “
--without-gd --with-headers=/tools/include --without-selinux
make
mkdir -v /tools/etc
touch /tools/etc/ld.so.conf
make install
cd ..
rm -rf glibc-build/
rm -rf glibc-2.5.1/

5:调整并测试工具链

mv -v /tools/bin/
mv -v /tools/$/bin/
mv -v /tools/bin/
ln -sv /tools/bin/ld /tools/$/bin/ld
gcc -dumpspecs sed ‘s@^/lib/ld-linux.so.2@/tools@g‘
`dirname $`/specs
GCC_INCLUDEDIR=`dirname $`/include
find $/ -maxdepth 0 -xtype d -exec rm -rvf ‘‘ “;
rm -vf `grep -l "DO NOT EDIT THIS FILE" $/`
unset GCC_INCLUDEDIR

现在,需要停下来确认新工具链的基本功能是否按预期工作,运行下面的命令做一个简单的合理性检查:

echo ‘main‘ dummy.c
cc dummy.c
readelf -l a.out grep ‘tools‘
[Requesting program interpreter: /tools/lib/ld-linux.so.2] #有这个提示才表示成功
rm -rf a.out dummy.c

6:TCL

tar xvf /lfs-sources/tcl8.4.15-src.tar.gz
cd tcl8.4.15/unix/
./configure --prefix=/tools
make
make install
make install-private-headers
ln -sv tclsh8.4 /tools/bin/tclsh
cd /mnt/lfs/sources/
tar xvf /lfs-sources/expect-5.43.0.tar.gz
cd expect-5.43/
patch -Np1 -i /lfs-sources/expect-5.43.0-spawn-1.patch
cp configure
sed ‘s:/usr/local/bin:/bin:‘ configure.bak configure
./configure --prefix=/tools --with-tcl=/tools/lib --with-tclinclude=/tools/include --with-x=no
make
make SCRIPTS="" install
cd $LFS/sources
tar xvf /lfs-sources/dejagnu-1.4.4.tar.gz
cd dejagnu-1.4.4
./configure --prefix=/tools
make install
cd ..
rm -rf tcl8.4.15
rm -rf expect-5.43
rm -rf dejagnu-1.4.4

7:GCC第二遍

tar xvf /lfs-sources/gcc-4.1.2.tar.bz2
cd gcc-4.1.2
cp -v gcc/Makefile.in
sed true@‘ gcc/Makefile.in.orig gcc/Makefile.in
cp -v gcc/Makefile.in
sed ‘s/^XCFLAGS =$/ -fomit-frame-pointer/‘ gcc/Makefile.in.tmp gcc/Makefile.in
patch -Np1 -i /lfs-sources/gcc-4.1.2-specs-1.patch
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-4.1.2/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
make
make install
cd ..
rm -rf gcc-build
rm -rf gcc-4.1.2

现在,需要停下来确认GCC的基本功能是否按预期工作,运行下面的命令做一个简单的合理性检查:

echo ‘main‘ dummy.c
cc dummy.c
readelf -l a.out grep ‘tools‘
[Requesting program interpreter: /tools/lib/ld-linux.so.2] #有这个提示才表示成功
rm -rf a.out dummy.c

8:Binutils第二遍

tar xvf /lfs-sources/binutils-2.17.tar.bz2
mkdir -v binutils-build
cd binutils-build
../binutils-2.17/configure --prefix=/tools --disable-nls --with-lib-path=/tools/lib
make
make install
make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib
cp -v ld/ld-new /tools/bin
cd ..
rm -rf binutils-build
rm -rf binutils-2.17

9:Ncurses

tar xvf /lfs-sources/ncurses-5.6.tar.gz
cd ncurses-5.6
./configure --prefix=/tools --with-shared --without-debug --without-ada --enable-overwrite
make
make install
cd ..
rm -rf ncurses-5.6

10:Bash

tar xvf /lfs-sources/bash-3.2.tar.gz
cd bash-3.2
patch -Np1 -i /lfs-sources/bash-3.2-fixes-5.patch
./configure --prefix=/tools --without-bash-malloc
make
make install
ln -vs bash /tools/bin/sh
cd ..
rm -rf bash-3.2

11:Bzip

tar xvf /lfs-sources/bzip2-1.0.4.tar.gz
cd bzip2-1.0.4
make
make PREFIX=/tools install
cd ..
rm -rf bzip2-1.0.4

12:Coreutils

tar xvf /lfs-sources/coreutils-6.9.tar.bz2
cd coreutils-6.9
./configure --prefix=/tools
make
make install
cp -v src/su /tools/bin/su-tools
cd ..
rm -rf coreutils-6.9

13:Diffutils

tar xvf /lfs-sources/diffutils-2.8.1.tar.gz
cd diffutils-2.8.1
./configure --prefix=/tools
make
make install
cd ..
rm -rf diffutils-2.8.1

14:Findutils

tar xvf /lfs-sources/findutils-4.2.31.tar.bz2
cd findutils-4.2.31
./configure --prefix=/tools
make
make install
cd ..
rm -rf findutils-4.2.31

15:Gawk

tar xvf /lfs-sources/gawk-3.1.5.tar.bz2
cd gawk-3.1.5
./configure --prefix=/tools
cat config.h "EOF"
#define HAVE_LANGINFO_CODESET 1
#define HAVE_LC_MESSAGES 1
EOF
make
make install
cd ..
rm -rf gawk-3.1.5

16:Gettext

tar xvf /lfs-sources/gettext-0.16.1.tar.gz
cd gettext-0.16.1
cd gettext-tools
./configure --prefix=/tools --disable-shared
make -C gnulib-lib
make -C src msgfmt
cp -v src/msgfmt /tools/bin
cd $LFS/sources
rm -rf gettext-0.16.1

17:Grep

tar xvf /lfs-sources/grep-2.5.1a.tar.bz2
cd grep-2.5.1a
./configure --prefix=/tools --disable-perl-regexp
make
make install
cd ..
rm -rf grep-2.5.1a

18:Gzip

tar xvf /lfs-sources/gzip-1.3.12.tar.gz
cd gzip-1.3.12
./configure --prefix=/tools
make
make install
cd ..
rm -rf gzip-1.3.12

19:Make

tar xvf /lfs-sources/make-3.81.tar.bz2
cd make-3.81
./configure --prefix=/tools
make
make install
cd ..
rm -rf make-3.81

20:Patch

tar xvf /lfs-sources/patch-2.5.4.tar.gz
cd patch-2.5.4
./configure --prefix=/tools
make
make install
cd ..
rm -rf patch-2.5.4

21:Perl

tar xvf /lfs-sources/perl-5.8.8.tar.bz2
cd perl-5.8.8
patch -Np1 -i /lfs-sources/perl-5.8.8-libc-2.patch
./configure.gnu --prefix=/tools -Dstatic_ext=‘Data/Dumper Fcntl IO POSIX‘
make perl utilities
cp -v perl pod/pod2man /tools/bin
mkdir -pv /tools/lib/perl5/5.8.8
cp -Rv lib/ /tools/lib/perl5/5.8.8
cd ..
rm -rf perl-5.8.8

22:Sed

tar xvf /lfs-sources/sed-4.1.5.tar.gz
cd sed-4.1.5
./configure --prefix=/tools
make
make install
cd ..
rm -rf sed-4.1.5

23:Tar

tar xvf /lfs-sources/tar-1.18.tar.bz2
cd tar-1.18
./configure --prefix=/tools
make
make install
cd ..
rm -rf tar-1.18

24:Textinfo

tar xvf /lfs-sources/texinfo-4.9.tar.bz2
cd texinfo-4.9
./configure --prefix=/tools
make
make install
cd ..
rm -rf texinfo-4.9

25:Util-linux

tar xvf /lfs-sources/util-linux-2.12r.tar.bz2
cd util-linux-2.12r
sed -i configure
./configure
make -C lib
make -C mount mount umount
make -C text-utils more
cp -v mount/mount text-utils/more /tools/bin
cd ..
rm -rf util-linux-2.12r

26:清理系统垃圾,去掉调试符号 这一步的步骤是可选的,但假如 LFS 分区实在很小则除外;了解哪些东西是不必要的、可以删除的也是有好处的。到目前为止已经安装的可执行程序和库文件包含大约 130 MB 不必要的调试符号,运行下面的命令删除这些符号:

strip --strip-debug /tools/lib/
strip --strip-unneeded /tools/bin/
rm -rf /tools/
exit

 

 

完全手工打造自定义的LINUX(一)

完全手工打造自定义的LINUX(三)

 

» 本文链接地址:https://www.xidige.com/177

打开支付宝扫一扫,即可进行扫码打赏哦

扫码支持
扫码打赏,你说多少就多少

标签:

分享到:

扫一扫 在手机阅读、分享本文

上一篇: 下一篇:
评论区0人评论156人参与

电子邮件地址不会被公开。 必填项已用*标注

*

loading

赞助商广告