zoukankan      html  css  js  c++  java
  • LFS7.10——构造临时Linux系统

    参考:LFS编译——准备Host系统

    前言

    在准备好Host环境后,接下来构造一个临时Linux系统。该系统包含****构建所需要的工具。构造临时Linux系统分两步:

    构建一个宿主系统无关的新工具链(编译器、汇编器、链接器、库和一些有用的工具)
    使用该工具链构建其它的基础工具。

    编译binutils-阶段1

    解压binutils-2.27.tar.bz2包

    tar -xvf binutils-2.27.tar.bz2
    View Code

    binutils作为第一个要编译的包,提供了linker、assembler以及其他处理目标文件(object files)的工具

    创建一个专用的编译目录

    mkdir -v build
    cd build
    View Code

    编译binutils

    ../configure --prefix=/tools 
    --with-sysroot=$LFS 
    --with-lib-path=/tools/lib 
    --target=$LFS_TGT 
    --disable-nls 
    --disable-werror
    View Code
    make
    View Code
    case $(uname -m) in
    x86_64) mkdir -v /tools/lib && ln -sv lib /tools/lib64 ;;
    esac
    View Code
    make install
    View Code

    编译gcc-阶段1

    解压gcc-6.2.0.tar.bz2

    tar -xvf gcc-6.2.0.tar.bz2 
    View Code

    GCC 需要 GMP、 MPFR 和 MPC 软件包

    cd gcc-6.2.0
    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
    View Code

    更改gcc默认动态链接器的位置,转而使用/tools下面的。他是在gcc搜索路径中移除/usr/include

    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
    View Code

    单独建一个目录编译gcc

    lfs:/mnt/lfs/sources/gcc-6.2.0$ pwd
    /mnt/lfs/sources/gcc-6.2.0
    lfs:/mnt/lfs/sources/gcc-6.2.0$ mkdir -v build
    mkdir: created directory 'build'
    View Code
    ../configure 
    --target=$LFS_TGT 
    --prefix=/tools 
    --with-glibc-version=2.11 
    --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-libmpx 
    --disable-libquadmath 
    --disable-libssp 
    --disable-libvtv 
    --disable-libstdcxx 
    --enable-languages=c,c++
    View Code
    make -j4
    View Code
    make install
    View Code

    cd /mnt/lfs/sources

    rm -rf gcc-6.2.0

    编译linux-4.7.2

    Linux内核需要向系统C库(LFS下指的是Glibc)暴露API接口。

    解压linux-4.7.2.tar.xz

    tar -xvf linux-4.7.2.tar.xz
    View Code

    make mrproper

    make INSTALL_HDR_PATH=dest headers_install

    cp -rv dest/include/* /tools/include

    编译Glibc-2.24

    tar -xvf glibc-2.24.tar.xz  

    cd glibc-2.24 

    mkdir -v build
    cd build/

    ../configure 
    --prefix=/tools 
    --host=$LFS_TGT 
    --build=$(../scripts/config.guess) 
    --enable-kernel=2.6.32 
    --with-headers=/tools/include 
    libc_cv_forced_unwind=yes 
    libc_cv_c_cleanup=yes
    View Code

    make -j4

    make install

    cd ../..

    rm -rf glibc-2.24(其实前面那些编译完的包都可以删除)

    echo 'int 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]

    rm -v dummy.c a.out

    编译Libstdc++

    Libstdc++是gcc的一部分,他的编译工作还是在gcc目录下完成

    tar -xvf gcc-6.2.0.tar.bz2

    cd gcc-6.2.0

    mkdir -v build

    cd build/

    ../libstdc++-v3/configure 
    --host=$LFS_TGT 
    --prefix=/tools 
    --disable-multilib 
    --disable-nls 
    --disable-libstdcxx-threads 
    --disable-libstdcxx-pch 
    --with-gxx-include-dir=/tools/$LFS_TGT/include/c++/6.2.0
    View Code

    make -j4

    make install

    cd ../..

    rm -rf  gcc-6.2.0

    编译Binutils-阶段2

    tar -xvf binutils-2.27.tar.bz2 

    mkdir -v build

    cd build

    CC=$LFS_TGT-gcc 
    AR=$LFS_TGT-ar 
    RANLIB=$LFS_TGT-ranlib 
    ../configure 
    --prefix=/tools 
    --disable-nls 
    --disable-werror 
    --with-lib-path=/tools/lib 
    --with-sysroot
    View Code

    make -j4

    make install

    cd ../..

    编译gcc-阶段2

    tar -xvf gcc-6.2.0.tar.bz2

    cd gcc-6.2.0

    cat gcc/limitx.h gcc/glimits.h gcc/limity.h > 
    `dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include-fixed/limits.h
    View Code
    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
    View Code
    tar -xf ../mpfr-3.1.4.tar.xz
    mv -v mpfr-3.1.4 mpfr
    tar -xf ../gmp-6.1.1.tar.xz
    mv -v gmp-6.1.1 gmp
    tar -xf ../mpc-1.0.3.tar.gz
    mv -v mpc-1.0.3 mpc
    View Code

    mkdir -v build
    cd build

    CC=$LFS_TGT-gcc 
    CXX=$LFS_TGT-g++ 
    AR=$LFS_TGT-ar 
    RANLIB=$LFS_TGT-ranlib 
    ../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
    View Code

    make -j4

    make install

    ln -sv gcc /tools/bin/cc

    cd ../../

    echo 'int main(){}' > dummy.c
    cc dummy.c
    readelf -l a.out | grep ': /tools'
    View Code

    输出:[Requesting program interpreter: /tools/lib/ld-linux.so.2]表示一切顺利

    rm -v dummy.c a.out

    编译Tcl-core

    tar -xvf tcl-core8.6.6-src.tar.gz 

    cd tcl8.6.6/

    cd unix

    ./configure --prefix=/tools

    make -j4

    TZ=UTC make test

    make install

    chmod -v u+w /tools/lib/libtcl8.6.so

    make install-private-headers

    ln -sv tclsh8.6 /tools/bin/tclsh

    cd ../..

    rm -rf tcl8.6.6/

    编译Expect

    tar -xvf 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
    View Code

    make -j4

    make SCRIPTS="" install

    cd ..

    rm -rf expect5.45

    编译DejaGNU

    tar -xvf dejagnu-1.6.tar.gz
    cd dejagnu-1.6

    ./configure --prefix=/tools

    make install

    make check

    编译Check

    tar -xvf check-0.10.0.tar.gz

    cd check-0.10.0

    PKG_CONFIG= ./configure --prefix=/tools

    make -j4

    make check

    make install

    编译Ncurses

    tar -xvf ncurses-6.0.tar.gz 

    cd ncurses-6.0

    sed -i s/mawk// configure

    ./configure --prefix=/tools 
    --with-shared 
    --without-debug 
    --without-ada 
    --enable-widec 
    --enable-overwrite
    View Code

    make -j8
    make install

    cd ..

    rm -rf ncurses-6.0

    编译Bash

    tar -xvf bash-4.3.30.tar.gz
    cd bash-4.3.30
    ./configure --prefix=/tools --without-bash-malloc
    make -j8
    make install

    cd ..

    rm -rf bash-4.3.30

    编译Bzip2

    tar -xvf bzip2-1.0.6.tar.gz

    cd bzip2-1.0.6

    make 

    make PREFIX=/tools install

    cd ..

    rm -rf bzip2-1.0.6

    编译Coreutils

    tar -xvf coreutils-8.25.tar.xz

    cd coreutils-8.25

    ./configure --prefix=/tools --enable-install-program=hostname

    make -j8

    make install

    编译Diffutils

    tar -xvf diffutils-3.5.tar.xz 

    cd diffutils-3.5

    ./configure --prefix=/tools

    make -j8

    make install

    cd ..

    rm -rf diffutils-3.5

    编译File

    tar -xvf file-5.28.tar.gz

    cd file-5.28

    ./configure --prefix=/tools

    make -j8

    make install

    cd ..

    rm -rf file-5.28

    编译Findutils

    tar -xvf findutils-4.6.0.tar.gz
    cd findutils-4.6.0
    ./configure --prefix=/tools
    make -j8
    make install
    cd ..
    rm -rf findutils-4.6.0

    安装Gawk

    tar -xvf gawk-4.1.3.tar.xz
    cd gawk-4.1.3
    ./configure --prefix=/tools
    make -j8
    make install
    cd ..
    rm -rf gawk-4.1.3

    编译Gettext

    tar -xvf gettext-0.19.8.1.tar.xz
    cd gettext-0.19.8.1
    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
    cd ../..
    rm -rf gettext-0.19.8.1

    编译Grep

    tar -xvf grep-2.25.tar.xz
    cd grep-2.25
    ./configure --prefix=/tools
    make -j8
    make install
    cd ..
    rm -rf grep-2.25

    编译Gzip

    tar -xvf gzip-1.8.tar.xz
    cd gzip-1.8
    ./configure --prefix=/tools
    make -j8
    make install
    cd ..
    rm -rf gzip-1.8

    编译M4

    tar -xvf m4-1.4.17.tar.xz
    cd m4-1.4.17
    ./configure --prefix=/tools
    make -j8
    make install
    cd ..
    rm -rf m4-1.4.17

    编译Make

    tar -xvf make-4.2.1.tar.bz2
    cd make-4.2.1
    ./configure --prefix=/tools --without-guile
    make -j8
    make install

    cd ..

    rm -rf m4-1.4.17

    编译Patch

    tar -xvf patch-2.7.5.tar.xz
    cd patch-2.7.5
    ./configure --prefix=/tools
    make -j8
    make install
    cd ..
    rm -rf patch-2.7.5

    编译Perl

    tar -xvf perl-5.24.0.tar.bz2
    cd perl-5.24.0
    sh Configure -des -Dprefix=/tools -Dlibs=-lm
    make -j8
    cp -v perl cpan/podlators/scripts/pod2man /tools/bin
    mkdir -pv /tools/lib/perl5/5.24.0
    cp -Rv lib/* /tools/lib/perl5/5.24.0
    cd ..
    rm -rf perl-5.24.0

    编译Sed

    tar -xvf sed-4.2.2.tar.bz2
    cd sed-4.2.2
    ./configure --prefix=/tools
    make -j8
    make install
    cd ..
    rm -rf sed-4.2.2

    编译Tar

    tar -xvf tar-1.29.tar.xz
    cd tar-1.29
    ./configure --prefix=/tools
    make -j8
    make install
    cd ..
    rm -rf tar-1.29

    编译Texinfo

    tar -xvf texinfo-6.1.tar.xz
    cd texinfo-6.1
    ./configure --prefix=/tools
    make -j8
    make install
    cd ..
    rm -rf texinfo-6.1

    编译Util-linux

    tar -xvf util-linux-2.28.1.tar.xz
    cd util-linux-2.28.1

    ./configure --prefix=/tools 
    --without-python 
    --disable-makeinstall-chown 
    --without-systemdsystemunitdir 
    PKG_CONFIG=""
    View Code

    make -j8
    make install
    cd ..
    rm -rf util-linux-2.28.1

    编译Xz

    tar -xvf xz-5.2.2.tar.xz
    cd xz-5.2.2
    ./configure --prefix=/tools
    make -j8
    make install
    cd ..
    rm -rf xz-5.2.2

  • 相关阅读:
    @bzoj
    @bzoj
    @codeforces
    @codeforces
    @bzoj
    @codeforces
    @codeforces
    @codeforces
    @NOIP2018
    反转字符串--C和Python
  • 原文地址:https://www.cnblogs.com/kelamoyujuzhen/p/9174044.html
Copyright © 2011-2022 走看看