- 论坛徽章:
- 0
|
tar xvf patch_and_config-2.0.tar.bz2 -C ${DOWNLOADDIR}
建立目标系统目录结构
pushd ${TARGET_DIR}
mkdir -pv {bin,boot,dev,{etc/,}opt,home,lib,mnt}
mkdir -pv {proc,media/{floppy,cdrom},sbin,srv,sys}
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
ln -svf lib lib64
ln -svf lib lib32
ln -svf lib usr/lib64
ln -svf lib usr/lib32
cd boot
ln -svf . boot
popd
创建必要的用户、组和日志文件
cat > ${TARGET_DIR}/etc/passwd << "EOF"
root::0:0:root:/root:/bin/bash
EOF
cat > ${TARGET_DIR}/etc/group << "EOF"
root :0:
bin :1:
sys :2:
kmem :3:
tty :4:
tape :5:
daemon :6:
floppy :7:
disk :8:
lp :9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
EOF
touch ${TARGET_DIR}/var/run/utmp ${TARGET_DIR}/var/log/{btmp,lastlog,wtmp}
chmod -v 664 ${TARGET_DIR}/var/run/utmp ${TARGET_DIR}/var/log/lastlog
制作交叉工具链
内核头文件(Linux-Header)
tar xvf ${DOWNLOADDIR}/linux-2.6.29.2.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/linux-2.6.29.2
make mrproper
make ARCH=mips headers_check
make ARCH=mips INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* ${TARGET_DIR}/usr/include
cd ..
rm -rf linux-2.6.29.2
popd
Binutils交叉工具
tar xvf ${DOWNLOADDIR}/binutils-2.19.1.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/binutils-2.19.1
patch -Np1 -i ${DOWNLOADDIR}/binutils-2.19.1-loongson2f-1.patch
mkdir -pv ../binutils-build
cd ../binutils-build
CC="gcc" AR="ar" ../binutils-2.19.1/configure --prefix=${TARGET_DIR}/cross-tools \
--build=${CROSS_HOST} --target=${CROSS_TARGET} --host=${CROSS_HOST} \
--enable-64-bit-bfd --with-sysroot=${TARGET_DIR} \
--disable-nls --enable-shared
make configure-host
make
make install
cp -v ../binutils-2.19.1/include/libiberty.h ${TARGET_DIR}/usr/include
cd ..
rm -rf binutils-build
rm -rf binutils-2.19.1
popd
GCC交叉工具(仅支持C语言)
tar xvf ${DOWNLOADDIR}/gcc-4.4.0.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gcc-4.4.0
mkdir -pv ../gcc-build
cd ../gcc-build
../gcc-4.4.0/configure --prefix=${TARGET_DIR}/cross-tools \
--host=${CROSS_HOST} --build=${CROSS_HOST} --target=${CROSS_TARGET} \
--with-sysroot=${TARGET_DIR} \
--disable-multilib --with-newlib \
--disable-nls --disable-shared --disable-threads --enable-languages=c \
--with-abi=${MABI}
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc
cd ..
rm -r gcc-build
rm -r gcc-4.4.0
popd
目标系统的glibc
tar xvf ${DOWNLOADDIR}/glibc-2.9-latest.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/glibc-2.9-*
tar xvf ${DOWNLOADDIR}/glibc-2.9-ports-latest.tar.bz2
mv -v glibc-2.9-ports-* ports
patch -Np1 -i ${DOWNLOADDIR}/glibc-2.9-libgcc_eh-1.patch
patch -Np1 -i ${DOWNLOADDIR}/glibc-2.9-localedef_segfault-1.patch
patch -Np1 -i ${DOWNLOADDIR}/glibc-2.9-cross_hacks-2.patch
touch libidn/configure
echo "" > ports/sysdeps/mips/mips64/n64/Makefile
echo "" > ports/sysdeps/mips/mips64/n32/Makefile
echo "" > ports/sysdeps/mips/mips32/Makefile
sed -i "/default) machine=/s/n32/${MABI}/g" ports/sysdeps/mips/preconfigure
mkdir -pv ../glibc-build
cd ../glibc-build
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" >> config.cache
echo "libc_cv_gnu89_inline=yes" >> config.cache
echo "libc_cv_mips_tls=yes" >> config.cache
echo "libc_cv_slibdir=/lib" >> config.cache
echo "install_root=${TARGET_DIR}" > configparms
echo "libdir=/usr/lib" >> configparms
BUILD_CC="gcc" CC="${CROSS_TARGET}-gcc ${BUILD_ARCH} ${BUILD_MABI}" \
AR="${CROSS_TARGET}-ar" RANLIB="${CROSS_TARGET}-ranlib" \
${BUILDDIR}/glibc-2.9-*/configure --prefix=/usr \
--libexecdir=/usr/lib/glibc --host=${CROSS_TARGET} --build=${CROSS_HOST} \
--disable-profile --enable-add-ons --with-tls --enable-kernel=2.6.26 \
--with-__thread --with-binutils=${TARGET_DIR}/cross-tools/bin \
--with-headers=${TARGET_DIR}/usr/include --cache-file=config.cache
make
make install
make localedata/install-locales
cd ..
rm -rf glibc-build
rm -rf glibc-2.9-*
cat > ${TARGET_DIR}/etc/nsswitch.conf << "EOF"
# Begin /etc/nsswitch.conf
passwd: files
group: files
shadow: files
hosts: files dns
networks: files
protocols: files
services: files
ethers: files
rpc: files
# End /etc/nsswitch.conf
EOF
cp -v --remove-destination ${TARGET_DIR}/usr/share/zoneinfo/Asia/Shanghai \
${TARGET_DIR}/etc/localtime
cat > ${TARGET_DIR}/etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf
/usr/local/lib
/opt/lib
# End /etc/ld.so.conf
EOF
popd
GCC交叉工具(支持c和c++语言)
tar xvf ${DOWNLOADDIR}/gcc-4.4.0.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gcc-4.4.0
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-4.4.0/configure --prefix=${TARGET_DIR}/cross-tools --host=${CROSS_HOST} \
--build=${CROSS_HOST} --target=${CROSS_TARGET} \
--with-sysroot=${TARGET_DIR} \
--disable-nls --enable-shared --enable-__cxa_atexit \
--disable-multilib --with-abi=${MABI} \
--enable-c99 --enable-long-long --enable-threads=posix \
--enable-languages=c,c++
make
make install
cd ..
rm -rf gcc-build
rm -rf gcc-4.4.0
popd
File软件包
tar xvf ${DOWNLOADDIR}/file-5.00.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/file-5.00
./configure --prefix=${TARGET_DIR}/cross-tools
make
make install
cd ..
rm -rf file-5.00
popd
Groff软件包
tar xvf ${DOWNLOADDIR}/groff-1.20.1.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/groff-1.20.1
PAGE=A4 ./configure --prefix=${TARGET_DIR}/cross-tools --without-x
make
make install
cd ..
rm -rf groff-1.20.1
popd
Shadow软件包
tar xvf ${DOWNLOADDIR}/shadow-4.1.3.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/shadow-4.1.3
patch -Np1 -i ${DOWNLOADDIR}/shadow-4.1.3-sysroot_hacks-1.patch
echo "shadow_cv_passwd_dir=${TARGET_DIR}/bin" > config.cache
echo "ac_cv_func_lckpwdf=no" >> config.cache
./configure --prefix=${TARGET_DIR}/cross-tools \
--sbindir=${TARGET_DIR}/cross-tools/bin \
--sysconfdir=${TARGET_DIR}/etc --disable-shared --without-libpam \
--without-audit --without-selinux \
--program-prefix=${CROSS_TARGET}- --cache-file=config.cache
cp config.h{,.orig} &&
sed "/PASSWD_PROGRAM/s/passwd/${CROSS_TARGET}-&/" config.h.orig > config.h
make
make install
cd ..
rm -rf shadow-4.1.3
popd
Ncurses软件包
tar xvf ${DOWNLOADDIR}/ncurses-5.7.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/ncurses-5.7
patch -Np1 -i ${DOWNLOADDIR}/ncurses-5.7-bash_fix-1.patch
./configure --prefix=${TARGET_DIR}/cross-tools \
--without-shared
make -C include
make -C progs tic
install -m755 progs/tic ${TARGET_DIR}/cross-tools/bin
cd ..
rm -rf ncurses-5.7
popd
清理交叉工具链
pushd ${TARGET_DIR}/cross-tools
strip --strip-all bin/*
strip --strip-debug lib/*
popd
注意:不正确的清理参数用于库文件的时候有导致库文件 损坏的可能,因此请注意命令的 参数,如果你不放心也可跳过这部分,并不会影响后面的过程。
制作目标系统
环境设置
export CC="${CROSS_TARGET}-gcc ${BUILD_ARCH} ${BUILD_MABI}"
export CXX="${CROSS_TARGET}-g++ ${BUILD_ARCH} ${BUILD_MABI}"
export AR="${CROSS_TARGET}-ar"
export AS="${CROSS_TARGET}-as"
export RANLIB="${CROSS_TARGET}-ranlib"
export LD="${CROSS_TARGET}-ld"
export STRIP="${CROSS_TARGET}-strip"
将环境变量设置到~/.bashrc中,以方便重新进入时自动设置
echo "export CC=\"${CROSS_TARGET}-gcc ${BUILD_ARCH} ${BUILD_MABI}\"" >> ~/.bashrc
echo "export CXX=\"${CROSS_TARGET}-g++ ${BUILD_ARCH} ${BUILD_MABI}\"" >> ~/.bashrc
echo "export AR=\"${CROSS_TARGET}-ar\"" >> ~/.bashrc
echo "export AS=\"${CROSS_TARGET}-as\"" >> ~/.bashrc
echo "export RANLIB=\"${CROSS_TARGET}-ranlib\"" >> ~/.bashrc
echo "export LD=\"${CROSS_TARGET}-ld\"" >> ~/.bashrc
echo "export STRIP=\"${CROSS_TARGET}-strip\"" >> ~/.bashrc
---------man-pages--------------
tar xvf ${DOWNLOADDIR}/man-pages-3.21.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/man-pages-3.21
make prefix=${TARGET_DIR}/usr install
cd ..
rm -rf man-pages-3.21
popd
------------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-1.patch
./configure --prefix=/usr --shared
make AR="${AR} rc"
make prefix=${TARGET_DIR}/usr install
mv -v ${TARGET_DIR}/usr/lib/libz.so.* ${TARGET_DIR}/lib
ln -svf ../../lib/libz.so.1 ${TARGET_DIR}/usr/lib/libz.so
chmod -v 644 ${TARGET_DIR}/usr/lib/libz.a
cd ..
rm -rf zlib-1.2.3
popd
---------Binutils--------
tar xvf ${DOWNLOADDIR}/binutils-2.19.1.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/binutils-2.19.1
patch -Np1 -i ${DOWNLOADDIR}/binutils-2.19.1-loongson2f-1.patch
mkdir -pv ../binutils-build
cd ../binutils-build
../binutils-2.19.1/configure --prefix=/usr \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --target=${CROSS_TARGET} \
--enable-64-bit-bfd --enable-shared
make configure-host
make tooldir=/usr
make DESTDIR=${TARGET_DIR} tooldir=/usr install
cp -v ../binutils-2.19.1/include/libiberty.h ${TARGET_DIR}/usr/include
cd ..
rm -rf binutils-build
rm -rf binutils-2.19.1
popd
---------GMP--------
tar xvf ${DOWNLOADDIR}/gmp-4.3.0.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gmp-4.3.0
./configure --host=${CROSS_TARGET} --prefix=/usr \
--enable-cxx --enable-mpbsd
make
make DESTDIR=${TARGET_DIR} install
rm -v ${TARGET_DIR}/usr/lib/lib{gmp,gmpxx,mp}.la
cd ..
rm -rf gmp-4.3.0
popd
---------MPFR--------
tar xvf ${DOWNLOADDIR}/mpfr-2.4.1.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/mpfr-2.4.1
patch -Np1 -i ${DOWNLOADDIR}/mpfr-2.4.1-branch_update-1.patch
patch -Np1 -i ${DOWNLOADDIR}/mpfr-2.4.1-mips_gcc4.4-1.patch
./configure --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
rm -v ${TARGET_DIR}/usr/lib/libmpfr.la
cd ..
rm -rf mpfr-2.4.1
popd
-----------GCC------------
tar xvf ${DOWNLOADDIR}/gcc-4.4.0.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gcc-4.4.0
patch -Np1 -i ${DOWNLOADDIR}/gcc-4.4.0-pure64-1.patch
cp libiberty/Makefile.in{,.orig} &&
sed 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in.orig \
> libiberty/Makefile.in
cp gcc/gccbug.in{,.orig} &&
sed 's/@have_mktemp_command@/yes/' gcc/gccbug.in.orig > gcc/gccbug.in
cp gcc/Makefile.in{,.orig} &&
sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-4.4.0/configure --prefix=/usr \
--libexecdir=/usr/lib --build=${CROSS_HOST} --host=${CROSS_TARGET} \
--target=${CROSS_TARGET} --enable-shared --enable-threads=posix \
--enable-__cxa_atexit --enable-c99 --enable-long-long \
--disable-multilib --with-abi=${MABI} \
--enable-clocale=gnu --enable-languages=c,c++ --disable-libstdcxx-pch
make
make DESTDIR=${TARGET_DIR} install
ln -sv ../usr/bin/cpp ${TARGET_DIR}/lib
ln -sv gcc ${TARGET_DIR}/usr/bin/cc
cd ..
rm -rf gcc-build
rm -rf gcc-4.4.0
popd
--------Sed-----------
tar xvf ${DOWNLOADDIR}/sed-4.1.5.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/sed-4.1.5
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr \
--bindir=/bin --enable-html
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -rf sed-4.1.5
popd
--------E2fsprogs--------
tar xvf ${DOWNLOADDIR}/e2fsprogs-1.41.5.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/e2fsprogs-1.41.5
mkdir -v build
cd build
../configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} \
--prefix=/usr --with-root-prefix="" \
--enable-elf-shlibs --disable-evms
make
make DESTDIR=${TARGET_DIR} install
make DESTDIR=${TARGET_DIR} install-libs
rm -v ${TARGET_DIR}/usr/lib/lib{blkid,com_err,e2p,ext2fs,ss,uuid}.so
ln -sv ../../lib/libblkid.so.1 ${TARGET_DIR}/usr/lib/libblkid.so
ln -sv ../../lib/libcom_err.so.2 ${TARGET_DIR}/usr/lib/libcom_err.so
ln -sv ../../lib/libe2p.so.2 ${TARGET_DIR}/usr/lib/libe2p.so
ln -sv ../../lib/libext2fs.so.2 ${TARGET_DIR}/usr/lib/libext2fs.so
ln -sv ../../lib/libss.so.2 ${TARGET_DIR}/usr/lib/libss.so
ln -sv ../../lib/libuuid.so.1 ${TARGET_DIR}/usr/lib/libuuid.so
cd ../..
rm -rf e2fsprogs-1.41.5
popd
---------Coreutils-----------
tar xvf ${DOWNLOADDIR}/coreutils-7.2.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/coreutils-7.2
patch -Np1 -i ${DOWNLOADDIR}/coreutils-7.2-uname-1.patch
touch man/hostname.1 man/*.1
cp -v src/Makefile.in{,.orig}
sed -e "/binPROGRAMS_INSTALL=/s:./ginstall:install:" src/Makefile.in.orig \
> src/Makefile.in
cat > config.cache << EOF
fu_cv_sys_stat_statfs2_bsize=yes
gl_cv_func_mbrtowc_incomplete_state=yes
gl_cv_func_mbrtowc_nul_retval=yes
gl_cv_func_mbrtowc_null_arg=yes
gl_cv_func_mbrtowc_retval=yes
gl_cv_func_btowc_eof=yes
gl_cv_func_wcrtomb_retval=yes
gl_cv_func_wctob_works=yes
EOF
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr \
--enable-install-program=hostname \
--enable-no-install-program=kill,uptime --cache-file=config.cache
make
make DESTDIR=${TARGET_DIR} install
mv -v ${TARGET_DIR}/usr/bin/{cat,chgrp,chmod,chown,cp,date} ${TARGET_DIR}/bin
mv -v ${TARGET_DIR}/usr/bin/{dd,df,echo,false,hostname,ls,mkdir} ${TARGET_DIR}/bin
mv -v ${TARGET_DIR}/usr/bin/{mv,pwd,rm,rmdir,stty,true,ln,uname} ${TARGET_DIR}/bin
mv -v ${TARGET_DIR}/usr/bin/chroot ${TARGET_DIR}/usr/sbin
mv -v ${TARGET_DIR}/usr/bin/{[,basename,head,install,nice} ${TARGET_DIR}/bin
mv -v ${TARGET_DIR}/usr/bin/{readlink,sleep,sync,test,touch} ${TARGET_DIR}/bin
ln -svf ../../bin/install ${TARGET_DIR}/usr/bin
cd ..
rm -rf coreutils-7.2
popd
---------Iana_Etc--------
tar xvf ${DOWNLOADDIR}/iana-etc-2.30.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/iana-etc-2.30
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -rf iana-etc-2.30
popd
----------M4------------
tar xvf ${DOWNLOADDIR}/m4-1.4.13.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/m4-1.4.13
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -rf m4-1.4.13
popd
---------Bison---------
tar xvf ${DOWNLOADDIR}/bison-2.4.1.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/bison-2.4.1
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
echo '#define YYENABLE_NLS 1' >> config.h
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -rf bison-2.4.1
popd
--------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 --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr \
--with-shared --enable-widec --without-debug --without-ada \
--with-build-cc="gcc -D_GNU_SOURCE" --libdir=/lib
make
make DESTDIR=${TARGET_DIR} install
mv -v ${TARGET_DIR}/lib/lib{panel,menu,form,ncurses,ncurses++}w.a \
${TARGET_DIR}/usr/lib
rm -v ${TARGET_DIR}/lib/lib{ncurses,menu,panel,form}w.so
ln -svf ../../lib/libncursesw.so.5 ${TARGET_DIR}/usr/lib/libncursesw.so
ln -svf ../../lib/libmenuw.so.5 ${TARGET_DIR}/usr/lib/libmenuw.so
ln -svf ../../lib/libpanelw.so.5 ${TARGET_DIR}/usr/lib/libpanelw.so
ln -svf ../../lib/libformw.so.5 ${TARGET_DIR}/usr/lib/libformw.so
for lib in curses ncurses form panel menu ; do
echo "INPUT(-l${lib}w)" > ${TARGET_DIR}/usr/lib/lib${lib}.so
ln -sfv lib${lib}w.a ${TARGET_DIR}/usr/lib/lib${lib}.a
done
ln -sfv libncursesw.so ${TARGET_DIR}/usr/lib/libcursesw.so
ln -sfv libncursesw.a ${TARGET_DIR}/usr/lib/libcursesw.a
ln -sfv libncurses++w.a ${TARGET_DIR}/usr/lib/libncurses++.a
ln -sfv ncursesw5-config ${TARGET_DIR}/usr/bin/ncurses5-config
ln -sfv ../../usr/share/terminfo ${TARGET_DIR}/usr/lib/terminfo
cd ..
rm -rf ncurses-5.7
popd |
|