首先声明这些命令是摘抄自 孙海勇 编著的《手把手教你构建自己的Linux系统》,方便自己操作,做个记录。
因为还没有照着做完,只做到部分,遇到了瓶颈,暂时做个记录。
1.设置环境变量及目录
export SYSDIR=/opt/mylinux
mkdir -pv ${SYSDIR}
mount /dev/sdb2 ${SYSDIR}
mkdir -pv ${SYSDIR}/sources
mkdir -pv ${SYSDIR}/build
chmod -v a+wt ${SYSDIR}/{sources,build}
mkdir -pv ${SYSDIR}/tools
ln -sv ${SYSDIR}/tools /
2.创建用于制造系统的用户
groupadd mylinux
useradd -s /bin/bash -g mylinux -m -k /dev/null/ mylinux
passwd mylinux
chown -v mylinux ${SYSDIR}/tools
chown -v mylinux ${SYSDIR}/sources
chown -v mylinux ${SYSDIR}/build
su - mylinux
3.设置制作用户的环境
cat > ~/.bash_profile << "EOF"
exec env -i HOME=${HOME} TERM=${TERM} PS1='\u:\w\$ ' /bin/bash
EOF
cat > ~/.bashrc << "EOF"
set +h
umask 022
SYSDIR=/opt/mylinux
LC_ALL=POSIX
PATH=/tools/bin:/bin:/usr/bin
DOWNLOADDIR=${SYSDIR}/sources
BUILDDIR=${SYSDIR}/build
export SYSDIR LC_ALL PATH DOWNLOADDIR BUILDDIR
EOF
source ~/.bash_profile
4.主系统为硬盘上的linux系统(恢复)
export SYSDIR=/opt/mylinux
mount /dev/sdb2 ${SYSDIR}
su - mylinux
二.预工具链建立
1.汇编连接器(Binutils)
tar xvf ${DOWNLOADDIR}/binutils-2.20.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/binutils-2.20
mkdir -pv ../binutils-build
cd ../binutils-build
cc="gcc -B/usr/bin/" ../binutils-2.20/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.20
popd
2.编译编译器
tar xvf ${DOWNLOADDIR}/gcc-4.4.2.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gcc-4.4.2
tar xvf ${DOWNLOADDIR}/gmp-4.3.1.tar.bz2
mv gmp-4.3.1 gmp
tar xvf ${DOWNLOADDIR}/mpfr-2.4.2.tar.bz2
mv mpfr-2.4.2 mpfr
mkdir -pv ../gcc-build
cd gcc-build
cc="gcc -B/usr/bin/" ../gcc-4.4.2/configure --prefix=/tools \
--disable-nls \
--disable-multilib --enable-shared \
--enable-languages=c
make bootstrap
make install
ln -vs gcc /tools/bin/cc
cd ..
rm -rf gcc-build
rm -rf gcc-4.4.2
popd
3.正确性检查
type gcc
ls -l /tools/bin/cc | awk -F/tools/bin/ '{print $2}'
ls /tools/bin/$(uname -m)*
gcc -v ${BUILDDIR}/test.c 2>&1 | grep Configured
三.临时工具链
1.内核头文件安装
tar xvf ${DOWNLOADDIR}/linux-2.6.33.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/linux-2.6.33
make mrproper
make headers_check
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /tools/include
cd ..
rm -rf linux-2.6.33
popd
正确性检查
ls /tools/include
2.基本C库
tar xvf ${DOWNLOADDIR}/glibc-2.11.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/glibc-2.11
mkdir -v ../glibc-build
cd ../glibc-build
echo "CFLAGS += -march=i686 -mtune=native" > configparms
../glibc-2.11/configure --prefix=/tools --enable-kernel=2.6.0 \
--without-gd --without-selinux
../glibc-2.11/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.11
popd
3.调整工具链
mv -v /tools/bin/{ld,ld-old}
mv -v /tools/$(gcc -dumpmachine)/bin/{ld,ld-old}
mv -v /tools/bin/{ld-new,ld}
ln -sv /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld
gcc -dumpspecs | sed 's@/lib\(64\)\?/ld@/tools&@g' \
> $(dirname $(gcc -print-libgcc-file-name))/specs
GCC_FIXED=$(dirname $(gcc -print-libgcc-file-name))/include-fixed
find ${GCC_FIXED}/* -maxdepth 0 -xtype d -exec rm -rvf '{}' \;
rm -vf $(grep -l "DO NOT EDIT THIS FILE" ${GCC_FIXED}/*)
unset GCC_FIXED
正确性检查
gcc -B/tools/lib ${BUILDDIR}/test.c
./a.out
4.汇编工具(Binutils)
tar xvf ${DOWNLOADDIR}/binutils-2.20.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/binutils-2.20
mkdir -v ../binutils-build
cd ../binutils-build
../binutils-2.20/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.20
popd
正确性检查
type ld
ldd /tools/bin/ld
type ld-new
gcc -v ${BUILDDIR}/test.c 2>&1 | grep Binutils
5.GCC
tar xvf ${DOWNLOADDIR}/gcc-4.4.2.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gcc-4.4.2
patch -Np1 -i ${DOWNLOADDIR}/gcc-4.4.2-startfiles_fix-1.patch
sed -i.orig 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
sed -i.tmp 's/^T_CFLAGS =$/& -fomit-frame-pointer/' \
gcc/Makefile.in
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_INCLUDE_DIR
#define STANDARD_INCLUDE_DIR "/tools/include/"
#define STANDARD_STARTFILE_PREFIX_1 "tools/lib/"
#define STANDARD_STARTFILE_PREFIX_2 ""' >> $file
touch $file.orig
done
for file in $(find gcc/config -name t-linux64)
do
sed -i.orig '/MULTILIB_OSDIRNAMES/d' $file
done
tar xvf ${DOWNLOADDIR}/gmp-4.3.1.tar.bz2
mv gmp-4.3.1 gmp
tar xvf ${DOWNLOADDIR}/mpfr-2.4.2.tar.bz2
mv mpfr-2.4.2 mpfr
mkdir -pv ../gcc-build
cd ../gcc-build
../gcc-4.4.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 --disable-multilib \
--disable-bootstrap
make
make install
cd ..
rm -r gcc-build
rm -r gcc-4.4.2
popd
正确性检查
type g++
ldd /tools/bin/gcc
6.测试工具集
Tcl安装
tar xvf ${DOWNLOADDIR}/tcl8.5.8-src.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/tcl8.5.8/unix
./configure --prefix=/tools
make
TZ=UTC make test
make install
chmod -v u+w /tools/lib/libtcl8.5.so
make install-private-headers
ln -sv tclsh8.5 /tools/bin/tclsh
Expect安装
tar xvf ${DOWNLOADDIR}/expect-5.43.0.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/expect-5.43
patch -Np1 -i ${DOWNLOADDIR}/expect-5.43.0-spawn-1.patch
patch -Np1 -i ${DOWNLOAddIR}/expect-5.43.0-tcl_8.5.5_fix-1.patch
sed -i.bak 's:/sur/local/bin:/bin:' configure
./configure --prefix=/tools --with-tcl=/tools/lib \
--with-tclinclude=/tools/include -with-x=no
make
make SCRIPTS="" install
popd
Dejagnu安装
tar xvf ${DOWNLOADDIR}/dejagnu-1.4.4.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/dejagnu-1.4.4
./configure -prefix=/tools
make install
popd
删除源代码目录
pushd ${BUILDDIR}
rm -rf tcl8.5.8 expect-5.43 dejagnu-1.4.4
popd
四.临时系统
1.文本交叉函数库(Ncurses)
tar xvf ${DOWNLOADDIR}/ncurses-5.7.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/ncurses-5.7
./configure --prefix=/tools --with-shared --without-debug \
--without-ada --enable-overwrite
make
make install
cd ..
rm -rf ncurses-5.7
popd
正确性检查:
type ncurses5-config
2.Bash
tar xvf ${DOWNLOADDIR}/bash-4.0.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/bash-4.0
patch -Np1 -i ${DOWNLOADDIR}/bash-4.0-fixes-5.patch
./configure --prefix=/tools --without-bash-malloc
make
make install
ln -sv bash /tools/bin/sh
cd ..
rm -rf bash-4.0
popd
正确性检查
ls -l /tools/bin/*sh | grep bash
ldd /tools/bin/bash
3.Bzip2
tar xvf ${DOWNLOADDIR}/bzip2-1.0.5.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/bzip2-1.0.5
make
make PREFIX=/tools install
cd ..
rm -rf bzip2-1.0.5
popd
正确性检查
type bzip2
4.常用命令工具集(Coreutils)
tar xvf ${DOWNLOADDIR}/coreutils-8.2.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/coreutils-8.2
./configure --prefix=/tools \
--enable-install-program=hostname
make
make install
cp -v src/su /tools/bin/su-tools
cd ..
rm -rf coreutils-8.2
popd
正确性检查
type cp
5.文件比较工具(Diffutils)
tar xvf ${DOWNLOADDIR}/diffutils-2.8.7.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/diffutils-2.8.7
./configure --prefix=/tools
make
make install
cd ..
rm -rf diffutils-2.8.7
popd
正确性检查
type diff
6.文件查找工具(Findutils)
tar xvf ${DOWNLOADDIR}/findutls-4.4.2.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/findutils-4.4.2
./configure --prefix=/tools
make
make install
cd ..
rm -rf findutils-4.4.2
popd
正确性检查
type find
7.文本处理工具(Gawk)
tar xvf ${DOWNLOADDIR}/gawk-3.1.7.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gawk-3.1.7
./configure --prefix=/tools
make
make install
cd ..
rm -rf gawk-3.1.7
popd
正确性检查
type gawk
8.国际化语言支持工具(Gettext)
tar xvf ${DOWNLOADDIR}/gettext-0.17.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/gettext-0.17
cd gettext-tools
./configure --prefix=/tools -disable-shared
make -C gnulib-lib
make -C src msgfmt
cp -v src/msgfmt /tools/bin
cd ../..
rm -rf gettext-0.17
popd
正确性检查
type msgfmt
9.文本匹配搜索工具(Grep)
tar xvf ${DOWNLOADDIR}/grep-2.5.4.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/grep-2.5.4
./configure --prefix=/tools --disable-perl-regexp \
--without-included-regex
make
make install
cd ..
rm -rf grep-2.5.4
popd
正确性检查
type grep
10.压缩工具(Gzip)
tar xvf ${DOWNLOADDIR}/gzip-1.3.13.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/gzip-1.3.13
./configure --prefix=/tools
make
make install
cd ..
rm -rf gzip-1.3.13
popd
正确性检查
type gzip
11.宏处理工具(M4)
tar xvf ${DOWNLOADDIR}/m4-1.4.13.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/m4-1.4.13
./configure --prefix=/tools
make
make install
cd ..
rm -rf m4-1.4.13
popd
正确性检查
type m4
12.语法分析工具(Bison)
tar xvf ${DOWNLOADDIR}/bison-2.4.1.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/bison-2.4.1
./configure --prefix=/tools
make
make install
cd ..
rm -rf bison-2.4.1
popd
正确性检查
type bison
13.编译过程控制工具(Make)
tar xvf ${DOWNLOADDIR}/make-3.81.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/make-3.81
./configure --prefix=/tools
make
make install
cd ..
rm -rf make-3.81
popd
正确性检查
type make
14.补丁文件使用工具(Patch)
tar xvf ${DOWNLOADDIR}/patch-2.6.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/patch-2.6
./configure --prefix=/tools
make
make install
cd ..
rm -rf patch-2.6
正确性检查
type patch
15.perl
tar xvf ${DOWNLOADDIR}/perl-5.10.1.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/perl-5.10.1
patch -Np1 -i ${DOWNLOADDIR}/perl-5.10.1-libc-1.patch
sh Configure -des -Dprefix=/tools \
-Dstatic_ext='Data/Dumper Fcntl IO POSIX'
make perl utilities ext/Errno/pm_to_blib
cp -v perl pod/pod2man /tools/bin
mkdir -pv /tools/lib/perl5/5.10.1
cp -Rv lib/* /tools/lib/perl5/5.10.1
cd ..
rm -rf perl-5.10.1
popd
正确性检查
type perl
16.文本流编辑工具(sed)
tar xvf ${DOWNLOADDIR}/sed-4.2.1.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/sed-4.2.1
./configure --prefix=/tools
make
make install
cd ..
rm -rf sed-4.2.1
popd
正确性检查
type sed
17.文件打包工具(Tar)
tar xvf ${DOWNLOADDIR}/tar-1.22.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/tar-1.22
./configure --prefix=/tools
make
make install
cd ..
rm -rf tar-1.22
popd
正确性检查
type tar
18.信息阅读工具(Texinfo)
tar xvf ${DOWNLOADDIR}/texinfo-4.13.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/texinfo-4.13
./configure --prefix=/tools
make
make install
cd ..
rm -rf texinfo-4.13
popd
正确性检查
type info
19.清理临时系统
strip --strip-debug /tools/lib/*
strip --strip-unneeded /tools/{,s}bin/*
rm -rf /tools/{info,man}
20.退出临时系统制作用户
exit
21恢复工作状态
export SYSDIR=/opt/mylinux
mkdir -pv ${SYSDIR}
mount /dev/sdb2 ${SYSDIR}
五.目标系统
1.设置环境变量
export TARGET_DIR=/opt/mylinux
chown -R root:root ${TARGET_DIR}/tools
mkdir -pv ${TARGET_DIR}/{dev,proc,sys}
mknod -m 600 ${TARGET_DIR}/dev/console c 5 1
mknod -m 666 ${TARGET_DIR}/dev/null c 1 3
mount -v --bind /dev ${TARGET_DIR}/dev
mount -vt devpts devpts ${TARGET_DIR}/dev/pts
mount -vt tmpfs shm ${TARGET_DIR}/dev/shm
mount -vt proc proc ${TARGET_DIR}/proc
mount -vt sysfs sysfs ${TARGET_DIR}/sys
chroot "${TARGET_DIR}" /tools/bin/env -i \
HOME=/root TERM="${TERM}" PS1='\u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
/tools/bin/bash --login +h
export DOWNLOADDIR=/sources
export BUILDDIR=/build
检测
export
2.恢复工作状态
export TARGET_DIR=/opt/mylinux
mkdir -pv ${TARGET_DIR}
mount /dev/sdb2 ${TARGET_DIR}
mount -v --bind /dev ${TARGET_DIR}/dev
mount -vt devpts devpts ${TARGET_DIR}/dev/pts
mount -vt tmpfs shm ${TARGET_DIR}/dev/shm
mount -vt proc proc ${TARGET_DIR}/proc
mount -vt sysfs sysfs ${TARGET_DIR}/sys
chroot "${TARGET_DIR}" /tools/bin/env -i \
HOME=/root TERM="${TERM}" PS1='\u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
/tools/bin/bash --login +h
export DOWNLOADDIR=/sources
export BUILDDIR=/build
3.建立目标环境目录
pushd /
mkdir -pv /{bin,boot,{etc/,}opt,home,lib,mnt}
mkdir -pv /{media/{floppy,cdrom},sbin,srv}
mkdir -pv /var/{lock,log,mail,run,spool}
mkdir -pv /var/{opt,cache,lib/{misc,locate},local}
install -dv -m 0750 /root
install -dv -m 1777 /{var/,}tmp
mkdir -pv /usr/{,local/}{bin,include,lib,sbin,src}
mkdir -pv /usr/{,local/}share/{doc,info,locale,man}
mkdir -pv /usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -pv /usr/{,local/}share/man/man{1..8}
for dir in /usr/{,/local}; do
ln -sv share/{man,doc,info} $dir
done
cd /boot
ln -svf . boot
popd
4.建立目标系统用户
cat >/etc/passwd<<"EOF"
root::0:0:root:/root:/bin/bash
bin:x:1:1:bin:/dev/null:/bin/false
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
EOF
cat > /etc/group <<"EOF"
root:x:0:
bin:x:1:
sys:x:2:
kmem:x:3:
tty:x:4:
tape:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
mail:x:34:
nogroup:x:99:
users:x:1000:
EOF
exec /tools/bin/bash --login +h
5.建立必要的文件
ln -sv /tools/bin/{bin,bat,echo,pwd,stty} /bin
ln -sv /tools/bin/perl /usr/bin
ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
ln -sv /tools/lib/libstdc++.so{,.6} /usr/lib
ln -sv bash /bin/sh
touch /etc/mtab
touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
chmod -v 664 /var/run/utmp /var/log/lastlog
六.目标系统工具链的制作
1.内核头文件
tar xvf ${DOWNLOADDIR}/linux-2.6.33.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/linux-2.6.33
make mrproper
make headers_check
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /usr/include
cd ..
rm -rf linux-2.6.33
popd
正确性检查
ls /usr/include
2.GNU基本C库(Glibc)
tar xvf ${DOWNLOADDIR}/glibc-2.11.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/glibc-2.11
DL=$(readelf -l /bin/sh | sed -n \
's@.*interpret.*/tools\(.*\)]$@\1@p')
sed -i "s|libs -o|libs -L/usr/lib -Wl,-dynamic-linker=$DL -o|" \
scripts/test-installation.pl
unset DL
sed -i 's|@BASH@|/bin/bash|' elf/ldd.bash.in
mkdir -v ../glibc-build
cd ../glibc-build
case $(uname -m) in
i?86) echo "CFLAGS += -march=i686 -mtune=native -O3 -pipe" \
> configparms ;;
esac
${BUILDDIR}/glibc-2.11/configure \
--prefix=/usr --disable-profile --enable-add-ons \
--enable-kernel=$(uname -r) --libexecdir=/usr/lib/glibc
make
cp -v ../glibc-2.11/iconvdata/gconv-modules iconvdata
make -k check 2>&1 | tee glibc-check-log
grep Error glibc-check-log
touch /etc/ld.so.conf
make install
make localedata/install-locales
cd ..
rm -rf glibc-2.11
rm -rf glibc-build
popd
cat > /etc/nsswitch.conf << "EOF"
passwd: files
group: files
shadow: files
hosts: files dns
networks: files
protocols: files
services: files
ethers: files
rpc: files
EOF
cp -v --remove-destination /usr/share/zoneinfo/Asia/Shanghai \
/etc/localtime
cat > /etc/ld.so.conf << "EOF"
/usr/local/lib
/opt/lib
EOF
正确性检查
/lib/libc.so.6 | grep "GNU C"
3.调整工具链
mv -v /tools/bin/{ld,ld-old}
mv -v /tools/$(gcc -dumpmachine)/bin/{ld,ld-old}
mv -v /tools/bin/{ld-new,ld}
ln -sv /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld
gcc -dumpspecs | \
sed -e 's@/tools@@g;' \
-e '/\*startfile_prefix_spec:/{n;s@.*@/usr/lib/ @}' \
-e '/\*cpp:/{n;s@$@ -isystem /usr/include@}' > \
$(dirname $(gcc --print-libgcc-file-name))/specs
正确性检查
cat $(dirname $(gcc --print-libgcc-file-name))/specs | grep tools
grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log
rm -v a.out dummy.log
4.ZIP格式支持库(Zlib)
tar xvf ${DOWNLOADDIR}/zlib-1.2.3.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/zlib-1.2.3
patch -Np1 -i ${DOWNLOADDIR}/zlib-1.2.3-fPIC-2.patch
./configure --prefix=/usr --shared
make
make check
make install
mv -v /usr/lib/libz.so.* /lib
ln -svf ../../lib/libz.so.1 /usr/lib/libz.so
chmod -v 644 /usr/lib/libz.a
cd ..
rm -rf zlib-1.2.3
popd
正确性检查
ldd /lib/libz.so.1.2.3
5.汇编器(Binuils)
tar xvf ${DOWNLOADDIR}/binutils-2.20.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/binutils-2.20
rm -fv etc/standards.info
sed -i.bak '/^INFO/s/standards.info //' etc/Makefile.in
mkdir -pv ../binutils-build
cd ../binutils-build
../binutils-2.20/configure --prefix=/usr --enable-shared
make tooldir=/usr
make check
make tooldir=/usr install
cp -v ../binutils-2.20/include/libiberty.h /usr/include
cd ..
rm -rf binutils-build
rm -rf binutils-2.20
popd
正确性检查
type ld
ldd /usr/bin/ld
6.任意精度算法库(GMP)
tar xvf ${DOWNLOADDIR}/gmp-4.3.1.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gmp-4.3.1
./configure --prefix=/usr --build=i686-pc-linux-gnu \
--enable-cxx --enable-mpbsd
make
make check 2>&1 | tee gmp-check-log
awk '/tests passed/{total+=$2} ; END{print total}' gmp-check-log
make install
cd ..
rm -rf gmp-4.3.1
popd
7.高精度浮点数算法库(MPFR)
tar xvf ${DOWNLOADDIR}/mpfr-2.4.1.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/mpfr-2.4.1
./configure --prefix=/usr --enable-thread-safe
make
make check
make install
make html
make install-html
cd ..
rm -rf mpfr-2.4.1
8.GCC
tar xvf ${DOWNLOADDIR}/gcc-4.4.2.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gcc-4.4.2
sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in
case $(uname -m) in
i?86) sed -i 's/^T_CFLAGS =$/& -fomit-frame-pointer/' \
gcc/Makefile.in ;;
esac
sed -i 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-4.4.2/configure --prefix=/usr --libexecdir=/usr/lib \
--enable-shared --enable-threads=posix \
--enable-__cxa_atexit --enable-c99 --enable-long-long \
--disable-multilib --enable-clocale=gnu \
--disable-libstdcxx-pch --enable-languages=c,c++
make
make install
ln -sv ../usr/bin/cpp /lib
ln -sv gcc /usr/bin/cc
cd ..
rm -rf gcc-build
rm -rf gcc-4.4.2
popd
正确性检查
type gcc
ldd /usr/bin/gcc
9.工具链的回测
type cc
ls -l /usr/bin/cc
cc ${BUILDDIR}/test.c -v -Wl,--brtnodr &> dummy.log
readelf -l a.out | grep '/lib'
grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log
grep -B4 '^ /usr/include' dummy.log
grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'
grep "/lib/libc.so.6 " dummy.log
grep found dummy.log
rm -v a.out dummy.log
七.目标系统的制作
1.帮助手册(Man-Pages)
tar xvf ${DOWNLOADDIR}/man-pages-3.23.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/man-pages-3.23
make install
cd ..
rm -rf man-pages-3.23
popd
2.高性能数据库(Berkeley DB)
tar xvf ${DOWNLOADDIR}/db-4.8.24.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/db-4.8.24
pushd build_unxi
../dist/configure --prefix=/usr --enable-compat185 --enable-cxx
make
make docdir=/usr/share/doc/db-4.8.24 install
chown -Rv root:root /usr/share/doc/db-4.8.24
popd
cd ..
rm -rf db-4.8.24
popd
3.阶段性检查
type -p gcc cc g++ c++ ld ar ranlib
find /{,usr/}{bin,sbin,lib}/* -type f -exec ldd '{}' ';' \
2>/dev/null | grep tools
4.文本流编辑工具(Sed)
tar xvf ${DOWNLOADDIR}/sed-4.2.1.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/sed-4.2.1
./configure --prefix=/usr --bindir=/bin \
--htmldir=/usr/share/doc/sed-4.2.1
make
make html
make check
make install
make -C doc install-html
cd ..
rm -rf sed-4.2.1
popd
正确性检查
type -p sed
5.软件包安装信息读取工具(Pkg-config)
tar xvf ${DOWNLOADDIR}/pkg-config-0.23.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/pkg-config-0.23
./configure --prefix=/usr
make
make check
make install
cd ..
rm -rf pkg-config-0.23
popd
6.文本下的鼠标工具(GPM)
tar xvf ${DOWNLOADDIR}/gpm-1.20.6.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gpm-1.20.6
./configure --prefix=/usr --sysconfdir=/etc
make
make install
cp -v conf/gpm-root.conf /etc
cd ..
rm -rf gpm-1.20.6
popd
mkdir -pv /etc/sysconfig
cat > /etc/sysconfig/mouse << "EOF"
MDEVICE="/dev/input/mice"
PROTOCOL="imps2"
GPMOPTS=""
EOF
7.文本环境交互函数库(Ncurses)
tar xvf ${DOWNLOADDIR}/ncurses-5.7.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/ncurses-5.7
patch -Np1 -i ${DOWNLOADDIR}/ncurses-5.7-branch_update-10.patch
patch -Np1 -i ${DOWNLOADDIR}/ncurses-5.7-bash_fix-1.patch
./configure --prefix=/usr \
--with-shared --enable-widec --without-debug
make
make install
mv -v /usr/lib/libncursesw.so.5* /lib
ln -svf ../../lib/libncursesw.so.5 /usr/lib/libncursesw.so
for lib in ncurses form panel menu ; do
rm -vf /usr/lib/lib${lib}.so ;
echo "INPUT(-l${lib}w)" > /usr/lib/lib${lib}.so ;
ln -sfv lib${lib}w.a /usr/lib/lib${lib}.a
done
ln -sfv libncurses++w.a /usr/lib/libncurses++.a
rm -vf /usr/lib/libcursesw.so
echo "INPUT(-lncursesw)" >/usr/lib/libcursesw.so
ln -sfv libncurses.so /usr/lib/libcurses.so
ln -sfv libncursesw.a /usr/lib/libcursesw.a
ln -sfv libncurses.a /usr/lib/libcurses.a
ln -sfv ncursesw5-config /usr/bin/ncurses5-config
mkdir -v /usr/share/doc/ncurses-5.7
cp -v -R doc/* /usr/share/doc/ncurses-5.7
cd ..
rm -rf ncurses-5.7
popd
8.系统常用命令(Util-Linux-ng)
tar xvf ${DOWNLOADDIR}/util-linux-ng-2.16.2.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/util-linux-ng-2.16.2
sed -e 's@etc/adjtime@var/lib/hwclock/adjtime@g' \
-i $(grep -rl '/etc/adjtime' .)
mkdir -pv /var/lib/hwclock
mkdir -pv /var/run/uuidd
./configure --enable-arch --enable-partx --enable-write
make
make install
mv -v /usr/bin/logger /bin
cd ..
rm -r util-linux-ng-2.16.2
popd
正确性检查
type -p arch fdisk hwclock mount umount
9.EXT文件系统管理工具(E2fsprogs)
tar xvf ${DOWNLOADDIR}/e2fsprogs-1.41.9.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/e2fsprogs-1.41.9
mkdir -v build
pushd build
../configure --prefix=/usr --with-root-prefix="" \
--enable-elf-shlibs --disable-libblkid \
--disable-libuuid --disable-uuidd --disable-fsck
make
make check
make install-libs
chmod -v u+w /usr/lib/{libcom_err,libe2p,libext2fs,libss}.a
gunzip -v /usr/share/info/libext2fs.info.gz
install-info --dir-file=/usr/share/info/dir \
/usr/share/info/libext2fs.info
makeinfo -o doc/com_err.info ../lib/et/com_err.texinfo
install -v -m644 doc/com_err.info /usr/share/info
install-info --dir-file=/usr/share/info/dir \
/usr/share/info/com_err.info
popd
cd ..
rm -rf e2fsprogs-1.41.9
popd
正确性检查
type -p fsck.ext3 mkfs.ext3 resize2fs
10.常用命令工具集(Coreutils)
tar xvf ${DOWNLOADDIR}/coreutils-8.2.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/coreutils-8.2
patch -Np1 -i ${DOWNLOADDIR}/coreutils-8.2-uname-1.patch
patch -Np1 -i ${DOWNLOADDIR}/coreutils-8.2-i18n-1.patch
./configure --prefix=/usr \
--enable-no-install-program=kill,uptime
make
make install
mv -v /usr/bin/{cat,chgrp,chmod,chown,cp,date} /bin
mv -v /usr/bin/{dd,df,echo,false,ls,mkdir,mknod} /bin
mv -v /usr/bin/{mv,pwd,rm,rmdir,stty,sync,true,ln,uname} /bin
mv -v /usr/bin/chroot /usr/sbin
mv -v /usr/bin/{head,sleep,nice} /bin
cd ..
rm -rf coreutils-8.2
popd
正确性检查
type -p ls cp cat echo du chroot
11.端口及协议文件(Iana-etc)
tar xvf ${DOWNLOADDIR}/iana-etc-2.30.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/iana-etc-2.30
make
make install
cd ..
rm -rf iana-etc-2.30
12.宏处理工具(M4)
tar xvf ${DOWNLOADDIR}/m4-1.4.13.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/m4-1.4.13
./configure --prefix=/usr
make
make install
cd ..
rm -rf m4-1.4.13
popd
正确性检查
type m4
13.语法分析工具(Bison)
tar xvf ${DOWNLOADDIR}/bison-2.4.1.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/bison-2.4.1
./configure --prefix=/usr
echo '#define YYENABLE_NLS 1' >> config.h
make
make check
make install
cd ..
rm -rf bison-2.4.1
popd
正确性检查
type -p bison yacc
14.常用进程管理工具(Procps)
tar xvf ${DOWNLOADDIR}/procps-3.2.8.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/procps-3.2.8
patch -Np1 -i ${DOWNLOADDIR}/procps-3.2.8-watch_unicode-1.patch
make
make install
cd ..
rm -rf procps-3.2.8
popd
正确性检查
type -p free killall ps top
15.文本匹配搜索工具(Grep)
tar xvf ${DOWNLOADDIR}/grep-2.5.4.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/grep-2.5.4
patch -Np1 -i ${DOWNLOADDIR}/grep-2.5.4-i18n-1.patch
./configure --prefix=/usr \
--bindir=/bin --without-included-regexp
make
make install
cd ..
rm -rf grep-2.5.4
popd
16.行编辑支持库(Readline)
tar xvf ${DOWNLOADDIR}/readline-6.0.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/readline-6.0
sed -i '/MV.*old/d' Makefile.in
sed -i '/{OLDSUFF}/c:' support/shlib-install
patch -Np1 -i ${DOWNLOADDIR}/readline-6.0-fixes-1.patch
./configure --prefix=/usr --libdir=/lib
make SHLIB_LIBS=-lncurses
make install
mv -v /lib/lib{readline,history}.a /usr/lib
rm -v /lib/lib{readline,history}.so
ln -svf ../../lib/libradline.so.6 /usr/lib/libradline.so
ln -svf ../../lib/libhistory.so.6 /usr/lib/libhistory.so
mkdir -v /sur/share/doc/readline-6.0
install -v -m644 doc/*.{ps,pdf,html,dvi} \
/usr/share/doc/readline-6.0
cd ..
rm -rf readline-6.0
popd
17.用户交互环境工具(Bash)
tar xvf ${DOWNLOADDIR}/bash-4.0.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/bash-4.0
patch -Np1 -i ${DOWNLOADDIR}/bash-4.0-fixes-5.patch
./configure --prefix=/usr --bindir=/bin -without-bash-malloc \
--htmldir=/usr/share/doc/bash-4.0 --with-installed-readline
make
make install
cd ..
rm -rf bash-4.0
popd
exec /bin/bash --login +h
正确性检查
readlink -f /bin/sh
18.恢复工作状态
export TARGET_DIR=/opt/mylinux
mkdir -pv ${TARGET_DIR}
mount /dev/sdb2 ${TARGET_DIR}
mount -v --bind /dev ${TARGET_DIR}/dev
mount -vt devpts devpts ${TARGET_DIR}/dev/pts
mount -vt tmpfs shm ${TARGET_DIR}/dev/shm
mount -vt proc proc ${TARGET_DIR}/proc
mount -vt sysfs sysfs ${TARGET_DIR}/sys
chroot "${TARGET_DIR}" /tools/bin/env -i \
HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
/bin/bash --login +h
export DOWNLOADDIR=/download
export BUILDDIR=/build
19.GUN通用库支持工具(Libtool)
tar xvf ${DOWNLOADDIR}/libtool-2.2.6b.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/libtool-2.2.6b
./configure --prefix=/usr
make
make check
make install
cd ..
rm -rf libtool-2.2.6b
popd
20.小型数据库(GDBM)
tar xvf ${DOWNLOADDIR}/gdbm-1.8.3.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/gdbm-1.8.3
./configure --prefix=/usr
make
make install
make install-compat
cd ..
rm -r gdbm-1.8.3
popd
21.常用网络工具集(Inetutils)
tar xvf ${DOWNLOADDIR}/inetutils-1.7.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/inetutils-1.7
chroot "${TARGET_DIR}" /tools/bin/env -i \
HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
/bin/bash --login +h
export DOWNLOADDIR=/download
export BUILDDIR=/build
19.GUN通用库支持工具(Libtool)
tar xvf ${DOWNLOADDIR}/libtool-2.2.6b.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/libtool-2.2.6b
./configure --prefix=/usr
make
make check
make install
cd ..
rm -rf libtool-2.2.6b
popd
20.小型数据库(GDBM)
tar xvf ${DOWNLOADDIR}/gdbm-1.8.3.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/gdbm-1.8.3
./configure --prefix=/usr
make
make install
make install-compat
cd ..
rm -r gdbm-1.8.3
popd
21.常用网络工具集(Inetutils)
tar xvf ${DOWNLOADDIR}/inetutils-1.7.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/inetutils-1.7
./configure --prefix=/usr --libexecdir=/usr/sbin \
--localstatedir=/var --disable-ifconfig \
--disable-logger --disable-syslogd --disable-whois \
--disable-servers
make
make install
mv -v /usr/bin/{hostname,ping,ping6} /bin
mv -v /usr/bin/traceroute /sbin
cd ..
rm -rf inetutils-1.7
正确性检查
type -p ping hostname telnet traceroute
22.脚本语言工具(Perl)
tar xvf ${DOWNLOADDIR}/perl-5.10.1.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/perl-5.10.1
sed -i -e '/^BUILD_ZLIB/ s/True/False/' \
-e '/^INCLUDE\|^LIB/ s|\./zlib-src|/usr/include|' \
-e "s|LIB\s*=./zlib-src|LIB=/usr/lib|" \
ext/Compress-Raw-Zlib/config.in
sh Configure -des -Dprefix=/usr \
-Dvendorprefix=/usr \
-Dman1dir=/usr/share/man/man1 \
-Dman3dir=/usr/share/man/man3 \
-Dpager="/usr/bin/less -isR"
make
make test
make install
cd ..
rm -rf perl-5.10.1
popd
23.自动化配置脚本生成工具(Autoconf)
tar xvf ${DOWNLOADDIR}/autoconf-2.65.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/autoconf-2.65
./configure --prefix=/usr
make
make install
cd ..
rm -rf autoconf-2.65
popd
24.自动化编译脚本生成工具(Automake)
tar xvf ${DOWNLOADDIR}/automake-1.11.1.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/automake-1.11.1
./configure --prefix=/usr \
--docdir=/usr/share/doc/automake-1.11.1
make
make install
cd ..
rm -rf automake-1.11.1
popd
25.压缩工具(Bzip2)
tar xvf ${DOWNLOADDIR}/bzip2-1.0.5.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/bzip2-1.0.5
patch -Np1 -i ${DOWNLOADDIR}/bzip2-1.0.5-install_docs-1.patch
sed -i -e 's:ln -s -f $(PREFIX)/bin/:ln -s :' Makefile
make -f Makefile-libbz2_so
make clean
make
make PREFIX=/usr install
cp -v bzip2-shared /bin/bzip2
cp -av libbz2.so* /lib
ln -sv ../../lib/libbz2.so.1.0 /usr/lib/libbz2.so
rm -v /usr/bin/{bunzip2,bzcat,bzip2}
ln -sv bzip2 /bin/bunzip2
ln -sv bzip2 /bin/bzcat
cd ..
rm -rf bzip2-1.0.5
popd
正确性检查
type -p bzip2 bunzip2 bzcat bzless
26.文件比较工具(Diffutils)
tar xvf ${DOWNLOADDIR}/diffutils-2.8.7.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/diffutils-2.8.7
patch -Np1 -i ${DOWNLOADDIR}/diffutils-2.8.7-i18n-1.patch
./configure --prefix=/usr
sed -i 's@\(^#define DEFAULT_EDITOR_PROGRAM \).*@\1"vi"@' \
config.h
touch man/*.1
make
make install
cd ..
rm -rf diffutils-2.8.7
popd
27.文件类型查询工具(File)
tar xvf ${DOWNLOADDIR}/file-5.0.3.tar.gz -C ${builddir}
pushd ${BUILDDIR}/file-5.00
patch -Np1 -i ${DOWNLOADDIR}/file-5.03-new_compressors-1.patch
./configure --prefix=/usr
make
make check
make install
cd ..
rm -rf file-5.03
popd
28.文本处理工具(Gawk)
tar xvf ${DOWNLOADDIR}/gawk-3.1.7.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gawk-3.1.7
./configure --prefix=/usr --libexecdir=/usr/lib
make
make check
make install
mkdir -v /usr/share/doc/gawk-3.1.7
cp -v doc/{awkforai.txt,*.{eps,pdf,jpg}} \
/usr/share/doc/gawk-3.1.7
cd ..
rm -r gawk-3.1.7
正确性检查
make check
29.文件查找工具(Findutils)
tar xvf ${DOWNLOADDIR}/findutils-4.4.2.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/findutils-4.4.2
./configure --prefix=/usr --libexecdir=/usr/lib/findutils \
--localstatedir=/var/lib/locate
make
make check
make install
mv -v /usr/bin/find /bin
sed -i 's@find:=${BINDIR}@find:=/bin@' /usr/bin/updatedb
cd ..
rm -rf findutils-4.4.2
popd
30.程序生成工具(Flex)
tar xvf ${DOWNLOADDIR}/flex-2.5.35.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/flex-2.5.35
patch -Np1 -i ${DOWNLOADDIR}/flex-2.5.35-gcc44-1.patch
./configure --prefix=/usr
make
make check
make install
ln -sv libfl.a /usr/bin/libl.a
mkdir -v /usr/share/doc/flex-2.5.35
cd ..
rm -r flex-2.5.35
popd
cat >/usr/bin/lex<<"EOF"
#!/bin/sh
exec /usr/bin/flex -l "$@"
EOF
chmod -v 755 /usr/bin/lex
31.国际化语言支持工具(Gettext)
tar xvf