LFS筆記 01 預工具鏈

預工具鏈是一個過渡工具鏈,由原工具鏈生成,用於生成臨時工具鏈。 linux


彙編連接器Binutils c++

建立目錄 shell

mkdir -v ../binutils-build
cd ../binutils-build
configure
../binutils-2.23.1/configure     \
    --prefix=/tools            \
    --with-sysroot=$LFS        \
    --with-lib-path=/tools/lib \
    --target=$LFS_TGT          \
    --disable-nls              \
    --disable-werror
make & install
make
make install
若是使用amd64做爲宿主系統,須要在make install以前建立到/tools/lib64的軟連接
make
case $(uname -m) in
  x86_64) mkdir -v /tools/lib && ln -sv lib /tools/lib64 ;;
esac
make install


編譯器GCC bootstrap

編譯GCC還須要GMP, MPFR, MPC package。 bash

tar -Jxf ../mpfr-3.1.1.tar.xz
mv -v mpfr-3.1.1 mpfr
tar -Jxf ../gmp-5.1.1.tar.xz
mv -v gmp-5.1.1 gmp
tar -zxf ../mpc-1.0.1.tar.gz
mv -v mpc-1.0.1 mpc

更改gcc動態連接器到/tools 框架

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
Glibc兼容性

sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure
makeinfo兼容性
sed -i 's/BUILD_INFO=info/BUILD_INFO=/' gcc/configure
建立文件夾
mkdir -v ../gcc-build
cd ../gcc-build
configure
../gcc-4.7.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-libmudflap       \
    --disable-libssp           \
    --disable-libgomp          \
    --disable-libquadmath      \
    --enable-languages=c       \
    --with-mpfr-include=$(pwd)/../gcc-4.7.2/mpfr/src \
    --with-mpfr-lib=$(pwd)/mpfr/src/.libs

make & install 編輯器

時間根據機器配置的不一樣可能長達數小時,請耐心等待。 ide

make
make install

給libgcc.a建立軟連接 工具

ln -sv libgcc.a `$LFS_TGT-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/'`


Linux Headers內核頭文件(linux-3.8.1.tar.xz) 測試

make mrproper
make & install
make headers_check
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /tools/include


C庫Glibc

檢查rpc headers

if [ ! -r /usr/include/rpc/types.h ]; then
  su -c 'mkdir -p /usr/include/rpc'
  su -c 'cp -v sunrpc/rpc/*.h /usr/include/rpc'
fi
建立文件夾
mkdir -v ../glibc-build
cd ../glibc-build
configure
../glibc-2.17/configure                             \
      --prefix=/tools                                 \
      --host=$LFS_TGT                                 \
      --build=$(../glibc-2.17/scripts/config.guess) \
      --disable-profile                               \
      --enable-kernel=2.6.25                          \
      --with-headers=/tools/include                   \
      libc_cv_forced_unwind=yes                       \
      libc_cv_ctors_header=yes                        \
      libc_cv_c_cleanup=yes

make & install

所需時間與GCC差很少。

make
make install
檢查
echo 'main(){}' > dummy.c
$LFS_TGT-gcc dummy.c
readelf -l a.out | grep ': /tools'

若是沒有問題的話,應該有以下輸出

[Requesting program interpreter: /tools/lib/ld-linux.so.2]
刪除無用文件
rm -v dummy.c a.out


Binutils彙編連接器第二次

建立文件夾

mkdir -v ../binutils-build
cd ../binutils-build

configure設置ld命令共享庫查找路徑

CC=$LFS_TGT-gcc            \
AR=$LFS_TGT-ar             \
RANLIB=$LFS_TGT-ranlib     \
../binutils-2.23.1/configure \
    --prefix=/tools        \
    --disable-nls          \
    --with-lib-path=/tools/lib
make & install
make
make install
創建新ld命令
make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib
cp -v ld/ld-new /tools/bin


編譯器GCC第二次

一些小改動

cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
  `dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include-fixed/limits.h
cp -v gcc/Makefile.in{,.tmp}
sed 's/^T_CFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in.tmp \
  > gcc/Makefile.in
更改GCC連接器位置
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 -Jxf ../mpfr-3.1.1.tar.xz
mv -v mpfr-3.1.1 mpfr
tar -Jxf ../gmp-5.1.1.tar.xz
mv -v gmp-5.1.1 gmp
tar -zxf ../mpc-1.0.1.tar.gz
mv -v mpc-1.0.1 mpc
兼容性改動
sed -i 's/BUILD_INFO=info/BUILD_INFO=/' gcc/configure
文件夾
mkdir -v ../gcc-build
cd ../gcc-build
configure
CC=$LFS_TGT-gcc \
AR=$LFS_TGT-ar                  \
RANLIB=$LFS_TGT-ranlib          \
../gcc-4.7.2/configure          \
    --prefix=/tools             \
    --with-local-prefix=/tools  \
    --with-native-system-header-dir=/tools/include \
    --enable-clocale=gnu        \
    --enable-shared             \
    --enable-threads=posix      \
    --enable-__cxa_atexit       \
    --enable-languages=c,c++    \
    --disable-libstdcxx-pch     \
    --disable-multilib          \
    --disable-bootstrap         \
    --disable-libgomp           \
    --with-mpfr-include=$(pwd)/../gcc-4.7.2/mpfr/src \
    --with-mpfr-lib=$(pwd)/mpfr/src/.libs
make & install
make
make install
之後使用臨時工具鏈的GCC
ln -sv gcc /tools/bin/cc
檢查,生成腳本並執行
echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep ': /tools'
輸出應該是

[Requesting program interpreter: /tools/lib/ld-linux.so.2]

清理垃圾

rm -v dummy.c a.out


Tcl

全稱是Tool Command Language。

configure

cd unix
./configure --prefix=/tools
make & install
make
make install 

增長寫權限,一會須要移除。

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

安裝tcl headers,後面的package編譯須要。

make install-private-headers

建立軟連接。

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


Expect自動交互工具

使用tcl的腳本語言。能夠自動的完成如Yes/No之類的交互。

cp -v configure{,.orig}
sed 's:/usr/local/bin:/bin:' configure.orig > configure

configure

./configure --prefix=/tools --with-tcl=/tools/lib \
  --with-tclinclude=/tools/include

make & install

make
make install


DejaGNU測試框架

configure

./configure --prefix=/tools
make & install
make install


Check C測試框架

configure

./configure --prefix=/tools
make & install
make
make install
注意!以上部分在個人機器上出錯。
/tools/lib/libpthread.so.0: could not read symbols: Invalid operation

google後,有了答案,須要加上LDFLAGS=-pthread參數

configure

CFLAGS="-L/tools/lib -lpthread" ./configure --prefix=/tools
make & install
CFLAGS="-L/tools/lib -lpthread" make
make install


Ncurses提供獨立於終端的基於文本的用戶界面支持

configure

./configure --prefix=/tools --with-shared \
    --without-debug --without-ada --enable-overwrite
make & install
make
make install


Bash最經典的shell

打patch

patch -Np1 -i ../bash-4.2-fixes-11.patch
configure
./configure --prefix=/tools --without-bash-malloc
make & install
make
make install
建立軟連接
ln -sv bash /tools/bin/sh


Bzip2解壓縮工具

make & install

make
make PREFIX=/tools install


Coreutils經常使用命令集

configure

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


Diffutils文本比較工具

Glibc兼容性fix

sed -i -e '/gets is a/d' lib/stdio.in.h
configure
./configure --prefix=/tools

make & install

make
make install


File文件類型檢測工具

configure

./configure --prefix=/tools
make & install
make
make install


Findutils文件查找工具

configure

./configure --prefix=/tools
make & install
make
make install


Gawk GNU發行的awk語言

configure

./configure --prefix=/tools
make & install
make
make install


Gettext國際化工具

configure

cd gettext-tools
EMACS="no" ./configure --prefix=/tools --disable-shared
make
make -C gnulib-lib
make -C src msgfmt
install
cp -v src/msgfmt /tools/bin


Grep支持正則的搜索工具

configure

./configure --prefix=/tools
make & install
make
make install


Gzip解壓縮工具

configure

./configure --prefix=/tools
make & install
make
make install


M4宏處理工具

Glibc兼容性fix

sed -i -e '/gets is a/d' lib/stdio.in.h
configure
./configure --prefix=/tools
make & install
make
make install


make構建工具

configure

./configure --prefix=/tools
make & install
make
make install


Patch打補丁工具

configure

./configure --prefix=/tools
make & install
make
make install


Perl寫一次就扔的語言

打補丁

patch -Np1 -i ../perl-5.16.2-libc-1.patch
configure
sh Configure -des -Dprefix=/tools
make
make
install
cp -v perl cpan/podlators/pod2man /tools/bin
mkdir -pv /tools/lib/perl5/5.16.2
cp -Rv lib/* /tools/lib/perl5/5.16.2


Sed基於流的文本編輯器

configure

./configure --prefix=/tools
make & install
make
make install


Tar打包工具

Glibc兼容性fix

sed -i -e '/gets is a/d' gnu/stdio.in.h
configure
./configure --prefix=/tools

make & install

make
make install


Texinfo info文檔工具

configure

./configure --prefix=/tools

make & install

make
make install


Xz解壓縮工具

configure

./configure --prefix=/tools
make & install
make
make install


清理系統(可選步驟)

去除debug信息

strip --strip-debug /tools/lib/*
strip --strip-unneeded /tools/{,s}bin/*
刪除文檔
rm -rf /tools/{,share}/{info,man,doc}


更改tools目錄權限

首先,添加lfs用戶到sudoers中。

登出lfs

exit

確認已經添加LFS環境變量。

export LFS=/mnt/lfs

從次之後將使用root,lfs賬號再也不使用。如不這樣作,還須要在未來的LFS系統中添加用戶lfs。

chown -R root:root $LFS/tools

根據登出後的賬號權限不一樣,可能須要sudo

sudo chown -R root:root $LFS/tools


至此,臨時系統準備完畢!

相關文章
相關標籤/搜索