- 论坛徽章:
- 0
|
手把手教你源代码制作龙芯64位系统
(交叉编译版本)正式版
作者:孙海勇
更新日志: 2007年2月18日(春节):正式版发布
目录
- 前言
- 相关知识
- 工具链原理
- build、host和target
- pushd和popd
- tar的使用
- 准备工作
- 创建分区
- 加载分区
- 设置工作目录
- 设置必要的环境变量
- 下载
- 建立目标系统目录结构
- 制作交叉工具链
- 环境设置
- 内核头文件(Linux-Header)
- Binutils交叉工具
- 目标系统glibc头文件
- GCC交叉工具(仅支持C语言)
- 目标系统的glibc
- GCC交叉工具(支持c和c++语言)
- File
- Shadow
- 清理交叉工具链
- 制作目标系统
- 环境设置
- Man_Pages
- Binutils
- GCC
- Sed
- E2fsprogs
- Coreutils
- Iana_Etc
- M4
- Bison
- Ncurses
- Procps
- Libtool
- Readline
- Zlib
- Autoconf
- Automake
- Bash
- Bzip2
- Diffutils
- File
- Findutils
- Flex
- Gawk
- Gettext
- Grep
- Groff
- Gzip
- Inetutils
- Iproute2
- Kbd
- Less
- Make
- Man
- Mktemp
- Module_Init_Tools
- Patch
- Psmisc
- Shadow
- Sysklogd
- Sysvinit
- Tar
- Texinfo
- Udev
- Util_Linux
- Vim
- bootscript
- udev_rules
- 编译内核
- 新系统必要的配置文件
- 系统的打包及启动
- 一些建议
- 结束
前言 一直很关心龙芯的成长,现在终于把基于龙芯2E的计算机拿到手了,于是便开始动手做一套原代码编译而来的纯64位Linux系统,其实制作系统本身和制作mips64位系统基本类似,只是有个别基于龙芯的补丁需要打上。
CLFS中针对mips64位的制作方法非常详细,因此这里不重复该过程,而我对sysroot的交叉方式“情有独衷”,但CLFS-sysroot中还没有出现针对mips和mips64的方法,因此本文将使用该方法建立一个在龙芯上运行的纯64位系统。
本文力争完成一个完整的制作命令,可以根据本文提供的命令顺序输入就可以完成“龙芯”64位系统的制作了,通常命令表示为 命令
更新: 由于篇幅比较长所以难免出现一些错误或者笔误,也有可能加入新内容,因此难免会进行修正或增删一些内容,如果本文被转载可以在本人的Blog中查看最新版本。
我的Blog:http://youbest.cublog.cn
如须转载请注明作者为孙海勇,并提供转载出处。
下面我们就开始制作的旅程,那么在开始前先了解一下我们会接触到的一些知识,这些知识对于理解整个制作过程将非常有帮助。
相关知识 sysroot、工具链及制作过程原理
请参考我的另一篇文章《CLFS2.0原理分析》,该文将整个交叉过程中的原理进行了描述,建议在开始动手前阅读该文章。
文章地址:
http://youbest.cublog.cn
或者http://www.linuxsir.org/bbs/showthread.php?t=267672
build、host和target
在交叉编译中比较 常见 的一些参数就是build、host和target了,正确的理解这三者的含义对于交叉编译是非常重要的,下面就此进行解释
--build=编译该软件所使用的平台
--host=该软件将运行的平台
--target=该软件所处理的目标平台
我们以 gcc 为例子来 讲解 这三者的作用
在gcc编译中我们使用
./configure --build=编译平台 --host=运行平台 --target=目标平台 [各种编译参数]
来配置gcc的源代码,以让其编译出我们需要的gcc编译器。
那么在这组配置参数中:
--build:
表示目前我们正在运行的平台名称是什么,如果当前我们是在intel的pentium机器中编译该系统,那么我们的--build就可能是i686-pc-linux-gnu,当然如果我们在其它种类的机器上编译那么这个build就应该是那个机器所对应的平台名称。
该参数在不指定的情况下将自动常识猜测目前平台的名称。
--host:
表示我们把这个编译好的gcc在什么样的平台下运行,在交叉编译过程中这个需要我们来指定,因为机器自己是不能知道我们心里是怎么想的,那么我们可以明确的告诉它,我们要做出来的程序是运行在“龙芯”上的,但是目前还不能直接指定“龙芯”,因此我们这里指定为mips64el-unknown-linux-gnu(如果你省点事情那么就用这个名字好了,如果你想用个有个性的名字,那么请你想明白它的含义再动手,并且做好后面的过程需要多出一些手续的麻烦的心理准备)。
--host也可以不指定,那么host将自动使用build来定义自己,不过那将不再是交叉编译。
注:--build和--host在不同的时候就被配置文件认定为交叉编译方式。
--target:
该参数的目的是让配置程序知道这个软件被编译后使用来处理什么平台上的文件的。
target这个参数只有在为数不多的几个包中有用处,虽然在./configure --help中经常能看到该参数,但实际上绝大多数软件包都是不需要该参数的。
从这个参数的含义来看,说明其处理的目标只有在不同平台下表现为不同的时候才有作用,而这些文件通常都跟目标平台 的指令系统直接或间接有关:比如可执行文件,对于不同平台下使用的可执行文件的编码可以是完全不同的,因此必须使用 对应能处理该编码的程序才能正确处理,而如果错误的使用则可能导致程序错误或者破坏文件,对于这样要处理不同平台下会 出现不同编码的软件,我们就应当对它指定目标平台,以免另其错误处理;而对于文本文件,对于不同的平台同样的内容表达的 含义都是相同的,因此我们不需要专门针对平台来处理,这样的软件我们就可以不必对它指定需要处理的平台了。
我们来总结一下:
build:自动测试在用平台名称,若无法检测出来则需要指定。
host:若无指定,自动使用build的结果。
build和host相同时表示本地编译,若不相同则表示交叉编译。
target:表示需要处理的目标平台名称,若无指定使用host相同名称,gcc、binutils等于平台指令相关软件有此参数,多数软件此参数无用处。
pushd和popd
这是一组用来切换当前目录的实用命令
pushd [目录名]
用来将当前目录压入堆栈中,并设置当前目录为指定的目录
popd
用来从堆栈中取出最后压入的目录,并将当前目录设置为改目录
例如:
当前目录为/usr
pushd /var/log
此时当前目录为/var/log,/usr进入堆栈中
cd /opt
进入到/opt目录下
popd
从堆栈中取出最后加入的目录,此时的结果为/usr,当前目录重新回到/usr下。
灵活使用这组命令将方便的切换目录,后面的制作过程中将使用该组命令来实现目录的切换。
tar的使用
tar可以说是Linux下使用频率非常高的命令,该命令用来将一组文件打包成一个独立的文件,也可以把一个压缩/打包的文件。
还原成原来的一组文件。
新版本的tar可以自动识别文件的后缀名来确认使用何种程序来解压缩,因此可以用tar xvf来解开包括tar/tar.bz2/tar.gz/tar.Z等文件而不需要指定压缩类型,因此本文中将直接使用tar xvf来解开文件。
例如:
tar xvf gcc-4.1.1.tar.bz2 -C /source
表示将gcc-4.1.1.tar.bz2展开并存放到/source目录下,-C用来指定目标目录。
tar 的使用方式非常的多,可使用tar --help或者man tar来查看具体应用。
准备工作
建立用户 groupadd loongson
useradd -s /bin/bash -g loongson -m -k /dev/null loongson
passwd loongson
创建工作目录 export TARGET_DIR="/loongson"
mkdir -pv ${TARGET_DIR}/{build,download}
chown -Rv loongson ${TARGET_DIR}
切换用户 su - loongson
设置必要的环境变量 cat > ~/.bash_profile cat > ~/.bashrc source ~/.bash_profile
以下是执行完上述命令后使用export命令所显示内容的一个例子
declare -x BUILD64="-mabi=64"
declare -x BUILDDIR="/loongson/build"
declare -x CROSS_HOST="i686-cross-linux-gnu"
declare -x CROSS_TARGET="mips64el-unknown-linux-gnu"
declare -x DOWNLOADDIR="/loongson/download"
declare -x HOME="/home/loongson"
declare -x LC_ALL="POSIX"
declare -x OLDPWD
declare -x PATH="/loongson/cross-tools/bin:/bin:/usr/bin"
declare -x PS1="\\u:\\w\\\$ "
declare -x PWD="/home/loongson"
declare -x SHLVL="1"
declare -x TARGET_DIR="/loongson"
declare -x TERM="linux"
软件包下载 Linux-kernel:
http://www.linux-mips.org/pub/linux/mips/kernel/v2.6/linux-2.6.18.1.tar.gz
Binutils:
http://ftp.gnu.org/gnu/binutils/binutils-2.17.tar.bz2
Glibc:
http://ftp.gnu.org/gnu/glibc/glibc-2.5.tar.bz2
Glibc-Ports:
http://ftp.gnu.org/gnu/glibc/glibc-ports-2.5.tar.bz2
GCC:
http://ftp.gnu.org/gnu/gcc/gcc-4.1.2/gcc-4.1.2.tar.bz2
File:
ftp://ftp.gw.com/mirrors/pub/unix/file/file-4.19.tar.gz
Shadow:
ftp://ftp.pld.org.pl/software/shadow/shadow-4.0.18.1.tar.bz2
Man-Pages:
http://www.kernel.org/pub/linux/docs/manpages/man-pages-2.43.tar.bz2
Sed:
http://ftp.gnu.org/gnu/sed/sed-4.1.5.tar.gz
E2fsprogs:
http://downloads.sourceforge.net/e2fsprogs/e2fsprogs-1.39.tar.gz
Coreutils:
http://ftp.gnu.org/gnu/coreutils/coreutils-6.7.tar.bz2
Iana-Etc:
http://www.sethwklein.net/projects/iana-etc/downloads/iana-etc-2.20.tar.bz2
M4:
http://ftp.gnu.org/gnu/m4/m4-1.4.8.tar.bz2
Bison:
http://ftp.gnu.org/gnu/bison/bison-2.3.tar.bz2
Ncurses:
ftp://invisible-island.net/ncurses/ncurses-5.6.tar.gz
Procps:
http://procps.sourceforge.net/procps-3.2.7.tar.gz
Libtool:
http://ftp.gnu.org/gnu/libtool/libtool-1.5.22.tar.gz
Readline:
http://ftp.gnu.org/gnu/readline/readline-5.2.tar.gz
Zlib:
http://www.zlib.net/zlib-1.2.3.tar.gz
Autoconf:
http://ftp.gnu.org/gnu/autoconf/autoconf-2.61.tar.bz2
Automake:
http://ftp.gnu.org/gnu/automake/automake-1.10.tar.bz2
Bash:
http://ftp.gnu.org/gnu/bash/bash-3.2.tar.gz
Bzip2:
http://www.bzip.org/1.0.4/bzip2-1.0.4.tar.gz
Diffutils:
ftp://alpha.gnu.org/gnu/diffutils/diffutils-2.8.7.tar.gz
Findutils:
http://ftp.gnu.org/gnu/findutils/findutils-4.2.29.tar.gz
Flex:
http://downloads.sourceforge.net/flex/flex-2.5.33.tar.bz2
Gawk:
http://ftp.gnu.org/gnu/gawk/gawk-3.1.5.tar.bz2
Gettext:
http://ftp.gnu.org/gnu/gettext/gettext-0.16.1.tar.gz2
Grep:
http://ftp.gnu.org/gnu/grep/grep-2.5.1a.tar.bz2
Groff:
http://ftp.gnu.org/gnu/groff/groff-1.19.2.tar.gz
Gzip:
http://ftp.gnu.org/gnu/gzip/gzip-1.3.9.tar.gz
Inetutils:
http://ftp.gnu.org/gnu/inetutils/inetutils-1.5.tar.gz
Iproute2:
http://developer.osdl.org/dev/iproute2/download/iproute2-2.6.18-061002.tar.gz
Kbd:
http://www.kernel.org/pub/linux/utils/kbd/kbd-1.12.tar.bz2
Less:
http://www.greenwoodsoftware.com/less/less-394.tar.gz
Make:
http://ftp.gnu.org/gnu/make/make-3.81.tar.bz2
Man:
http://primates.ximian.com/~flucifredi/man/man-1.6e.tar.gz
Mktemp:
ftp://ftp.mktemp.org/pub/mktemp/mktemp-1.5.tar.gz
Module-Init-Tools:
http://www.kerneltools.org/pub/downloads/module-init-tools/module-init-tools-3.2.2.tar.bz2
Patch:
ftp://alpha.gnu.org/gnu/diffutils/patch-2.5.9.tar.gz
Psmisc:
http://downloads.sourceforge.net/psmisc/psmisc-22.3.tar.gz
Sysklogd:
http://www.infodrom.org/projects/sysklogd/download/sysklogd-1.4.1.tar.gz
Sysvinit:
ftp://ftp.cistron.nl/pub/people/miquels/sysvinit/sysvinit-2.86.tar.gz
Tar:
http://ftp.gnu.org/gnu/tar/tar-1.16.1.tar.bz2
Texinfo:
http://ftp.gnu.org/gnu/texinfo/texinfo-4.8a.tar.bz2
Udev:
http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev-105.tar.bz2
Util-Linux:
http://www.kernel.org/pub/linux/utils/util-linux/util-linux-2.12r.tar.bz2
Vim:
ftp://ftp.vim.org/pub/vim/unix/vim-7.0.tar.bz2
ftp://ftp.vim.org/pub/vim/extra/vim-7.0-extra.tar.gz
ftp://ftp.vim.org/pub/vim/extra/vim-7.0-lang.tar.gz
说明:所有文件请下载后保存在${DOWNLOADDIR}(本文中即/loongson/download)目录中。
补丁及配置文件 http://www.zdbr.net.cn/download/patch_and_config-1.tar.bz2
说明:下载该文件后可执行以下命令展开到download目录中。 tar xvf patch_and_config-1.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
cd boot
ln -svf . boot
popd
创建必要的用户、组和日志文件cat > ${TARGET_DIR}/etc/passwd cat > ${TARGET_DIR}/etc/group 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.18.1.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/linux-2.6.18.1
patch -Np1 -i ${DOWNLOADDIR}/linux-2.6.18.1-loongson-1.patch
make include/linux/version.h
cp -av include/{asm-generic,linux,mtd,scsi,sound} ${TARGET_DIR}/usr/include
cp -av include/asm-mips ${TARGET_DIR}/usr/include/asm
cd ..
rm -r linux-2.6.18.1
popd
Binutils交叉工具
tar xvf ${DOWNLOADDIR}/binutils-2.17.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/binutils-2.17
patch -Np1 -i ${DOWNLOADDIR}/binutils-2.17-posix-1.patch
patch -Np1 -i ${DOWNLOADDIR}/binutils-2.17-branch_update-2.patch
patch -Np1 -i ${DOWNLOADDIR}/binutils-2.17-loongson-1.dpatch
mkdir -pv ../binutils-build
cd ../binutils-build
../binutils-2.17/configure --prefix=${TARGET_DIR}/cross-tools \
--host=${CROSS_HOST} --target=${CROSS_TARGET} \
--enable-64-bit-bfd --with-sysroot=${TARGET_DIR} \
--disable-nls --enable-shared --disable-multilib
make configure-host
make
make install
cp -v ../binutils-2.17/include/libiberty.h ${TARGET_DIR}/usr/include
cd ..
rm -r binutils-build
rm -r binutils-2.17
popd
目标系统glibc头文件
tar xvf ${DOWNLOADDIR}/glibc-2.5.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/glibc-2.5
cp configure{,.orig} &&
sed -e 's/3.4/3.[0-9]/g' configure.orig > configure
tar xvf ${DOWNLOADDIR}/glibc-ports-2.5.tar.bz2
mv -v glibc-ports-2.5 ports
patch -Np1 -i ${DOWNLOADDIR}/glibc-2.5-mips_fixes-1.patch
echo "" > ports/sysdeps/mips/mips64/n32/Makefile
sed -i 's/-mabi=$mips_config_abi//g' ports/sysdeps/mips/preconfigure
mkdir -vp ../glibc-build
cd ../glibc-build
echo "libc_cv_forced_unwind=yes" > config.cache &&
echo "libc_cv_c_cleanup=yes" >> config.cache &&
echo "libc_cv_mips64_tls=yes" >> config.cache
echo "install_root=${TARGET_DIR}" > configparms
CC="gcc" ../glibc-2.5/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.5/ports/sysdeps/unix/sysv/linux/mips/nptl/bits/pthreadtypes.h \
${TARGET_DIR}/usr/include/bits
cd ..
rm -r glibc-build
rm -r glibc-2.5
popd
GCC交叉工具(仅支持C语言)
tar xvf ${DOWNLOADDIR}/gcc-4.1.2.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gcc-4.1.2
patch -Np1 -i ${DOWNLOADDIR}/gcc-4.1.2-posix-1.patch
patch -Np1 -i ${DOWNLOADDIR}/gcc-4.1.2-cross_search_paths-1.patch
mkdir -vp ../gcc-build
cd ../gcc-build
../gcc-4.1.2/configure --prefix=${TARGET_DIR}/cross-tools --host=${CROSS_HOST} \
--target=${CROSS_TARGET} --with-sysroot=${TARGET_DIR} \
--disable-nls --disable-shared --disable-threads --disable-multilib \
--enable-languages=c --with-abi=64
make all-gcc
make install-gcc
cd ..
rm -r gcc-build
rm -r gcc-4.1.2
popd
目标系统的glibc
tar xvf ${DOWNLOADDIR}/glibc-2.5.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/glibc-2.5
tar xvf ${DOWNLOADDIR}/glibc-ports-2.5.tar.bz2
mv -v glibc-ports-2.5 ports
patch -Np1 -i ${DOWNLOADDIR}/glibc-2.5-libgcc_eh-2.patch
patch -Np1 -i ${DOWNLOADDIR}/glibc-2.5-localedef_segfault-1.patch
patch -Np1 -i ${DOWNLOADDIR}/glibc-2.5-cross_hacks-2.patch
patch -Np1 -i ${DOWNLOADDIR}/glibc-2.5-branch_update-3.patch
patch -Np1 -i ${DOWNLOADDIR}/glibc-2.5-mips_fixes-1.patch
sed -i '/default) machine=/s/n32/64/g' ports/sysdeps/mips/preconfigure
mkdir -vp ../glibc-build
cd ../glibc-build
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" >> config.cache
echo "libc_cv_mips64_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 ${BUILD64}" AR="${CROSS_TARGET}-ar" \
RANLIB="${CROSS_TARGET}-ranlib" ../glibc-2.5/configure --prefix=/usr \
--libexecdir=/usr/lib/glibc --host=${CROSS_TARGET} --build=${CROSS_HOST} \
--disable-profile --enable-add-ons --with-tls --enable-kernel=2.6.18 \
--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 -r glibc-build
rm -r glibc-2.5
cat > ${TARGET_DIR}/etc/nsswitch.conf ${TARGET_DIR}/etc/ld.so.conf
GCC交叉工具(支持c和c++语言)
tar xvf ${DOWNLOADDIR}/gcc-4.1.2.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gcc-4.1.2
patch -Np1 -i ${DOWNLOADDIR}/gcc-4.1.2-posix-1.patch
patch -Np1 -i ${DOWNLOADDIR}/gcc-4.1.2-cross_search_paths-1.patch
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-4.1.2/configure --prefix=${TARGET_DIR}/cross-tools --host=${CROSS_HOST} \
--target=${CROSS_TARGET} --with-sysroot=${TARGET_DIR} --with-abi=64 \
--disable-nls --enable-shared --disable-multilib --enable-__cxa_atexit \
--enable-c99 --enable-long-long --enable-threads=posix --enable-languages=c,c++
make
make install
cd ..
rm -r gcc-build
rm -r gcc-4.1.2
popd
File软件包
tar xvf ${DOWNLOADDIR}/file-4.19.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/file-4.19
./configure --prefix=${TARGET_DIR}/cross-tools
make
make install
cd ..
rm -r file-4.19
popd
Shadow软件包
tar xvf ${DOWNLOADDIR}/shadow-4.0.18.1.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/shadow-4.0.18.1
patch -Np1 -i ${DOWNLOADDIR}/shadow-4.0.18.1-useradd_fix-1.patch
patch -Np1 -i ${DOWNLOADDIR}/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 -r shadow-4.0.18.1
popd
清理交叉工具链
pushd ${TARGET_DIR}/cross-tools
/usr/bin/find ./{bin,lib} -type f -exec strip --strip-debug '{}' ';'
popd
注意:不正确的清理参数用于库文件的时候有导致库文件 损坏的可能,因此请注意命令的 参数,如果你不放心也可跳过这部分,并不会影响后面的过程。
制作目标系统
环境设置
export CC="${CROSS_TARGET}-gcc"
export CXX="${CROSS_TARGET}-g++"
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\"" >> ~/.bashrc
echo "export CXX=\"${CROSS_TARGET}-g++\"" >> ~/.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-2.43.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/man-pages-2.43
make prefix=${TARGET_DIR} install
cd ..
rm -r man-pages-2.43
popd
---------Binutils--------
tar xvf ${DOWNLOADDIR}/binutils-2.17.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/binutils-2.17
patch -Np1 -i ${DOWNLOADDIR}/binutils-2.17-posix-1.patch
patch -Np1 -i ${DOWNLOADDIR}/binutils-2.17-branch_update-2.patch
patch -Np1 -i ${DOWNLOADDIR}/binutils-2.17-loongson-1.dpatch
mkdir -pv ../binutils-build
cd ../binutils-build
CC="${CC} ${BUILD64}" CXX="${CXX} ${BUILD64}" ../binutils-2.17/configure \
--prefix=/usr --build=${CROSS_HOST} --host=${CROSS_TARGET} \
--enable-64-bit-bfd --enable-shared --disable-multilib
make configure-host
make tooldir=/usr
make DESTDIR=${TARGET_DIR} tooldir=/usr install
cp -v ../binutils-2.17/include/libiberty.h ${TARGET_DIR}/usr/include
cd ..
rm -r binutils-build
rm -r binutils-2.17
popd
-----------GCC------------
tar xvf ${DOWNLOADDIR}/gcc-4.1.2.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gcc-4.1.2
patch -Np1 -i ${DOWNLOADDIR}/gcc-4.1.2-posix-1.patch
patch -Np1 -i ${DOWNLOADDIR}/gcc-4.1.2-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
CC="${CC} ${BUILD64}" CXX="${CXX} ${BUILD64}" ../gcc-4.1.2/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 --with-abi=64 \
--enable-clocale=gnu --enable-languages=c,c++ --disable-libstdcxx-pch \
--disable-multilib
make
make DESTDIR=${TARGET_DIR} install
ln -sv ../usr/bin/cpp ${TARGET_DIR}/lib
ln -sv gcc ${TARGET_DIR}/usr/bin/cc
cd ..
rm -r gcc-build
rm -r gcc-4.1.2
popd
--------Sed-----------
tar xvf ${DOWNLOADDIR}/sed-4.1.5.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/sed-4.1.5
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --bindir=/bin \
--enable-html
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r sed-4.1.5
popd
--------E2fsprogs--------
tar xvf ${DOWNLOADDIR}/e2fsprogs-1.39.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/e2fsprogs-1.39
mkdir -v build
cd build
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ../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 -r e2fsprogs-1.39
popd
---------Coreutils-----------
tar xvf ${DOWNLOADDIR}/coreutils-6.7.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/coreutils-6.7
patch -Np1 -i ${DOWNLOADDIR}/coreutils-6.7-suppress_uptime_kill_su-1.patch
patch -Np1 -i ${DOWNLOADDIR}/coreutils-6.7-uname-1.patch
touch man/uname.1
echo "fu_cv_sys_stat_statfs2_bsize=yes" > config.cache
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --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 -r coreutils-6.7
popd
---------Iana_Etc--------
tar xvf ${DOWNLOADDIR}/iana-etc-2.20.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/iana-etc-2.20
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r iana-etc-2.20
popd
----------M4------------
tar xvf ${DOWNLOADDIR}/m4-1.4.8.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/m4-1.4.8
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r m4-1.4.8
popd
---------Bison---------
tar xvf ${DOWNLOADDIR}/bison-2.3.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/bison-2.3
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
echo '#define YYENABLE_NLS 1' >> config.h
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r bison-2.3
popd
--------Ncurses----------
tar xvf ${DOWNLOADDIR}/ncurses-5.6.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/ncurses-5.6
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./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 -r ncurses-5.6
popd
-----------Procps------------
tar xvf ${DOWNLOADDIR}/procps-3.2.7.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/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 -r procps-3.2.7
popd
-----------Libtool--------------
tar xvf ${DOWNLOADDIR}/libtool-1.5.22.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/libtool-1.5.22
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r libtool-1.5.22
popd
-----------Readline------------
tar xvf ${DOWNLOADDIR}/readline-5.2.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/readline-5.2
patch -Np1 -i ${DOWNLOADDIR}/readline-5.2-fixes-1.patch
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./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 -r readline-5.2
popd
------------Zlib-----------
tar xvf ${DOWNLOADDIR}/zlib-1.2.3.tar.bz -C ${BUILDDIR}
pushd ${BUILDDIR}/zlib-1.2.3
patch -Np1 -i ${DOWNLOADDIR}/zlib-1.2.3-fPIC-1.patch
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./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 -r zlib-1.2.3
popd
-----------Autoconf------------
tar xvf ${DOWNLOADDIR}/autoconf-2.61.tar.bz -C ${BUILDDIR}
pushd ${BUILDDIR}/autoconf-2.61
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r autoconf-2.61
popd
-------------Automake-----------
tar xvf ${DOWNLOADDIR}/automake-1.9.6.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/automake-1.9.6
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r automake-1.9.6
popd
-------------Bash-----------
tar xvf ${DOWNLOADDIR}/bash-3.2.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/bash-3.2
patch -Np1 -i ${DOWNLOADDIR}/bash-3.2-fixes-4.patch
echo "bash_cv_sys_named_pipes=yes" > config.cache
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./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 -r bash-3.2
popd
-------------Bzip2---------------
tar xvf ${DOWNLOADDIR}/bzip2-1.0.4.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/bzip2-1.0.4
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 -r bzip2-1.0.4
popd
------------Diffutils-----------
tar xvf ${DOWNLOADDIR}/diffutils-2.8.7.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/diffutils-2.8.7
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r diffutils-2.8.7
popd
-------------File---------------
tar xvf ${DOWNLOADDIR}/file-4.19.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/file-4.19
patch -Np1 -i ${DOWNLOADDIR}/file-4.19-config_update-1.patch
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r file-4.19
popd
--------------Findutils------------
tar xvf ${DOWNLOADDIR}/findutils-4.2.29.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/findutils-4.2.29
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./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 -r findutils-4.2.29
popd
--------------Flex--------------
tar xvf ${DOWNLOADDIR}/flex-2.5.33.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/flex-2.5.33
cp -v Makefile.in{,.orig} &&
sed "s/-I@includedir@//g" Makefile.in.orig > Makefile.in
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
ln -sv libfl.a ${TARGET_DIR}/usr/lib/libl.a
cd ..
rm -r flex-2.5.33
cat > ${TARGET_DIR}/usr/bin/lex
----------------Gawk------------
tar xvf ${DOWNLOADDIR}/gawk-3.1.5.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gawk-3.1.5
patch -Np1 -i ${DOWNLOADDIR}/gawk-3.1.5-segfault_fix-1.patch
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --libexecdir=/usr/lib
echo '#define HAVE_LANGINFO_CODESET 1' >> config.h
echo '#define HAVE_LC_MESSAGES 1' >> config.h
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r gawk-3.1.5
popd
--------------Gettext--------------
tar xvf ${DOWNLOADDIR}/gawk-3.1.5.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gawk-3.1.5
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r gawk-3.1.5
popd
-----------------Grep--------------
tar xvf ${DOWNLOADDIR}/grep-2.5.1a.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/grep-2.5.1a
patch -Np1 -i ${DOWNLOADDIR}/grep-2.5.1a-config_update-1.patch
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --bindir=/bin \
--disable-perl-regexp
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r grep-2.5.1a
popd
---------------Groff----------------
tar xvf ${DOWNLOADDIR}/groff-1.19.2.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/groff-1.19.2
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" PAGE=A4 ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make TROFFBIN=troff GROFFBIN=groff GROFF_BIN_PATH=
make prefix=${TARGET_DIR}/usr install
ln -sv soelim ${TARGET_DIR}/usr/bin/zsoelim
ln -sv eqn ${TARGET_DIR}/usr/bin/geqn
ln -sv tbl ${TARGET_DIR}/usr/bin/gtbl
cd ..
rm -r groff-1.19.2
popd
---------------Gzip--------------------
tar xvf ${DOWNLOADDIR}/gzip-1.3.9.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/gzip-1.3.9
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./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 -r gzip-1.3.9
popd
--------------Inetutils---------------
tar xvf ${DOWNLOADDIR}/inetutils-1.5.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/inetutils-1.5
patch -Np1 -i ${DOWNLOADDIR}/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
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./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
cd ..
rm -r inetutils-1.5
popd
-------------Iproute2------------
tar xvf ${DOWNLOADDIR}/iproute2-2.6.18-061002.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/iproute2-2.6.18-061002
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} ${BUILD64}" SBINDIR=/sbin
make DESTDIR=${TARGET_DIR} SBINDIR=/sbin install
cd ..
rm -r iproute2-2.6.18-061002
popd
-------------Kbd------------------
tar xvf ${DOWNLOADDIR}/kbd-1.12.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/kbd-1.12
patch -Np1 -i ${DOWNLOADDIR}/kbd-1.12-gcc4_fixes-1.patch
cp configure{,.orig} &&
sed -e "s@&& ./conftest@@" configure.orig > configure
cp src/Makefile.in{,.orig} &&
sed -e "s/install -s/install/" src/Makefile.in.orig > src/Makefile.in
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--datadir=/lib/kbd
cp make_include{,.orig} &&
sed "/^ARCH/s/=.*/=mips64el/" make_include.orig > make_include
make CC="${CC} ${BUILD64}"
make DESTDIR=${TARGET_DIR} install
mv -v ${TARGET_DIR}/usr/bin/{kbd_mode,openvt,setfont} ${TARGET_DIR}/bin
cd ..
rm -r kbd-1.12
popd
-------------Less------------
tar xvf ${DOWNLOADDIR}/less-394.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/less-394
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./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 -r less-394
popd
------------Make------------
tar xvf ${DOWNLOADDIR}/make-3.81.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/make-3.81
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r make-3.81
popd
--------------Man---------------
tar xvf ${DOWNLOADDIR}/man-1.6e.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/man-1.6e
cp configure{,.orig} &&
sed -e "/PREPATH=/s@=.*@=\"$(eval echo ${TARGET_DIR}/{,usr/}{sbin,bin})\"@g" \
-e 's@-is@&R@g' configure.orig > configure
cp src/man.conf.in{,.orig} &&
sed -e 's@MANPATH./usr/man@#&@g' -e 's@MANPATH./usr/local/man@#@g' src/man.conf.in.orig \
> src/man.conf.in
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
-confdir=/etc
cp conf_script{,.orig} &&
sed "s@${TARGET_DIR}@@" conf_script.orig > conf_script
gcc src/makemsg.c -o src/makemsg
make CC="${CC} ${BUILD64}"
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r man-1.6e
popd
------------Mktemp------------
tar xvf ${DOWNLOADDIR}/mktemp-1.5.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/mktemp-1.5
patch -Np1 -i ${DOWNLOADDIR}/mktemp-1.5-add_tempfile-3.patch
cp Makefile.in{,.orig} &&
sed -e 's/-s $(PROG)/$(PROG)/' Makefile.in.orig > Makefile.in
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --with-libc
make
make prefix=${TARGET_DIR}/usr install
make prefix=${TARGET_DIR}/usr install-tempfile
cd ..
rm -r mktemp-1.5
popd
--------Module_Init_Tools------------
tar xvf ${DOWNLOADDIR}/module-init-tools-3.2.2.tar.bz -C ${BUILDDIR}
pushd ${BUILDDIR}/module-init-tools-3.2.2
patch -Np1 -i ${DOWNLOADDIR}/module-init-tools-3.2.2-config_update-1.patch
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/ --enable-zlib
make
make DESTDIR=${TARGET_DIR} INSTALL=install install
cd ..
rm -r module-init-tools-3.2.2
popd
-------------Patch-----------
tar xvf ${DOWNLOADDIR}/patch-2.5.9.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/patch-2.5.9
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make
make prefix=${TARGET_DIR}/usr install
cd ..
rm -r patch-2.5.9
popd
-------------Psmisc--------------
tar xvf ${DOWNLOADDIR}/psmisc-22.3.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/psmisc-22.3
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --exec-prefix=""
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 -r psmisc-22.3
popd
-----------Shadow--------------
tar xvf ${DOWNLOADDIR}/shadow-4.0.18.1.tar.bz -C ${BUILDDIR}
pushd ${BUILDDIR}/shadow-4.0.18.1
patch -Np1 -i ${DOWNLOADDIR}/shadow-4.0.18.1-useradd_fix-1.patch
echo "ac_cv_func_setpgrp_void=yes" > config.cache
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./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
cd ..
rm -r shadow-4.0.18.1
popd
-------------Sysklogd-------------
tar xvf ${DOWNLOADDIR}/sysklogd-1.4.1.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/sysklogd-1.4.1
patch -Np1 -i ${DOWNLOADDIR}/sysklogd-1.4.1-fixes-2.patch
cp Makefile{,.orig} &&
sed -e 's/-o ${MAN_USER} -g ${MAN_GROUP}//' -e 's/500 -s/500/' Makefile.orig > Makefile
make CC="${CC} ${BUILD64}"
make prefix=${TARGET_DIR} install
cd ..
rm -r sysklogd-1.4.1
cat > ${TARGET_DIR}/etc/syslog.conf
-----------Sysvinit-----------
tar xvf ${DOWNLOADDIR}/sysvinit-2.86.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/sysvinit-2.8
cp src/init.c{,.orig} &&
sed 's@Sending processes@& started by init@g' src/init.c.orig > src/init.c
cp -v src/Makefile src/Makefile.orig &&
sed -e 's@/dev/initctl@$(ROOT)&@g' -e 's@\(mknod \)-m \([0-9]* \)\(.* \)p@\1\3p; chmod \2\3@g' \
-e '/^ifeq/s/$(ROOT)//' -e 's@/usr/lib@$(ROOT)&@' src/Makefile.orig > src/Makefile
make -C src clobber
make -C src ROOT=${TARGET_DIR} CC="${CC} ${BUILD64}"
make -C src ROOT=${TARGET_DIR} INSTALL="install" install
cd ..
rm -r sysvinit-2.8
cat > ${TARGET_DIR}/etc/inittab
-----------Tar-------------
tar xvf ${DOWNLOADDIR}/tar-1.16.1.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/tar-1.16.1
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr --bindir=/bin \
--libexecdir=/usr/sbin
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r tar-1.16.1
popd
------------Texinfo--------------
tar xvf ${DOWNLOADDIR}/texinfo-4.8a.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/texinfo-4.8
patch -Np1 -i ${DOWNLOADDIR}/texinfo-4.8a-tempfile_fix-1.patch
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure \
--build=${CROSS_HOST} --host=${CROSS_TARGET} --prefix=/usr
make
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r texinfo-4.8
popd
pushd ${TARGET_DIR}/usr/share/info
rm dir
for f in *
do install-info ${f} dir 2>/dev/null
done
popd
-------------Udev-------------
tar xvf ${DOWNLOADDIR}/udev-104.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/udev-104
make CROSS_COMPILE="${CROSS_TARGET}-" CC="${CC} ${BUILD64}" LD="${CC} ${BUILD64}" \
EXTRAS="extras/floppy extras/cdrom_id extras/firmware extras/scsi_id
extras/volume_id extras/ata_id extras/usb_id extras/edd_id
extras/dasd_id extras/path_id"
make DESTDIR="${TARGET_DIR}" EXTRAS="extras/floppy extras/cdrom_id
extras/firmware extras/scsi_id extras/volume_id extras/ata_id
extras/usb_id extras/edd_id extras/dasd_id extras/path_id" install
install -v extras/eventrecorder.sh ${TARGET_DIR}/lib/udev
install -v -m644 -D docs/writing_udev_rules/index.html \
${TARGET_DIR}/usr/share/doc/udev-104/index.html
install -dv ${TARGET_DIR}/lib/firmware
cd ..
rm -r udev-104
popd
------------Util_Linux-----------
tar xvf ${DOWNLOADDIR}/util-linux-2.12r.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/util-linux-2.12r
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
patch -Np1 -i ${DOWNLOADDIR}/util-linux-2.12r-cramfs-1.patch
patch -Np1 -i ${DOWNLOADDIR}/util-linux-2.12r-syscall_fixes-1.patch
patch -Np1 -i ${DOWNLOADDIR}/util-linux-2.12r-missing_header-1.patch
patch -Np1 -i ${DOWNLOADDIR}/util-linux-2.12r-missing_lseek-1.patch
cp MCONFIG{,.orig} &&
sed -e "s/-o root//" MCONFIG.orig > MCONFIG
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./configure
make HAVE_KILL=yes HAVE_SLN=yes CPUOPT="" ARCH="" CPU=""
make HAVE_KILL=yes HAVE_SLN=yes CPUOPT="" ARCH="" CPU="" \
USE_TTY_GROUP=no DESTDIR=${TARGET_DIR} install
mv -v ${TARGET_DIR}/usr/bin/logger ${TARGET_DIR}/bin
cd ..
rm -r util-linux-2.12r
popd
-----------Vim-------------
tar xvf ${DOWNLOADDIR}/vim-7.0.tar.bz2 -C ${BUILDDIR}
tar xvf ${DOWNLOADDIR}/vim-7.0-extra.tar.gz -C ${BUILDDIR}
tar xvf ${DOWNLOADDIR}/vim-7.0-lang.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/vim70
patch -Np1 -i ${DOWNLOADDIR}/vim-7.0-cross_compile-1.patch
patch -Np1 -i ${DOWNLOADDIR}/vim-7.0-fixes-21.patch
echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h
CC="${CROSS_TARGET}-gcc ${BUILD64}" CXX="${CROSS_TARGET}-g++ ${BUILD64}" ./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
make
make DESTDIR=${TARGET_DIR} install
ln -sv vim ${TARGET_DIR}/usr/bin/vi
ln -sv ../vim/vim70/doc ${TARGET_DIR}/usr/share/doc/vim-7.0
cd ..
rm -r vim70
cat > ${TARGET_DIR}/etc/vimrc
---------Bootscripts-1.1-pre3--------------
tar xvf ${DOWNLOADDIR}/bootscripts-cross-lfs-1.1-pre3.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/bootscripts-cross-lfs
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r bootscripts-cross-lfs
popd
---------Udev_Rules-1.1-pre3--------------
tar xvf ${DOWNLOADDIR}/udev-cross-lfs-1.1-pre3.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/udev-cross-lfs
make DESTDIR=${TARGET_DIR} install
cd ..
rm -r udev-cross-lfs
popd
编译内核tar xvf ${DOWNLOADDIR}/linux-2.6.18.1.tar.gz -C ${BUILDDIR}
pushd ${BUILDDIR}/linux-2.6.18.1
patch -Np1 -i ${DOWNLOADDIR}/linux-2.6.18.1-loongson-1.patch &&
make mrproper &&
cp ${DOWNLOADDIR}/config-2.6.18.1-loongson .config &&
make ARCH=mips CROSS_COMPILE=${CROSS_TARGET}- menuconfig &&
make ARCH=mips CROSS_COMPILE=${CROSS_TARGET}- &&
make ARCH=mips CROSS_COMPILE=${CROSS_TARGET}- INSTALL_MOD_PATH=${TARGET_DIR} modules_install &&
cp vmlinux.32 ${TARGET_DIR}/boot/loongson-vmlinux-64-2.6.18.1 &&
cp System.map ${TARGET_DIR}/boot/loongson-System.map-64-2.6.18.1
cd ..
popd
一个建议:内核编译目录可以保留不必删除,因为今后的一些编译有可能需要内核源码
新系统必要的配置文件
时间设置文件 cat > ${TARGET_DIR}/etc/sysconfig/clock
设置bash下的键盘功能键设置 cat > ${TARGET_DIR}/etc/inputrc
设置Bash Shell启动文件(The Bash Shell Startup Files) cat > ${TARGET_DIR}/etc/profile
设置本地网络名
echo "HOSTNAME=loongsonbox" > ${TARGET_DIR}/etc/sysconfig/network
设置hosts文件
cat > ${TARGET_DIR}/etc/hosts
设置网络的静态地址
pushd ${TARGET_DIR}/etc/sysconfig/network-devices &&
mkdir -v ifconfig.eth0 &&
cat > ifconfig.eth0/ipv4 注意:IP、GATEWAY、BROADCAST的地址根据自己的实际情况设置。
设置DNS
cat > ${TARGET_DIR}/etc/resolv.conf
建立fstab文件
cat > ${TARGET_DIR}/etc/fstab 注意:这里的磁盘名以及文件系统名需要根据实际情况修改。
系统的打包及启动系统 完成 后可以用 exit
退出loongson用户
重新进入root用户 export TARGET_DIR=/loongson
pushd ${TARGET_DIR}
mknod -m 600 dev/console c 5 1
mknod -m 666 dev/null c 1 3
chown -R root:root *
打包整个系统,用如下命令
tar -cjf loongson-system-64.tar.bz2 *
来打包并压缩,以便复制到目标机器上展开。
一些建议 新系统建议展开到一个空白分区中,并且分区的文件系统应是内核支持的文件系统,并且和做好的系统中/etc/fstab中的文件系统描述一致。
在系统正确运行在目标系统上后可以编译Perl并重新编译File软件包。
结束(转载请保持文章的完整性,请注明作者和出处)
作者:孙海勇
Email:youbest@sina.com
2007年2月18日
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/17412/showart_249588.html |
|