LFS 7.2 Install - pass1

最近又做了一遍LFS。现在官网以及更新到了7.2版本。

写成自动化脚本。

1。执行:ln -sv $LFS/tools /
2。执行:install-lfs.sh | tee lfs-Install.log

其中install-lfs.sh内容:

# ! /bin/bash

set +h
umask 022
export LC_ALL=POSIX
export LFS=~/Workspace/LFS/7.2
export LFS_TGT=$(uname -m)-lfs-linux-gnu
export PATH=$LFS/tools/bin:$PATH

MAKEFLAG=-j2

function pass1
{
  cd $LFS
  PREFIX=$LFS
  echo PREFIX:=$PREFIX

  # clean history
  if [ $1 -le -1 ]; then
    rm -rf tools/*
    if [ $? -eq 0 ]; then echo "Clean OK...!"; else exit 1; fi
  fi

  # env
  # check /tools
  if [ -L /tools ]; then
    echo "Exist Sysmbol link to tools"
  else
    echo "No Sysmbol link to tools"
  fi

  if [ $1 -le 0 ]; then
    echo LC_ALL:=$LC_ALL
    echo LFS:=$LFS
    echo LFS_TGT:=$LFS_TGT
    echo PATH:=$PATH
  fi

  # binutils
  if [ $1 -le 1 ]; then
    echo "Binutils..."
    if [ -d binutils-2.22  ]
      then echo "Already decompressed...!";
    else
      tar xvf package/binutils-2.22.tar.bz2
      if [ $? -eq 0 ]; then echo "Decompressed...!"; else exit 1; fi
    fi

    cd binutils-2.22
    patch -Np1 -i ../package/binutils-2.22-build_fix-1.patch
    if [ $? -eq 0 ]; then echo "Patch OK...!"; else exit 2; fi
    cd ..

    if [ -d binutils-build ]
      then cd binutils-build; rm -rf *;
    else mkdir binutils-build; cd binutils-build;
    fi

    ../binutils-2.22/configure --prefix=$PREFIX/tools --with-sysroot=$LFS \
                             --with-lib-path=/tools/lib --target=$LFS_TGT \
                             --disable-nls --disable-werror
    if [ $? -eq 0 ]; then echo "Configure OK...!"; else exit 3; fi

    make $MAKEFLAG
    if [ $? -eq 0 ]; then echo "Make OK...!"; else exit 4; fi

    case $(uname -m) in
      x86_64) mkdir -v $PREFIX/tools/lib && ln -sv lib $PREFIX/tools/lib64 ;;
    esac

    make install
    if [ $? -eq 0 ]; then echo "Install OK...!"; else exit 5; fi

    cd ..
    rm -rf binutils-build
    rm -rf binutils-2.22
  fi

  #gcc-4.7.1
  if [ $1 -le 2 ]; then
    echo "GCC..."
    if [ -d gcc-4.7.1 ]
      then echo "Already decompressed...!";
    else
      tar xvf package/gcc-4.7.1.tar.bz2
      if [ $? -eq 0 ]; then echo "Decompressed...!"; else exit 1; fi
    fi

    cd gcc-4.7.1
    if [ ! -d mpc  ]; then tar -zxvf ../package/mpc-1.0.tar.gz; mv -v mpc-1.0 mpc; fi
    if [ ! -d gmp  ]; then tar -Jxvf ../package/gmp-5.0.5.tar.xz; mv -v gmp-5.0.5 gmp; fi
    if [ ! -d mpfr ]; then tar -Jxvf ../package/mpfr-3.1.1.tar.xz; mv -v mpfr-3.1.1 mpfr; fi

    for file in $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
    do
      if [ -e $file.orig ]; then continue; else cp -uv $file{,.orig}; fi
      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

    if [ ! -e gcc/configure.orig ]
    then
      cp gcc/configure{,orig}
      sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure
    fi

    if [ -d ../gcc-build ]; then cd ../gcc-build; rm -rf *;
    else mkdir -v ../gcc-build; cd ../gcc-build;
    fi

    ./../gcc-4.7.1/configure --target=$LFS_TGT --prefix=$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-libmudflap --disable-libssp --disable-libgomp \
                          --disable-libquadmath --enable-languages=c \
                          --with-mpfr-include=$(pwd)/../gcc-4.7.1/mpfr/src \
                          --with-mpfr-lib=$(pwd)/mpfr/src/.libs
    if [ $? -eq 0 ]; then echo "Configure OK...!"; else exit 2; fi

    make $MAKEFLAG
    if [ $? -eq 0 ]; then echo "Make OK...!"; else exit 3; fi

    make install
    if [ $? -eq 0 ]; then echo "Install OK...!"; else exit 4; fi

    lib=`$LFS_TGT-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/'`
    echo $lib
    ln -vs libgcc.a $lib

    cd ..
    rm -rf gcc-build
    rm -rf gcc-4.7.1
  fi

  #linux-header
  if [ $1 -le 3 ]; then
    echo "Linux header..."
    if [ -d linux-3.5.2 ]
      then echo "Already decompressed...!";
    else
      tar xvf package/linux-3.5.2.tar.xz
      if [ $? -eq 0 ]; then echo "Decompressed...!"; else exit 1; fi
    fi

    cd linux-3.5.2
    make mrproper
    if [ $? -eq 0 ]; then echo "mrproper OK...!"; else exit 2; fi

    make headers_check
    if [ $? -eq 0 ]; then echo "headers_check OK...!"; else exit 3; fi

    make INSTALL_HDR_PATH=dest headers_install
    if [ $? -eq 0 ]; then echo "headers_install OK...!"; else exit 4; fi

    cp -rv dest/include/* $PREFIX/tools/include
    cd ..
    rm -rf linux-3.5.2
  fi

  #Glibc
  if [ $1 -le 4 ]; then
    echo "Glibc..."
    if [ -d glibc-2.16.0 ]
      then echo "Already decompressed...!";
    else
      tar xvf package/glibc-2.16.0.tar.xz
      if [ $? -eq 0 ]; then echo "Decompressed...!"; else exit 1; fi
    fi

    cd glibc-2.16.0

    if [ ! -r /usr/include/rpc/types.h ]; then
      echo "Grant read to /usr/include/rpc/types.h"
      su -c 'mkdir -p /usr/include/rpc'
      su -c 'cp -v sunrpc/rpc/*.h /usr/include/rpc'
    fi

    if [ ! -e Makeconfig.orig ]
    then
      cp -v Makeconfig{,.orig}
      sed -i 's/ -lgcc_s//' Makeconfig
    fi

    if [ -d ../glibc-build ]; then cd ../glibc-build; rm -rf *;
    else mkdir -v ../glibc-build; cd ../glibc-build;
    fi

    ../glibc-2.16.0/configure --prefix=$PREFIX/tools --host=$LFS_TGT \
                              --build=$(../glibc-2.16.0/scripts/config.guess) \
                              --disable-profile --enable-add-ons --enable-kernel=2.6.25 \
                              --with-headers=$PREFIX/tools/include \
                              libc_cv_forced_unwind=yes libc_cv_ctors_header=yes libc_cv_c_cleanup=yes
    if [ $? -eq 0 ]; then echo "Configure OK...!"; else exit 2; fi

    make $MAKEFLAG
    if [ $? -eq 0 ]; then echo "Make OK...!"; else exit 3; fi

    make install
    if [ $? -eq 0 ]; then echo "Install OK...!"; else exit 4; fi

    cd ..
    rm -rf glibc-build
    rm -rf glibc-2.16.0
  fi

  #Test GCC
  if [ $1 -le 5 ]; then
    echo "Test GCC..."
    echo 'main(){}' > dummy.c
    $LFS_TGT-gcc dummy.c
    if [ $? -ne 0 ];then exit 1; fi
    if [ -e a.out ];
    then
      readelf -l a.out | grep ': /tools'
      rm -v a.out
    else exit 2;
    fi
    rm -v dummy.c
  fi
}

pass1 -1

3。上面创建 /tools到$LFS/tools的链接必须做,虽然我原以为使用了with-sysyroot 就可以不必了。

但是若把创建链接作为A,设定PREFIX变量(空或者$LFS)作为B。 当 A真B假时,$LFS_TGT-gcc dummy才正常;A真B真和A假时,均会出现错误,错误如下:

 /home/mkkopter/Workspace/LFS/7.2/tools/libexec/gcc/i686-lfs-linux-gnu/4.7.1/collect2 --sysroot=/home/mkkopter/Workspace/LFS/7.2 --eh-frame-hdr -m elf_i386 -dynamic-linker /tools/lib/ld-linux.so.2 /home/mkkopter/Workspace/LFS/7.2/tools/lib/crt1.o /home/mkkopter/Workspace/LFS/7.2/tools/lib/crti.o /home/mkkopter/Workspace/LFS/7.2/tools/lib/gcc/i686-lfs-linux-gnu/4.7.1/crtbegin.o -L/home/mkkopter/Workspace/LFS/7.2/tools/lib/gcc/i686-lfs-linux-gnu/4.7.1 -L/home/mkkopter/Workspace/LFS/7.2/tools/lib/gcc/i686-lfs-linux-gnu/4.7.1/../../../../i686-lfs-linux-gnu/lib -L/home/mkkopter/Workspace/LFS/7.2/tools/lib /tmp/ccuureL3.o -lgcc -lc -lgcc /home/mkkopter/Workspace/LFS/7.2/tools/lib/gcc/i686-lfs-linux-gnu/4.7.1/crtend.o /home/mkkopter/Workspace/LFS/7.2/tools/lib/crtn.o
/home/mkkopter/Workspace/LFS/7.2/tools/lib/gcc/i686-lfs-linux-gnu/4.7.1/../../../../i686-lfs-linux-gnu/bin/ld: cannot find /home/mkkopter/Workspace/LFS/7.2/tools/lib/libc.so.6 inside /home/mkkopter/Workspace/LFS/7.2
/home/mkkopter/Workspace/LFS/7.2/tools/lib/gcc/i686-lfs-linux-gnu/4.7.1/../../../../i686-lfs-linux-gnu/bin/ld: cannot find /home/mkkopter/Workspace/LFS/7.2/tools/lib/libc_nonshared.a inside /home/mkkopter/Workspace/LFS/7.2
/home/mkkopter/Workspace/LFS/7.2/tools/lib/gcc/i686-lfs-linux-gnu/4.7.1/../../../../i686-lfs-linux-gnu/bin/ld: cannot find /home/mkkopter/Workspace/LFS/7.2/tools/lib/ld-linux.so.2 inside /home/mkkopter/Workspace/LFS/7.2
collect2: error: ld returned 1 exit status

4。glibc make check的时候 到一步会出错,报告缺少 lstdc++,这是正常的。


评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值