LFS笔记 01 预工具链

预工具链是一个过渡工具链,由原工具链生成,用于生成临时工具链。


汇编链接器Binutils

创建目录

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

编译GCC还需要GMP, MPFR, MPC package。

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

时间根据机器配置的不同可能长达数小时,请耐心等待。

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


至此,临时系统准备完毕!

你可能感兴趣的:(ubuntu,lfs)