Monthly Archives: May 2009

>[GSoC] Summary 2009.05.03 – 2009.05.10

>Coly suggested me to write in English, so I’ll try my best…I’m afraid I can’t express myself exactly.

Another week passed and unfortunately I had to do my work from beginning, as I walked towards a wrong direction. Most of my last twenty-days work became useless. But I’m not sad and don’t worry about it. I got to know what should I do next exactly and how much work left. Below is the detail.

In April I did two things, building rpm in Debian and cross-compiling an OpenSuSE based bootable system.
The cross-compiling stuff didn’t get much progress. I cross-compilied OpenSuSE’s sysvinit, elfutils, udev and rpm to the bootable system, other basic packages(coreutils, bash, zlib etc.) were from upstream. This system was unstable, sometimes I got “unable to determine your tty name” when login. But there was a good news, the cross-compilied rpm was working!
On the other hand, the rpm-building process went smoothly. I built 73 src.rpm packages on Debian. Then in May I got the bad news, I shouldn’t build rpms on Debian.

What should I do is cross-compiling an OpenSuSE based bootable system then building rpms on this system not Debian. So I need to cross-compile many libraries, utilities. After finishing the summary of work before May on May 7th, I started cross-compiling the OpenSuSE bootable building environment. This is the most important work and the foundation of later works. By now I have finished binutils, gmp, mpfr, gcc, sed, libsepol, libselinux, udev, e2fsprogs, and now I’m working on coreutils which has lots of dependency problems.

Have to go to bed now, hope all packages I’ve done are OK.

>Google Summer of Code 2009 第一阶段工作总结及下一阶段工作计划

>

Google Summer of Code 2009 第一阶段工作总结及下一阶段工作计划

关尔昱 2009年5月6日

一、概述

1、目标

本次项目的题目是”Porting OpenSuSE to MIPS Platform“,也就是移植OpenSuSE到MIPS架构上。更具体一些,就是要让OpenSuSE可以跑在以龙芯(loongson2f)作为处理器的Gdium上网本上。当然,要完成的还只是一个可使用的系统原型(没有软件仓库,仅有文本模式,有开发构建其他软件包的环境),要达到真正可发布的程度还需要非常非常多的后期工作,这就不是一个人的力量可以完成的了。
本次项目是由Coly li来指导的,感谢Coly li给于我的巨大帮助!

2、起因

这要追溯到今年的寒假,coly在群里发布了一条消息,问是否有人对移植OpenSuSE到MIPS上感兴趣。从那时开始我就有心做这个项目了,但还有点 犹豫和担心,因为之前没做过这方面的任何东西。当时还不知道会把这个项目放到GSoC上。开学之后,在本学期2月第一次linuxfb活动会场上,我和 coly说了我的意愿,coly很支持,并说可能会被放到GSoC上。我当时的想法是是否被放到GSoC上无所谓,能做这个项目才是重点。
就这样,从2月底开始我就准备各种资料了,熟悉交叉编译和CLFS等等。

3、申请过程

申请的起止日期是2009.03.23 – 2009.04.03,在这期间学生可以提交自己的申请并进行修改。在这之前要到GSoC2009的网站上进行注册。
在3月19号我完成了申请的第一版,我知道这一版存在非常多的问题,但是当时还没有太多的思路,只好厚着脸皮骚扰coly让他帮看一下了。果然coly给 我提了很多非常有用的建议,让我把工作细化,列出每一步所需要的软件包等等。又经过五天的准备,最终完成并提交了申请。最后的申请可以在这里找到。
在等待结果的期间,coly以给我的申请提问题的方式,让我可以进一步补充我的申请和最新的进展,这样其他mentor也都能看到我的进度和所做出的努力。
最终在4月21号的时候,收到了google的邮件,通知我的申请已经被接受了。

二、实现方法

在说明每种实现方法之前,需要大概了解一下目标体系结构。MIPS架构有两种endian,而龙芯(loongson2f)是属于mips64el,也就 是64位的小端。所以要构建的交叉编译环境也是要针对mips64el的。(目前对mips体系结构了解还不多,如果需要还得看很多资料)

1、交叉编译整个系统

首先,建立起针对mips64el的交叉编译环境,其中包括glibc,binutils和gcc。然后建立交叉构建rpm包的环境。第三要交叉构建 rpm包。最后安装这些rpm包。这个方法是最开始coly和我大概说过的一个思路。由于我一开始没很好的理解,而是直接想到了第二种实现方法,所以对这 个方法理解不多。

2、交叉编译基本构建系统

这是我写在申请中的方法。跟上一个方法最重要的区别在于不用交叉构建rpm包了,而是利用qemu来模拟mips环境。
首先还是要建立起交叉编译环境。其次,利用交叉编译环境编译出一个可启动的、可用于开发的基系统。第三,利用qemu来启动这个系统并以此系统为基础构建各个所需的rpm包。最后安装构建好的rpm。具体描述可以参考我的申请
在coly的建议下,之后的工作将采用这个方法来实现。

3、交叉编译可启动基本系统

这是目前所采用的方法。第二种方法最大的不足在于第三步,利用自己交叉编译出来的系统来构建各个rpm包。因为这些rpm包要依赖很多开发库和命令,而要交叉编译这些所需的库很可能陷入依赖关系的噩梦,而且很可能不是所有库都是能以我自己的能力完成交叉编译的。
此方法首先建立起交叉编译环境。其次交叉编译出一个可以启动、可以使用rpm命令安装rpm包的基本系统。第三,利用debian系统的mipsel版本 来构建各个rpm包。最后用qemu来启动交叉编译出来的系统并安装这些rpm包。这个方法的好处就是在构建rpm包的时候,需要什么库都可以用 debian的apt系统来安装,非常方便。但也是需要付出代价的,那就是在qemu中跑的mipsel版的debian很慢,平均编译一个包要在半小时 到一小时之间,最长的是gcc,用了100小时。

以上这些方法的共同点是,都需要构建一个交叉编译环境,并且交叉编译出一个可以启动的基本系统。其不同点在于其他软件包的构建方式。

三、已完成的工作

这一部分内容基本上是一个时间流水帐,记录某段时间都做了什么。

目前已经完成了可启动的、可用rpm命令安装rpm包的基本系统的交叉编译工作。完成了大部分基础rpm包的编译工作。

具体已完成的软件包列表可以查看这三个google doc文档,文档一文档二文档三 。软件包链接地址被标注为蓝色的是已经完成的。

1、2月末 ~ 3月初

这段时间主要在熟悉交叉编译和如何建立交叉编译环境。在这期间找了很多关于建立交叉编译环境和CLFS的资料。发现了一篇教你如何构建龙芯系统的文章,《手把手教你源代码制作龙芯64位系统》 大喜过望,这不就是我所需要的吗。还用kvm安装了好多次opensuse11.1系统,可能因为kvm不够稳定,虚拟机经常死掉然后还不能启动,所以装 了很多次,最后放弃了,还是用vbox安装了opensuse11.1。用的光盘是coly在北邮install festival上带去的dvd光盘。

2、3月初 ~ 3月19

初次尝试建立交叉编译环境,是按照《手把手》这篇文章的说明来编译的,还比较顺利。然后着手开始写申请的第一版。这一版申请内容很空洞,因为我自己对这个 项目需要采取什么样的方法来实现还没有一个很清醒的认识。匆匆写了一个就扔给coly来给提意见了。果然coly提出了很多非常有帮助的建议。coly建 议我要细化,究竟哪些包是需要交叉编译的,那些才能称得上是opensuse等等。

3、3月20 ~ 4月5

在听取了coly的建议之后,辛苦的分析opensuse中需要的各个包的依赖关系,并把哪些步骤需要哪些包都详细记录下来,并且在opensuse的src仓库中找到下载链接。在准备好了这些资料之后,又整理了一下自己的思路,开始写申请的第二版,最后提交了这个版本。

4、4月6 ~ 4月15

在这段期间,coly依然给出了很多建议,并建议我改进我的申请。但当时已经过了提交申请的截止日期,申请都不能修改了,所以coly就在我的申请下发表 评论并提问,让我来回答。我也利用这段时间来交叉编译出一个可启动的基本系统,并尝试用qemu来启动它。虽然最后我没有成功,但我把这一段时间的努力和 进展都以回答coly提问的方式更新了我的申请,对最后的结果产生了很好的推动作用。后来coly说一开始我的排名在15,后来升到了第4。
在这期间所做的工作的详细记录可以查看我的这篇blog。总之最后得出结论,不能用《手把手》那篇文章中的方法来建立交叉编译环境和构建系统,因为那是对龙芯2f做了优化的,而qemu还不支持模拟龙芯。这直接促使我采用第三种实现方法。(其中关于mips的各种编译参数还不是很了解,比如-mabi对最后编译结果的影响等)

5、4月16 ~ 4月30

在发现qemu不支持模拟龙芯之后就放弃了实现方法二,而直接采用现成的debian系统来构建rpm包,同时交叉编译出可启动、可使用rpm命令安装 rpm包的基本系统,这个系统需要使用opensuse的启动脚本来启动。所以这段时间基本就在做两件事情,一是在qemu中跑debian,用来 rpmbuild各个rpm包,二是在建立好交叉编译环境之后,根据sysvinit和rpm这两个包的spec文件中所描述的编译和安装步骤来交叉编译 它们并安装到我的基本系统当中。

6、5月1 ~ 5月8

写总结,并整理思路,进行修整。一直在低头赶路,需要抬头看看走过的和前边的路,并稍做休息。

四、各种困难

1、已解决的困难

  • 如何建立交叉编译环境。(CLFS,CLFS 2.0, 手把手)
  • 如何使用qemu模拟mipsel环境(内核的选择,命令行参数等)
  • 如何利用qemu启动交叉编译出的系统(sysvinit,inittab等)
  • 如何交叉编译insserv、fillup、lzmautils、elfutils、sysvinit、rpm等等(自己写了一个补丁,对rpm的Makefile做简单的修改)
  • 如何用debian系统做rpmbuild环境(rpm配置,patch命令,spec文件等)
  • 利用debian作为rpmbuild的host时遇到的各种编译、打包问题(binutils,glibc等)

2、未解决的问题

  • 某些软件包依赖opensuse的一个内核补丁(sysvinit,hwinfo:ioctl 需要TIOCGDEV命令)
  • 一些opensuse特有的包相互之间的依赖关系严重,构建rpm有困难(aaa_base,permissions,openSUSE-build-key等等)
  • 基系统启动不稳定,有事在login的时候出现 Unable to determine your tty name或者INIT: Id “S0” respawning too fast: disabled for 5 minutes这种错误,时好时坏
  • 一些src.rpm打包出现的错误(kernel-source.src.rpm,opensslapps/openssl: symbol lookup error: apps/openssl: undefined symbol: __gcov_indirect_call_profiler等)

3、以后可能遇到的问题

  • 编译出来的rpm包不能很好的安装在交叉编译出的基系统上(这就麻烦了,弄不好要重新编译所有的rpm包)
  • kernel的编译,可能会出现很多问题
  • 包的依赖关系不好解决,比如上边提到的一些opensuse特有的包和yast相关的包
  • to be continued…

五、下一步计划

在8月20号之前还有3个月13天,去掉15天左右的准备中期检查和做其他事情的时间,还有不到3个月的时间。

1、要完成的任务

1) 分析一些基础包的依赖关系,找出哪些包和库需要交叉编译安装到基本boot环境中。

2) 重新使用opensuse中的源码交叉编译出可以启动的、可用来build rpm的构建环境。(这是最关键也是最重要的一步!)

3) 在任务2中交叉编译出的系统上构建各个rpm包。不使用之前在debian系统中构建的rpm包。

4) 把构建出来的rpm包安装到boot系统上,替换掉原来交叉编译出来的二进制文件,完成一个真正的opensuse系统。

5) 把完成的系统拷贝到gdium上进行测试。

6) 整理各种文档。

调整之前的任务计划,用灰色字体

1) 为交叉编译出的基系统安装更多的rpm包。目前除了kernel和正在编译的glibc之外其他的基础包使用–nodeps参数应该都可以安装了。

2) 解决安装rpm中的各种问题,让系统能够顺利启动。同时要理清各种启动脚本的工作方式,让一些基本的服务能够起来。

3) 继续编译rpm包。重点是之前遗留下来的问题包还有与yast相关的一些包。这个应该是很耗时的工作。

4) 安装所有编译出来的rpm包到基系统上,替换交叉编译出来的那些二进制文件和配置文件,完成一个真正的opensuse系统。

5) 把系统拷贝到gdium上,让其能够正常运行。

6) 整理各种文档。

2、进度安排

  • 5月9 ~ 5月15 : 完成任务1
  • 5月16 ~ 6月15 : 完成任务2 。任务2是底线,就算之后的工作没时间或无法完成,任务2也一定要完成。
  • 6月16 ~ 6月30 : 完成任务3大部分包
  • 7月1 ~ 7月10 : 完成中期检查,总结之前的工作
  • 7月11 ~ 7月15 : 完成任务3
  • 7月16 ~ 7月31 : 完成任务4
  • 8月1 ~ 8月10 : 完成任务5
  • 8月11 ~ 8月20 : 完成任务6

3、重要的时间点

  • 5月15 : Deadline to return tax form and proof of enrollment if you want to be paid as part of the initial program payments
  • 7 月1 : Deadline to return tax form and proof of enrollment if you want to be paid as part of the second batch of program payments
  • 7月13 : Mid-term evaluations deadline
  • 8月10 : Suggested ‘pencils down’ date. Take a week to scrub code, write tests, improve documentation, etc.
  • 8月14 : Deadline to return tax form and proof of enrollment if you want to be paid for participation in the Google Summer of Code 2009 program
  • 8月24 : Final evaluation deadline
  • 8月25 : Final results of GSoC 2009 announced
  • 9月3 : Students can begin submitting required code samples to Google

六、详细描述实现方法(已过时)

目前完成的内容可以分为四步

  • 建立交叉编译环境
  • 交叉编译可启动、可使用rpm命令的基本系统

  • 建立qemu虚拟编译环境
  • 在qemu模拟的debian系统中编译rpm包

(以下都是具体的过程步骤,再无其他内容)

1、建立交叉编译环境

首先要准备一个空白分区,我这里用的是sda10,并挂载到了/media/sda10
建立用户并准备环境
sudo groupadd lfs
sudo useradd -s /bin/bash -g lfs -m -k /dev/null lfs
sudo passwd lfs
sudo chown lfs:lfs /media/sda10/* -R
sudo su – lfs

cat > ~/.bashrc << "EOF"
set +h
umask 022
export TARGET_DIR=/media/sda10
export LC_ALL=POSIX
export CROSS_HOST="i386-unknow-linux-gnu"
export CROSS_TARGET="mipsel-unknown-linux-gnu"
export PATH=${TARGET_DIR}/cross-tools/bin:/bin:/usr/bin
unset CFLAGS
unset CXXFLAGS
EOF
source ~/.bash_profile


根据《手把手》中的说明,下载必要的源码和补丁,并建立一些必要的文件
一下命令都是以$TARGET_DIR/build这个目录作为当前目录的

安装内核头文件
tar xf ../source/kernel/linux-2.6.26.tar.bz2
cd linux-2.6.26/
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 linux-2.6.26/ -rf

安装binutils交叉工具
tar xf ../source/loongson/binutils-2.18.50.tar.bz2
cd binutils-2.18.50/
patch -Np1 -i ../../source/patches/2fpatch/binutils-2.18.50-loongson-2f-3.patch

mkdir -pv ../binutils-build
cd ../binutils-build
CC="gcc" AR="ar" ../binutils-2.18.50/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.18.50/include/libiberty.h ${TARGET_DIR}/usr/include
cd ..
rm binutils-* -rf

目标系统glibc头文件
tar xf ../source/loongson/glibc-2.7.tar.bz2
cd glibc-2.7/
cp configure{,.orig}
sed -e 's/3.4/3.[0-9]/g' configure.orig > configure
tar xf ../../source/loongson/glibc-ports-2.7.tar.gz
mv glibc-ports-2.7 ports
patch -Np1 -i ../../source/patches/2fpatch/glibc-2.7-mips_fixes-1.patch
echo "" > ports/sysdeps/mips/mips64/n32/Makefile
echo "" > ports/sysdeps/mips/mips32/Makefile
sed -i 's/-mabi=$mips_config_abi//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_mips_tls=yes" >> config.cache
echo "install_root=${TARGET_DIR}" > configparms
CC="gcc" ../glibc-2.7/configure --prefix=/usr
--host=${CROSS_TARGET} --build=${CROSS_HOST}
--with-headers=${TARGET_DIR}/usr/include --cache-file=config.cache

make install-headers
install -dv ${TARGET_DIR}/usr/include/bits
touch ${TARGET_DIR}/usr/include/bits/stdio_lim.h
touch ${TARGET_DIR}/usr/include/gnu/stubs.h
cp -v ../glibc-2.7/ports/sysdeps/unix/sysv/linux/mips/nptl/bits/pthreadtypes.h
${TARGET_DIR}/usr/include/bits
cd ..
rm glibc-* -rf


GCC交叉工具(仅支持C语言)

sed -i 's/include-fixed/include/g' fixincludes/mkheaders.in gcc/Makefile.in
mkdir -pv ../gcc-build
cd ../gcc-build
../gcc-4.4-20090407/configure --prefix=${TARGET_DIR}/cross-tools
--host=${CROSS_HOST} --build=${CROSS_HOST} --target=${CROSS_TARGET}
--with-sysroot=${TARGET_DIR}
--disable-multilib
--disable-nls --disable-shared --disable-threads --enable-languages=c

make all-target-libgcc
make install-gcc
make install-target-libgcc

目标系统的glibc
tar xf ../source/loongson/glibc-2.7.tar.bz2
cd glibc-2.7/
tar xf ../../source/loongson/glibc-ports-2.7.tar.gz
mv glibc-ports-2.7 ports
patch -Np1 -i ../../source/patches/2fpatch/glibc-2.7-libgcc_eh-1.patch
patch -Np1 -i ../../source/patches/2fpatch/glibc-2.7-localedef_segfault-1.patch
patch -Np1 -i ../../source/patches/2fpatch/glibc-2.7-cross_hacks-1.patch
patch -Np1 -i ../../source/patches/2fpatch/glibc-2.7-mips_fixes-1.patch
patch -Np1 -i ../../source/patches/2fpatch/glibc-2.7-gcc4.4-mips_fixes-1.patch
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/64/g' ports/sysdeps/mips/preconfigure
如果是gcc4.3那么关于inline的定义有变化,做一个dirty的patch
或者在后来做?
echo "libc_cv_gnu89_inline=yes" >> config.cache
if test "$(gcc -dumpversion 2>&1 | cut -d'.' -f1,2)" = "4.3"; then
echo "founded gcc ver4.3! apply dirty patch"
sed -i 's/^const struct keyword_t *$/static &/' locale/programs/charmap-kw.h
sed -i 's/^const struct keyword_t *$/static &/' locale/programs/locfile-kw.h
fi
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_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" ../glibc-2.7/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
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

GCC交叉工具(支持c和c++语言)
sed -i 's/include-fixed/include/g' fixincludes/mkheaders.in gcc/Makefile.in
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-4.4-20090407/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
--enable-c99 --enable-long-long --enable-threads=posix --enable-languages=c,c++

make
make install

File软件包
tar xf ../source/loongson/file-4.24.tar.bz2
cd file-4.24/
./configure --prefix=${TARGET_DIR}/cross-tools
make
make install
cd ..
rm ./file-4.24/ -rf

Groff软件包
tar xf ../source/loongson/groff-1.19.2.tar.gz
cd groff-1.19.2/
PAGE=A4 ./configure --prefix=${TARGET_DIR}/cross-tools --without-x
make
make install
cd ..
rm groff-1.19.2/ -rf

Shadow软件包
tar xf ../source/loongson/shadow-4.0.18.1.tar.bz2
cd shadow-4.0.18.1/
patch -Np1 -i ../../source/patches/2fpatch/shadow-4.0.18.1-useradd_fix-2.patch
patch -Np1 -i ../../source/patches/2fpatch/shadow-4.0.18.1-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 shadow-4.0.18.1/ -rf

2、交叉编译可启动、可使用rpm命令的基本系统

环境设置
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

安装GMP
tar xf ../source/loongson/gmp-4.2.2.tar.bz2
cd gmp-4.2.2/
patch -Np1 -i ../../source/patches/2fpatch/gmp-4.2.2-loongson-1.patch
./configure --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm gmp-4.2.2/ -rf

安装MPFR
tar xf ../source/loongson/mpfr-2.3.1.tar.bz2
cd mpfr-2.3.1/
patch -Np1 -i ../../source/patches/2fpatch/mpfr-2.3.1-loongson-1.patch
patch -Np1 -i ../../source/patches/2fpatch/mpfr-2.3.1-rpath-1.patch
./configure --host=${CROSS_TARGET} --prefix=/usr
make
ln -s libmpfr.la .libs/libmpfr.lai
make DESTDIR=${TARGET_DIR} install
cd ..
rm mpfr-2.3.1/ -rf

安装coreutils
tar xf ../source/coreutils/coreutils-6.12.tar.gz
cd coreutils-6.12/
patch -Np1 -i ../../source/patches/2fpatch/coreutils-6.12-cross_compiler-1.patch
touch man/hostname.1 man/*.1
echo "fu_cv_sys_stat_statfs2_bsize=yes" > config.cache
echo "fu_cv_sys_stat_statvfs=yes" >> config.cache
./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,ln,ls,mkdir,mknod} ${TARGET_DIR}/bin
mv -v ${TARGET_DIR}/usr/bin/{mv,pwd,rm,rmdir,stty,true,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-6.12

安装ncurses
tar xf ../source/loongson/ncurses-5.6.tar.bz2
cd ncurses-5.6/
patch -Np1 -i ../../source/patches/2fpatch/ncurses-5.6-bash_fix-1.patch
patch -Np1 -i ../../source/patches/2fpatch/ncurses-5.6-coverity_fixes-1.patch
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --with-shared
--without-debug --without-ada --with-build-cc=gcc --libdir=/lib
make
make DESTDIR=${TARGET_DIR} install
mv -v ${TARGET_DIR}/lib/lib{panel,menu,form,ncurses,ncurses++,curses}.a ${TARGET_DIR}/usr/lib
rm -v ${TARGET_DIR}/lib/lib{ncurses,menu,panel,form,curses}.so
ln -svf ../../lib/libncurses.so.5 ${TARGET_DIR}/usr/lib/libcurses.so
ln -svf ../../lib/libncurses.so.5 ${TARGET_DIR}/usr/lib/libncurses.so
ln -svf ../../lib/libmenu.so.5 ${TARGET_DIR}/usr/lib/libmenu.so
ln -svf ../../lib/libpanel.so.5 ${TARGET_DIR}/usr/lib/libpanel.so
ln -svf ../../lib/libform.so.5 ${TARGET_DIR}/usr/lib/libform.so
chmod -v 755 ${TARGET_DIR}/lib/lib{panel,menu,form,ncurses}.so.5.6
cd ..
rm -rf ncurses-5.6

安装procps
tar xf ../source/loongson/procps-3.2.7.tar.gz
cd procps-3.2.7/
cp -v Makefile{,.orig}
sed -e "/^install :=/s/--owner 0 --group 0//"
-e "/^ldconfig :=/s/= ldconfig/=/" Makefile.orig > Makefile
make
make DESTDIR=${TARGET_DIR} lib64=lib install
cd ..
rm procps-3.2.7/ -rf

安装readline
tar xf ../source/loongson/readline-5.2.tar.gz
cd readline-5.2/
patch -Np1 -i ../../source/patches/2fpatch/readline-5.2-fixes-5.patch
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --libdir=/lib
make SHLIB_XLDFLAGS=-lncurses
make DESTDIR=${TARGET_DIR} install
chmod -v 755 ${TARGET_DIR}/lib/lib{readline,history}.so*
mv -v ${TARGET_DIR}/lib/lib{readline,history}.a ${TARGET_DIR}/usr/lib
rm -v ${TARGET_DIR}/lib/lib{readline,history}.so
ln -svf ../../lib/libreadline.so.5 ${TARGET_DIR}/usr/lib/libreadline.so
ln -svf ../../lib/libhistory.so.5 ${TARGET_DIR}/usr/lib/libhistory.so
cd ..
rm -rf readline-5.2

安装bash
tar xf ../source/loongson/bash-3.2.tar.gz
cd bash-3.2/
tar xf ../../source/loongson/bash-doc-3.2.tar.gz
patch -Np1 -i ../../source/patches/2fpatch/bash-3.2-fixes-7.patch
echo "bash_cv_sys_named_pipes=yes" > config.cache
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --bindir=/bin
--cache-file=config.cache --without-bash-malloc --with-installed-readline
make
make DESTDIR=${TARGET_DIR} htmldir=/usr/share/doc/bash-3.2 install
ln -sv bash ${TARGET_DIR}/bin/sh
cd ..
rm -rf bash-3.2

安装bzip2
tar xf ../source/loongson/bzip2-1.0.5.tar.gz
cd bzip2-1.0.5/
patch -Np1 -i ../../source/patches/2fpatch/bzip2-1.0.5-install_docs-1.patch
cp Makefile{,.orig}
sed -e "/^all:/s/ test//" Makefile.orig > Makefile
make -f Makefile-libbz2_so CC="${CC}" AR="${AR}" RANLIB="${RANLIB}"
make clean
make CC="${CC}" AR="${AR}" RANLIB="${RANLIB}"
make PREFIX=${TARGET_DIR}/usr install
cp -v bzip2-shared ${TARGET_DIR}/bin/bzip2
cp -av libbz2.so* ${TARGET_DIR}/lib
ln -sv ../../lib/libbz2.so.1.0 ${TARGET_DIR}/usr/lib/libbz2.so
rm -v ${TARGET_DIR}/usr/bin/{bunzip2,bzcat,bzip2}
ln -sv bzip2 ${TARGET_DIR}/bin/bunzip2
ln -sv bzip2 ${TARGET_DIR}/bin/bzcat
cd ..
rm -rf bzip2-1.0.5

安装gzip
tar xf ../source/loongson/gzip-1.3.12.tar.gz
cd gzip-1.3.12/
sed -i 's/futimens/gl_&/' gzip.c lib/utimens.{c,h}
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
mv -v ${TARGET_DIR}/usr/bin/gzip ${TARGET_DIR}/bin
rm -v ${TARGET_DIR}/usr/bin/{gunzip,zcat}
ln -sv gzip ${TARGET_DIR}/bin/gunzip
ln -sv gzip ${TARGET_DIR}/bin/zcat
ln -sv gzip ${TARGET_DIR}/bin/compress
ln -sv gunzip ${TARGET_DIR}/bin/uncompress
cd ..
rm -rf gzip-1.3.12


安装findutils
tar xf ../source/loongson/findutils-4.2.33.tar.gz
cd findutils-4.2.33/
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
--libexecdir=/usr/lib/locate --localstatedir=/var/lib/locate
make
make DESTDIR=${TARGET_DIR} install
mv -v ${TARGET_DIR}/usr/bin/find ${TARGET_DIR}/bin
cp ${TARGET_DIR}/usr/bin/updatedb{,.orig}
sed 's@find:=${BINDIR}@find:=/bin@' ${TARGET_DIR}/usr/bin/updatedb.orig
> ${TARGET_DIR}/usr/bin/updatedb
rm ${TARGET_DIR}/usr/bin/updatedb.orig
cd ..
rm -rf findutils-4.2.33

安装gettext
tar xf ../source/loongson/gettext-0.16.1.tar.gz
cd gettext-0.16.1/
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -rf gettext-0.16.1

安装grep
tar xf ../source/loongson/grep-2.5.3.tar.bz2
cd grep-2.5.3/
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --bindir=/bin
--disable-perl-regexp
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -rf grep-2.5.3

安装inetutils
tar xf ../source/loongson/inetutils-1.5.tar.gz
cd inetutils-1.5/
patch -Np1 -i ../../source/patches/2fpatch/inetutils-1.5-no_server_man_pages-2.patch
for dir in ping rcp rlogin rsh; do
cp ${dir}/Makefile.in{,.orig}
sed '/^SUIDMODE =/s/-o root//' ${dir}/Makefile.in.orig > ${dir}/Makefile.in
done
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --libexecdir=/usr/sbin
--sysconfdir=/etc --localstatedir=/var --disable-logger --disable-syslogd
--disable-whois --disable-servers
make
make DESTDIR=${TARGET_DIR} install
mv -v ${TARGET_DIR}/usr/bin/ping{,6} ${TARGET_DIR}/bin
mv $TARGET_DIR/usr/bin/ifconfig $TARGET_DIR/sbin
cd ..
rm -rf inetutils-1.5

安装iproute2
tar xf ../source/loongson/iproute2-2.6.26.tar.bz2
cd iproute2-2.6.26/
for dir in ip misc tc; do
cp ${dir}/Makefile{,.orig}
sed 's/0755 -s/0755/' ${dir}/Makefile.orig > ${dir}/Makefile
done
cp misc/Makefile{,.orig}
sed '/^TARGETS/s@arpd@@g' misc/Makefile.orig > misc/Makefile
make CC="${CC}" SBINDIR=/sbin
make DESTDIR=${TARGET_DIR} SBINDIR=/sbin install
cd ..
rm -rf iproute2-2.6.26

安装less
tar xf ../source/loongson/less-418.tar.gz
cd less-418/
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --sysconfdir=/etc
make
make prefix=${TARGET_DIR}/usr install
mv -v ${TARGET_DIR}/usr/bin/less ${TARGET_DIR}/bin
cd ..
rm -rf less-418

安装zlib
tar xf ../source/loongson/zlib-1.2.3.tar.gz
cd zlib-1.2.3/
patch -Np1 -i ../../source/patches/2fpatch/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

安装module-init-tools
tar xf ../source/module-init-tools/module-init-tools-3.4.tar.bz2
cd module-init-tools-3.4/
patch -Np1 -i ../../source/patches/2fpatch/module-init-tools-3.4-manpages-1.patch
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/ --enable-zlib
make
make DESTDIR=${TARGET_DIR} INSTALL=install install
cd ..
rm -rf module-init-tools-3.4

安装psmisc
tar xf ../source/loongson/psmisc-22.6.tar.gz
cd psmisc-22.6/
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --exec-prefix=""
patch -Np1 -i ../../source/patches/2fpatch/psmisc-22.6-fixes-1.patch
make
make DESTDIR=${TARGET_DIR} install
mv -v ${TARGET_DIR}/bin/pstree* ${TARGET_DIR}/usr/bin
ln -sv killall ${TARGET_DIR}/bin/pidof
cd ..
rm -rf psmisc-22.6

安装shadow
tar xf ../source/loongson/shadow-4.0.18.1.tar.bz2
cd shadow-4.0.18.1/
patch -Np1 -i ../../source/patches/2fpatch/shadow-4.0.18.1-useradd_fix-2.patch
echo "ac_cv_func_setpgrp_void=yes" > config.cache
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --libdir=/lib --sysconfdir=/etc
--enable-shared --without-libpam --without-audit --without-selinux
--cache-file=config.cache
cp src/Makefile{,.orig}
sed 's/groups$(EXEEXT) //' src/Makefile.orig > src/Makefile
cp man/Makefile{,.orig}
sed -e '/groups1.xml/d' -e 's/groups.1//' man/Makefile.orig > man/Makefile
make
make DESTDIR=${TARGET_DIR} install
cp ${TARGET_DIR}/etc/login.defs login.defs.orig
sed -e 's@#MD5_CRYPT_ENAB.no@MD5_CRYPT_ENAB yes@' -e 's@/var/spool/mail@/var/mail@'
login.defs.orig > ${TARGET_DIR}/etc/login.defs
mv -v ${TARGET_DIR}/usr/bin/passwd ${TARGET_DIR}/bin
mv -v ${TARGET_DIR}/lib/libshadow.*a ${TARGET_DIR}/usr/lib
rm -v ${TARGET_DIR}/lib/libshadow.so
ln -svf ../../lib/libshadow.so.0 ${TARGET_DIR}/usr/lib/libshadow.so
${CROSS_TARGET}-pwconv
${CROSS_TARGET}-grpconv
${CROSS_TARGET}-passwd root
输入root密码
cd ..
rm -rf shadow-4.0.18.1

安装sysklogd
tar xf ../source/loongson/sysklogd-1.5.tar.gz
cd sysklogd-1.5/
cp Makefile{,.orig}
sed -e 's/-o ${MAN_USER} -g ${MAN_GROUP}//' -e 's/500 -s/500/' Makefile.orig > Makefile
make CC="${CC}"
make prefix=${TARGET_DIR} install
cd ..
rm -rf sysklogd-1.5
cat > ${TARGET_DIR}/etc/syslog.conf << "EOF"
# Begin /etc/syslog.conf
auth,authpriv.* -/var/log/auth.log
*.*;auth,authpriv.none -/var/log/sys.log
daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log
*.info;mail.none;authpriv.none;cron.none -/var/log/messages
*.emerg
*
# log the bootscript output:
local2.* -/var/log/boot.log

# End /etc/syslog.conf
EOF

File软件包
tar xf ../source/loongson/file-4.24.tar.bz2
cd file-4.24/
./configure --prefix=${TARGET_DIR}/cross-tools
make
make install
cd ..
rm ./file-4.24/ -rf

Groff软件包
tar xf ../source/loongson/groff-1.19.2.tar.gz
cd groff-1.19.2/
PAGE=A4 ./configure --prefix=${TARGET_DIR}/cross-tools --without-x
make
make install
cd ..
rm groff-1.19.2/ -rf

安装e2fsprogs
tar xf ../source/loongson/e2fsprogs-1.41.0.tar.gz
cd e2fsprogs-1.41.0/
patch -Np1 -i ../../source/patches/2fpatch/e2fsprogs-1.41.0-linux-gcc4.4-1.patch
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
cd ../..
rm -rf e2fsprogs-1.41.0


安装util-linux-ng
tar xf ../source/loongson/util-linux-ng-2.13.1.1.tar.bz2
cd util-linux-ng-2.13.1.1/
cp hwclock/hwclock.c{,.orig}
sed 's@etc/adjtime@var/lib/hwclock/adjtime@g' hwclock/hwclock.c.orig > hwclock/hwclock.c
mkdir -pv ${TARGET_DIR}/var/lib/hwclock
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET}
--enable-partx --disable-wall --enable-write
--disable-makeinstall-chown
make
make DESTDIR=${TARGET_DIR} install
mv -v ${TARGET_DIR}/usr/bin/logger ${TARGET_DIR}/bin
cd ..
rm -r util-linux-ng-2.13.1.1

Shadow软件包
tar xf ../source/loongson/shadow-4.0.18.1.tar.bz2
cd shadow-4.0.18.1/
patch -Np1 -i ../../source/patches/2fpatch/shadow-4.0.18.1-useradd_fix-2.patch
patch -Np1 -i ../../source/patches/2fpatch/shadow-4.0.18.1-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 shadow-4.0.18.1/ -rf

安装tar
tar xf ../source/loongson/tar-1.20.tar.bz2
cd tar-1.20/
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --bindir=/bin
--libexecdir=/usr/sbin
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -rf tar-1.20

安装udev
cp -r ../source/rpmbuild/udev-128/ .
cd udev-128/
find . -name "*.[78]" -exec touch '{}' ;
./configure
--prefix=/usr
--exec-prefix=
--sysconfdir=/etc
--with-libdir-name=lib
--with-selinux
CFLAGS="-O2" --build=i386-cross-linux-gnu --host=mipsel-unknown-linux-gnu
make
make DESTDIR=$TARGET_DIR install
mkdir -p $TARGET_DIR/usr/bin
ln -s ../../sbin/udevadm $TARGET_DIR/usr/bin/udevinfo
ln -s udevadm $TARGET_DIR/sbin/udevsettle
cp rules/packages/64-device-mapper.rules $TARGET_DIR/lib/udev/rules.d/
cp rules/packages/64-md-raid.rules $TARGET_DIR/lib/udev/rules.d/
cp rules/packages/40-zaptel.rules $TARGET_DIR/lib/udev/rules.d/
cp rules/suse/*.rules $TARGET_DIR/lib/udev/rules.d/
install -m755 -D $TARGET_DIR/source/rpmbuild/boot.udev $TARGET_DIR/etc/init.d/boot.udev
install -m755 -D $TARGET_DIR/source/rpmbuild/boot.udev_retry $TARGET_DIR/etc/init.d/boot.udev_retry
install -m644 -D $TARGET_DIR/source/rpmbuild/pnp-aliases $TARGET_DIR/etc/modprobe.d/pnp-aliases
mkdir -p $TARGET_DIR/lib/udev/devices
mkdir -p $TARGET_DIR/lib/udev/devices/pts
mkdir -p $TARGET_DIR/lib/udev/devices/shm
mkdir -p $TARGET_DIR/lib/udev/devices/net
ln -sn /proc/self/fd/ $TARGET_DIR/lib/udev/devices/fd
ln -sn /proc/self/fd/0 $TARGET_DIR/lib/udev/devices/stdin
ln -sn /proc/self/fd/1 $TARGET_DIR/lib/udev/devices/stdout
ln -sn /proc/self/fd/2 $TARGET_DIR/lib/udev/devices/stderr
ln -sn /proc/kcore $TARGET_DIR/lib/udev/devices/core
cd ..
rm udev-128/ -rf

安装vim
tar xf ../source/loongson/vim-7.2.tar.bz2
tar xf ../source/loongson/vim-7.2-extra.tar.gz
tar xf ../source/loongson/vim-7.2-lang.tar.gz
cd vim72
echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h
echo "vim_cv_toupper_broken=yes" > src/auto/config.cache
echo "vim_cv_terminfo=yes" >> src/auto/config.cache
echo "vim_cv_tty_group=yes" >> src/auto/config.cache
echo "vim_cv_tty_mode=yes" >> src/auto/config.cache
echo "vim_cv_getcwd_broken=yes" >> src/auto/config.cache
echo "vim_cv_stat_ignores_slash=yes" >> src/auto/config.cache
echo "ac_cv_sizeof_int=4" >> src/auto/config.cache
echo "vim_cv_memmove_handles_overlap=yes" >> src/auto/config.cache
./configure --build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --enable-multibyte
--enable-gui=no --disable-gtktest --disable-xim --with-features=normal
--disable-gpm --without-x --disable-netbeans --with-tlib=ncurses --cache-file=config.cache
make
make DESTDIR=${TARGET_DIR} install
ln -sv vim ${TARGET_DIR}/usr/bin/vi
ln -sv ../vim/vim72/doc ${TARGET_DIR}/usr/share/doc/vim-7.2
cd ..
rm -rf vim72
cat > ${TARGET_DIR}/etc/vimrc << "EOF"
" Begin /etc/vimrc
set nocompatible
set backspace=2
syntax on
if (&term == "iterm") || (&term == "putty")
set background=dark
endif
" End /etc/vimrc
EOF

安装libsepol
tar xf ../source/libsepol/libsepol-2.0.32.tar.bz2
cd libsepol-2.0.32/
make
make DESTDIR=${TARGET_DIR} install
cd ..
安装libselinux
tar xf ../source/libselinux/libselinux-2.0.71.tar.bz2
cd libselinux-2.0.71/
cp -v src/Makefile{,.orig}
sed -e 's/^TLSFLAGS/#TLSFLAGS/' src/Makefile.orig > src/Makefile
make
make DESTDIR=${TARGET_DIR} install
cd ..

安装sysvinit
首先把rpmbuild -bp命令产生的源码cp到build目录
export CFLAGS="-Wall -O2 -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D__NO_STRING_INLINES -pipe"
cp -v src/Makefile src/Makefile.orig
sed -e 's@/dev/initctl@$(ROOT)&@g' -e 's@(mknod )-m ([0-9]* )(.* )p@13p; chmod 23@g'
-e '/^ifeq/s/$(ROOT)//' -e 's@/usr/lib@$(ROOT)&@' src/Makefile.orig > src/Makefile
make -C src CFLAGS="$CFLAGS" CC="$CC"
pushd contrib/
$CC $CFLAGS -o start-stop-daemon start-stop-daemon.c
popd
pushd ../powerd-2.0.2
./configure --prefix= --bindir='$(TARGET_DIR)/sbin'
--mandir='$(TARGET_DIR)/usr/share/man'
--sbindir='$(TARGET_DIR)/sbin' --build=${CROSS_HOST} --host=${CROSS_TARGET}
make CFLAGS="-I../sysvinit-2.86/src $CFLAGS" CC="$CC"
popd
pushd ../startpar-0.52
make CFLAGS="$CFLAGS" CC="$CC"
popd
make install -C src MANPATH=/usr/share/man ROOT=${TARGET_DIR}
install contrib/start-stop-daemon ${TARGET_DIR}/sbin/
test -p ${TARGET_DIR}/dev/initctl || {
rm -f ${TARGET_DIR}/dev/initctl
mknod ${TARGET_DIR}/dev/initctl p
chmod 600 ${TARGET_DIR}/dev/initctl
}
pushd ../powerd-2.0.2
make install DESTDIR=${TARGET_DIR}
cp README README.powerd
cp SUPPORTED SUPPORTED.powerd
cp FAQ FAQ.powerd
echo '# ' > ${TARGET_DIR}/etc/powerd.conf
echo '# /etc/powerd.conf for powerd version-2.02' >> ${TARGET_DIR}/etc/powerd.conf
echo '# ' >> ${TARGET_DIR}/etc/powerd.conf
echo '# read manual page of detectups(8) and powerd(8) its self.' >> ${TARGET_DIR}/etc/powerd.conf
echo '# ' >> ${TARGET_DIR}/etc/powerd.conf
mkdir -p ${TARGET_DIR}/etc/init.d
install -m 0744 ${TARGET_DIR}/source/rpmbuild/rc.powerd ${TARGET_DIR}/etc/init.d/powerd
popd
pushd ../startpar-0.52
make install DESTDIR=${TARGET_DIR}
popd
install -d $TARGET_DIR/lib/mkinitrd/scripts
install -m 0755 ${TARGET_DIR}/source/rpmbuild/mkinitrd-boot.sh $TARGET_DIR/lib/mkinitrd/scripts/boot-blogd.sh
install -m 0755 ${TARGET_DIR}/source/rpmbuild/mkinitrd-kill1.sh $TARGET_DIR/lib/mkinitrd/scripts/boot-killblogd.sh
install -m 0755 ${TARGET_DIR}/source/rpmbuild/mkinitrd-kill2.sh $TARGET_DIR/lib/mkinitrd/scripts/boot-killblogd2.sh
mknod -m 0640 ${TARGET_DIR}/dev/blog p
unset CFLAGS

安装mingetty
cp -r ../source/rpmbuild/mingetty-1.0.7s/ .
cd mingetty-1.0.7s/
make RPM_OPT_FLAGS=”-O2 -D_FILE_OFFSET_BITS=64″ DEFTERM=linux CC=”$CC”
mkdir -p ${TARGET_DIR}{/sbin,/usr/share/man/man8}
make install MANPATH=/usr/share/man DESTDIR=${TARGET_DIR}
cd ..
rm mingetty-1.0.7s/ -rf

安装lzma-utils
cp -r $TARGET_DIR/source/rpmbuild/lzma-utils $TARGET_DIR/build
pushd $TARGET_DIR/build/lzma-utils
export CFLAGS=”-O2″ CXXFLAGS=”-O2″
./configure –with-pic –disable-rpath –enable-werror –disable-shared –build=i386-cross-linux-gnu –host=mipsel-unknown-linux-gnu
make CC=”$CC”
make install DESTDIR=$TARGET_DIR
unset CFLAGS CXXFLAGS
popd
rm -rf $TARGET_DIR/build/lzma-utils

安装elfutils
cp -r $TARGET_DIR/source/rpmbuild/elfutils-0.137 $TARGET_DIR/build
pushd $TARGET_DIR/build/elfutils-0.137
autoreconf -fi
./configure –program-prefix=eu- –build=i386-cross-linux-gnu –host=mipsel-suse-linux-gnu
cp Makefile Makefile.orig
sed -e ‘/^SUBDIRS/s/libebl//’ -e ‘/^SUBDIRS/s/libcpu//’ -e ‘/^SUBDIRS/s/backends//’ Makefile.orig > Makefile
make CC=”$CC”
make DESTDIR=$TARGET_DIR install
popd
rm -rf $TARGET_DIR/build/elfutils-0.137

安装rpm
cp -r $TARGET_DIR/source/rpmbuild/rpm-4.4.2.3 $TARGET_DIR/build
pushd $TARGET_DIR/build/rpm-4.4.2.3
export CFLAGS=”-O2 -fno-strict-aliasing -ffunction-sections”
export LDFLAGS=”-Wl,-Bsymbolic-functions -ffunction-sections”
rm -rf zlib
cp $TARGET_DIR/usr/share/gettext/config.rpath .
cp popt/autogen.sh beecrypt
cp popt/autogen.sh file
./autogen.sh –prefix=/usr –mandir=/usr/share/man –infodir=/usr/share/info –libdir=/usr/lib –sysconfdir=/etc –localstatedir=/var –with-lua –with-selinux –enable-shared –build=i386-cross-linux-gnu –host=mipsel-suse-linux-gnu –without-python
rm po/de.gmo
patch -Np1 -i ../../source/patches/mypatch/rpm-4.4.2.3-cross.patch
cp -v file/magic/Makefile file/magic/Makefile.orig
sed -e “/-C -m /s//src/file//cross-tools/bin/file/” -e “/-C -m /s/top_builddir/TARGET_DIR/” file/magic/Makefile.orig > file/magic/Makefile
make
mkdir -p $TARGET_DIR/usr/lib
mkdir -p $TARGET_DIR/usr/share/locale
ln -s ../share/locale $TARGET_DIR/usr/lib/locale
make DESTDIR=”$TARGET_DIR” install
rm -f $TARGET_DIR/usr/lib/libpopt.a $TARGET_DIR/usr/lib/libpopt.la
for f in $TARGET_DIR/usr/lib/*.la; do
sed -i -e “s,/usr/lib/libpopt.la,-lpopt,g” $f
done
mkdir -p $TARGET_DIR/etc/init.d
install -m 755 $TARGET_DIR/source/rpmbuild/rpmconfigcheck $TARGET_DIR/etc/init.d
mkdir -p $TARGET_DIR/usr/sbin
ln -sf ../../etc/init.d/rpmconfigcheck $TARGET_DIR/usr/sbin/rcrpmconfigcheck
cp -a $TARGET_DIR/source/rpmbuild/suse_macros $TARGET_DIR/usr/lib/rpm
mv $TARGET_DIR/usr/src/* $TARGET_DIR/usr/src/packages
mkdir -p $TARGET_DIR/var/lib/rpm
mkdir -p $TARGET_DIR/var/spool/repackage
rm -rf $TARGET_DIR/usr/include/beecrypt $TARGET_DIR/usr/lib/libbeecrypt*
gzip -9 $TARGET_DIR/usr/share/man/man[18]/*.[18]
export TARGET_DIR
chmod 755 doc/manual
rm -rf doc/manual/Makefile*
rm -f $TARGET_DIR/usr/lib/rpmpopt
rm -rf $TARGET_DIR/usr/share/man/{fr,ja,ko,pl,ru,sk}
rm -f $TARGET_DIR/usr/share/locale/de/LC_MESSAGES/rpm.mo
mkdir -p $TARGET_DIR/var/adm/fillup-templates
install -c -m 0644 $TARGET_DIR/source/rpmbuild/sysconfig.services-rpm $TARGET_DIR/var/adm/fillup-templates/
rm -f $TARGET_DIR/usr/lib/rpm/cpanflute $TARGET_DIR/usr/lib/rpm/cpanflute2
mv $TARGET_DIR/usr/src/packages/cross/* $TARGET_DIR/usr/src/packages/
rm -rf $TARGET_DIR/usr/src/packages/cross
find $TARGET_DIR/usr/src/packages/* -type d | sed -e “s@$TARGET_DIR@@” >> $TARGET_DIR/usr/lib/rpm/permlist
install -m 755 $TARGET_DIR/source/rpmbuild/rpmsort $TARGET_DIR/usr/lib/rpm
install -m 755 $TARGET_DIR/source/rpmbuild/symset-table $TARGET_DIR/usr/lib/rpm
install -m 755 scripts/find-supplements{,.ksyms} $TARGET_DIR/usr/lib/rpm
install -m 755 scripts/firmware.prov $TARGET_DIR/usr/lib/rpm
rm -f $TARGET_DIR/usr/lib/locale $TARGET_DIR/usr/lib/rpmrc
mkdir -p $TARGET_DIR/etc/rpm
chmod 755 $TARGET_DIR/etc/rpm
pushd $TARGET_DIR/usr/lib/rpm/
for f in rpm2cpio.sh rpm.daily rpmdiff* rpm.log rpm.xinetd freshen.sh u_pkg.sh
magic magic.mgc magic.mime* rpmfile *.pl javadeps brp-redhat
brp-strip-static-archive vpkg-provides*.sh http.req sql.req tcl.req
rpmdb_* brp-sparc64-linux brp-strip-comment-note brp-java-gcjcompile
do
rm $f
done
for i in $TARGET_DIR/usr/share/automake-*/*; do
if test -f “$i” && test -f “${i##*/}”; then
rm -f “${i##*/}”
fi
done
popd
unset CFLAGS LDFLAGS
popd
rm -rf $TARGET_DIR/build/rpm-4.4.2.3

复制一些opensuse用到的配置文
cp $TARGET_DIR/source/rpmbuild/boot $TARGET_DIR/etc/init.d/
要修改inittab,只启动tty1,开启S0
cp $TARGET_DIR/source/rpmbuild/inittab $TARGET_DIR/etc
cp $TARGET_DIR/source/rpmbuild/rc $TARGET_DIR/etc/init.d
cp $TARGET_DIR/source/rpmbuild/rc.status $TARGET_DIR/etc/
cp $TARGET_DIR/source/rpmbuild/rc.splash $TARGET_DIR/etc/
cp $TARGET_DIR/source/rpmbuild/sysconfig-boot $TARGET_DIR/etc/sysconfig/boot
cp $TARGET_DIR/source/rpmbuild/initscript $TARGET_DIR/etc/
pushd $TARGET_DIR/etc/init.d/boot.d/
ln -sv ../boot.udev S02boot.udev
ln -sv ../boot.udev_retry S13boot.udev_retry
popd

建立必要的节点

pushd $TARGET_DIR/dev
mknod -m 660 console c 5 1
mknod -m 660 null c 1 3
mknod -m 660 ttyS0 c 4 64
mknod -m 660 hda b 3 0
mknod -m 660 hda1 b 3 1
mknod -m 660 hda2 b 3 2

popd

为系统打包
sudo tar cjf /media/MOBILE3/snapshots/basesystem-opensuse_boot-rpm-ubuntu-090424.tar.bz2 . –exclude=build –exclude=cross-tools –exclude=qemu_debian –exclude=rpm.gery –exclude=source

3、建立qemu虚拟环境

创建一个img
qemu-img create -f qcow loongson2f.img 10G
用lfs的liveCD对这个img进行分区
qemu-system-x86_64 -hda loongson2f.img -cdrom lfslivecd-x86-6.3-r2160-nosrc.iso -m 256 -boot d -daemonize
进入到lfsliveCD之后
cfdisk /dev/hda
创建两个分区hda1是ext3文件系统,hda2是swap文件系统
mkfs.ext3 /dev/hda1
mkswap /dev/hda2
mkdir mnt
mount -t ext3 /dev/hda1 mnt
cd mnt
scp gery@59.64.153.106:/path/to/tarball .
tar xf basesystem-opensuse_boot-rpm-ubuntu-090424.tar.bz2
chown root:root ./* -R

然后scp debian的modules和kernel过来,最后启动这个系统
qemu-system-mipsel -M malta -kernel vmlinux-2.6.26-1-4kc-malta.debian -hda loongson2f.img -append “root=/dev/hda1 console=ttyS0” -nographic -m 256 -no-reboot

4、在qemu模拟的debian系统中编译rpm包

一个已经安装好的debian系统可以在这里下载。在debian中安装rpm,然后用rpmbuild -bb *.spec命令编译rpm包。