Chinaunix首页 | 论坛 | 博客
  • 博客访问: 219993
  • 博文数量: 19
  • 博客积分: 757
  • 博客等级: 军士长
  • 技术积分: 320
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-08 07:55
个人简介

醉卧沙场君莫笑

文章分类

全部博文(19)

文章存档

2016年(5)

2015年(2)

2014年(3)

2013年(1)

2012年(5)

2011年(3)

分类: LINUX

2014-01-21 21:43:23

本文的脚本整理来自clfs的构建,参考下面网页,将所有步骤写成了一个脚本:

 http://cross-lfs.org/files/BOOK/1.2.0/CLFS-mips.html


step 1:本机库安装,在编译的过程中,可能会发现本机缺少库,可以通过apt-get install packagename安装。

step 2:下载相关文件 http://ftp.cross-lfs.org/pub/clfs/clfs-packages/clfs-packages-1.2.0.tar

step 3: 建立一个目录,这个目录是我们的工作目录,在工作目录下建立sources和scripts两个目录。把下载的文件解压到sources文件夹里面,把下面的build.sh放在scripts里面。

点击(此处)折叠或打开

  1. mkdir clfs
  2. cd clfs
  3. mkdir sources
  4. mkdir scripts
  5. tar -xf clfs-packages-1.2.0.tar -C sources
将以下脚本拷贝到scripts目录下,并chmod +x build.sh,然后运行cd scripts && ./build.sh。如果一切顺利的话,会在clfs/sys_root/cross-tools/bin下生成目标文件。

脚本build.sh内容:



点击(此处)折叠或打开

  1. #!/bin/bash

  2. PWD=$(pwd)
  3. J=4
  4. export CLFS=${PWD}/../clfs
  5. export SYS_ROOT=${PWD}/../sys_root
  6. export BUILD=${PWD}/../build
  7. export SRC=${PWD}/../sources

  8. unset CFLAGS
  9. unset CXXFLAGS

  10. export CLFS_HOST=$(echo ${MACHTYPE} | sed -e 's/-[^-]*/-cross/')
  11. export CLFS_TARGET="mips64el-unknown-linux-gnu"
  12. export PATH=$PATH:${SYS_ROOT}/cross-tools/bin/

  13. die()
  14. {
  15. echo -e "\n**********\033[41m$1 \033[0m**********\n"
  16. echo -e "\n**********\033[41m$1 \033[0m**********\n" >> time.txt
  17. exit -1
  18. }

  19. bar()
  20. {
  21. let stage+=1
  22. echo -e "[$(date +%T)] \033[31m +++++++++++++++ STAGE $stage: $1 +++++++++++++++ \033[0m"
  23. echo -e "[$(date +%T)] \033[31m +++++++++++++++ STAGE $stage: $1 +++++++++++++++ \033[0m" >> time.txt
  24. }

  25. :<< EOFEOF
  26. EOFEOF

  27. if [ "x$1" = "xclean" ]; then
  28. rm -rf ${BUILD} ${SYS_ROOT} ${CLFS}
  29. fi

  30. mkdir -p ${BUILD} ${SYS_ROOT} ${CLFS}

  31. ### clean time.txt
  32. cat /dev/null > time.txt

  33. bar 'Start..'
  34. ### Installation of Linux-Headers
  35. bar 'install linux-headers..'
  36. if [ ! -d ${BUILD}/linux-2.6.39 ]; then
  37. [ -f ${SRC}/linux-2.6.39.tar.bz2 ] || die "Miss linux kernel "
  38. tar -xjf ${SRC}/linux-2.6.39.tar.bz2 -C ${BUILD}
  39. fi
  40. cd ${BUILD}/linux-2.6.39
  41. install -dv ${SYS_ROOT}/tools/include
  42. make mrproper > /dev/null || die "Install Linux Headers 1"
  43. make ARCH=mips headers_check > /dev/null || die "Install Linux Headers 2"
  44. make ARCH=mips INSTALL_HDR_PATH=dest headers_install > /dev/null || die "Install Linux Headers 3"
  45. cp -rv dest/include/* ${SYS_ROOT}/tools/include > /dev/null

  46. bar 'build file..'
  47. if [ ! -d ${BUILD}/file-5.07 ]; then
  48. tar -xzf ${SRC}/file-5.07.tar.gz -C ${BUILD} || die "tar file"
  49. fi
  50. cd ${BUILD}/file-5.07
  51. ./configure --prefix=${SYS_ROOT}/cross-tools > /dev/null || die "configure"
  52. make -j${J} > /dev/null || die "make file"
  53. make install || die "install file"

  54. bar 'build m4..'
  55. if [ ! -d ${BUILD}/m4-1.4.16 ]; then
  56. tar -xjf ${SRC}/m4-1.4.16.tar.bz2 -C ${BUILD} || die "tar m4"
  57. fi
  58. cd ${BUILD}/m4-1.4.16
  59. ./configure --prefix=${SYS_ROOT}/cross-tools > /dev/null || die "configure"
  60. make -j${J} > /dev/null || die "make m4"
  61. make install || die "install m4"

  62. bar 'build ncurses..'
  63. if [ ! -d ${BUILD}/ncurses-5.9 ]; then
  64. tar -xzf ${SRC}/ncurses-5.9.tar.gz -C ${BUILD} || die "tar ncurses"
  65. cd ${BUILD}/ncurses-5.9
  66. patch -Np1 -i ${SRC}/ncurses-5.9-bash_fix-1.patch > /dev/null
  67. fi
  68. cd ${BUILD}/ncurses-5.9
  69. ./configure --prefix=${SYS_ROOT}/cross-tools \
  70. --without-debug --without-shared > /dev/null || die "configure"
  71. make -C include > /dev/null || die "make ncurses"
  72. make -C progs tic > /dev/null || die "make ncurses"
  73. install -v -m755 progs/tic ${SYS_ROOT}/cross-tools/bin > /dev/null || die "install ncurses"

  74. bar 'build gmp..'
  75. if [ ! -d ${BUILD}/gmp-5.0.2 ]; then
  76. tar -xjf ${SRC}/gmp-5.0.2.tar.bz2 -C ${BUILD} || die "tar gmp"
  77. fi
  78. cd ${BUILD}/gmp-5.0.2
  79. CPPFLAGS=-fexceptions ./configure \
  80. --prefix=${SYS_ROOT}/cross-tools --enable-cxx > /dev/null || die "configure"
  81. make -j${J} > /dev/null || die "make gmp"
  82. make install > /dev/null || die "install gmp"

  83. bar 'build mpfr..'
  84. if [ ! -d ${BUILD}/mpfr-3.0.1 ]; then
  85. tar -xjf ${SRC}/mpfr-3.0.1.tar.bz2 -C ${BUILD} || die "tar mpfr"
  86. fi
  87. cd ${BUILD}/mpfr-3.0.1
  88. LDFLAGS="-Wl,-rpath,${SYS_ROOT}/cross-tools/lib" \
  89. ./configure --prefix=${SYS_ROOT}/cross-tools \
  90. --enable-shared --with-gmp=${SYS_ROOT}/cross-tools > /dev/null || die "configure"
  91. make -j${J} > /dev/null || die "make mpfr"
  92. make install > /dev/null || die "install mpfr"

  93. bar 'build mpc..'
  94. if [ ! -d ${BUILD}/mpc-0.9 ]; then
  95. tar -xzf ${SRC}/mpc-0.9.tar.gz -C ${BUILD} || die "tar mpc"
  96. fi
  97. cd ${BUILD}/mpc-0.9
  98. LDFLAGS="-Wl,-rpath,${SYS_ROOT}/cross-tools/lib" \
  99. ./configure --prefix=${SYS_ROOT}/cross-tools \
  100. --with-gmp=${SYS_ROOT}/cross-tools \
  101. --with-mpfr=${SYS_ROOT}/cross-tools > /dev/null || die "configure"
  102. make -j${J} > /dev/null || die "make mpc"
  103. make install > /dev/null || die "install mpc"


  104. bar 'build ppl..'
  105. if [ ! -d ${BUILD}/ppl-0.11.2 ]; then
  106. tar -xjf ${SRC}/ppl-0.11.2.tar.bz2 -C ${BUILD} || die "tar ppl"
  107. fi
  108. cd ${BUILD}/ppl-0.11.2
  109. CPPFLAGS="-I${SYS_ROOT}/cross-tools/include" \
  110. LDFLAGS="-Wl,-rpath,${SYS_ROOT}/cross-tools/lib" \
  111. ./configure --prefix=${SYS_ROOT}/cross-tools --enable-shared \
  112. --enable-interfaces="c,cxx" --disable-optimization \
  113. --with-libgmp-prefix=${SYS_ROOT}/cross-tools \
  114. --with-libgmpxx-prefix=${SYS_ROOT}/cross-tools > /dev/null || die "configure"
  115. make -j${J} > /dev/null || die "make ppl"
  116. make install > /dev/null || die "install ppl"

  117. bar 'build cloog-ppl..'
  118. if [ ! -d cloog-ppl-0.15.11 ]; then
  119. tar -xzf ${SRC}/cloog-ppl-0.15.11.tar.gz -C ${BUILD}
  120. fi
  121. cd ${BUILD}/cloog-ppl-0.15.11
  122. cp -v configure{,.orig}
  123. sed -e "/LD_LIBRARY_PATH=/d" \
  124. configure.orig > configure
  125. LDFLAGS="-Wl,-rpath,${SYS_ROOT}/cross-tools/lib" \
  126. ./configure --prefix=${SYS_ROOT}/cross-tools --enable-shared --with-bits=gmp \
  127. --with-gmp=${SYS_ROOT}/cross-tools --with-ppl=${SYS_ROOT}/cross-tools > /dev/null || die "configure"
  128. make -j${J} > /dev/null || die "make cloog-ppl"
  129. make install > /dev/null || die "install cloog-ppl"


  130. ###
  131. bar 'build binutils..'
  132. if [ ! -d ${BUILD}/binutils-2.21.1 ]; then
  133. tar -xjf ${SRC}/binutils-2.21.1a.tar.bz2 -C ${BUILD} || die "tar binutils"
  134. fi
  135. mkdir -p ${BUILD}/binutils-build
  136. cd ${BUILD}/binutils-build
  137. AR=ar AS=as ../binutils-2.21.1/configure \
  138. --prefix=${SYS_ROOT}/cross-tools --host=${CLFS_HOST} --target=${CLFS_TARGET} \
  139. --with-sysroot=${CLFS} --with-lib-path=${SYS_ROOT}/tools/lib --disable-nls --enable-shared \
  140. --disable-multilib > /dev/null || die "configure"
  141. make configure-host > /dev/null
  142. make -j${J} > /dev/null || die "make binutils"
  143. make install > /dev/null || die "install binutils"
  144. cp -v ../binutils-2.21.1/include/libiberty.h ${SYS_ROOT}/tools/include

  145. bar 'build gcc(static)..'
  146. if [ ! -d ${BUILD}/gcc-4.6.0 ]; then
  147. tar -xjf ${SRC}/gcc-4.6.0.tar.bz2 -C ${BUILD} || die "tar gcc"
  148. cd ${BUILD}/gcc-4.6.0
  149. patch -Np1 -i ${SRC}/gcc-4.6.0-branch_update-1.patch > /dev/null
  150. patch -Np1 -i ${SRC}/gcc-4.6.0-pure64_specs-1.patch > /dev/null
  151. patch -Np1 -i ${SRC}/gcc-4.6.0-mips_fix-1.patch > /dev/null
  152. echo -en "#undef STANDARD_INCLUDE_DIR\n#define STANDARD_INCLUDE_DIR \"${SYS_ROOT}/tools/include/\"\n\n" >> gcc/config/linux.h
  153. echo -en "\n#undef STANDARD_STARTFILE_PREFIX_1\n#define STANDARD_STARTFILE_PREFIX_1 \"${SYS_ROOT}/tools/lib/\"\n" >> gcc/config/linux.h
  154. echo -en '\n#undef STANDARD_STARTFILE_PREFIX_2\n#define STANDARD_STARTFILE_PREFIX_2 ""\n' >> gcc/config/linux.h
  155. echo -en "\n#undef CROSS_INCLUDE_DIR\n#define CROSS_INCLUDE_DIR \"${SYS_ROOT}/tools/include\"\n" >> gcc/config/linux.h
  156. cp -v gcc/Makefile.in{,.orig}
  157. #sed -i "s@\(^CROSS_SYSTEM_HEADER_DIR =\).*@\1 \"${SYS_ROOT}/tools/include\"@g" gcc/Makefile.in
  158. sed -i "/\-DCROSS_INCLUDE_DIR/d" gcc/Makefile.in
  159. touch ${SYS_ROOT}/tools/include/limits.h
  160. rm -rf ${BUILD}/gcc-build
  161. mkdir -vp ${BUILD}/gcc-build
  162. fi
  163. cd ${BUILD}/gcc-build
  164. AR=ar LDFLAGS="-Wl,-rpath,${SYS_ROOT}/cross-tools/lib" \
  165. ../gcc-4.6.0/configure --prefix=${SYS_ROOT}/cross-tools \
  166. --build=${CLFS_HOST} --host=${CLFS_HOST} --target=${CLFS_TARGET} \
  167. --with-sysroot=${CLFS} --with-local-prefix=${SYS_ROOT}/tools --disable-nls \
  168. --disable-shared --with-mpfr=${SYS_ROOT}/cross-tools --with-gmp=${SYS_ROOT}/cross-tools \
  169. --with-ppl=${SYS_ROOT}/cross-tools --with-cloog=${SYS_ROOT}/cross-tools \
  170. --without-headers --with-newlib --disable-decimal-float \
  171. --disable-libgomp --disable-libmudflap --disable-libssp \
  172. --disable-threads --enable-languages=c --disable-multilib > /dev/null || die "configure"

  173. make all-gcc all-target-libgcc -j${J} > /dev/null || die "make gcc"
  174. make install-gcc install-target-libgcc > /dev/null || die "install gcc"


  175. bar 'build eglibc..'
  176. rm ${BUILD}/eglibc* -rf
  177. if [ ! -d ${BUILD}/eglibc-2.13 ]; then
  178. tar -xjf ${SRC}/eglibc-2.13-r13356.tar.bz2 -C ${BUILD} || die "tar eglibc"
  179. cd ${BUILD}/eglibc-2.13
  180. tar -jxf ${SRC}/eglibc-ports-2.13-r13356.tar.bz2 || die "tar ports"
  181. cp -v Makeconfig{,.orig}
  182. sed -e 's/-lgcc_eh//g' Makeconfig.orig > Makeconfig
  183. sed -i "s@\(ldd_rewrite_script=\).*@\1${BUILD}/eglibc-2.13/ports/sysdeps/unix/sysv/linux/mips/mips64/@" \
  184. ports/sysdeps/unix/sysv/linux/mips/mips64/configure || die "sed"
  185. mkdir ${BUILD}/eglibc-build
  186. fi
  187. cd ${BUILD}/eglibc-build
  188. cat > config.cache << EOF
  189. libc_cv_forced_unwind=yes
  190. libc_cv_c_cleanup=yes
  191. libc_cv_gnu89_inline=yes
  192. libc_cv_ssp=no
  193. EOF
  194. BUILD_CC="gcc" CC="${CLFS_TARGET}-gcc" \
  195. AR="${CLFS_TARGET}-ar" RANLIB="${CLFS_TARGET}-ranlib" \
  196. ../eglibc-2.13/configure --prefix=${SYS_ROOT}/tools \
  197. --host=${CLFS_TARGET} --build=${CLFS_HOST} \
  198. --disable-profile --enable-add-ons \
  199. --with-tls --enable-kernel=2.6.0 --with-__thread \
  200. --with-binutils=${SYS_ROOT}/cross-tools/bin --with-headers=${SYS_ROOT}/tools/include \
  201. --cache-file=config.cache > /dev/null || die "configure"
  202. make -j${J} > /dev/null || die "make eglib"
  203. make install > /dev/null || die "install eglib"

  204. bar 'build gcc..(2)'
  205. if [ ! -d ${BUILD}/gcc-4.6.0 ]; then
  206. tar -xjf ${SRC}/gcc-4.6.0.tar.bz2 -C ${BUILD} || die "tar gcc"
  207. cd ${BUILD}/gcc-4.6.0
  208. patch -Np1 -i ${SRC}/gcc-4.6.0-branch_update-1.patch > /dev/null
  209. patch -Np1 -i ${SRC}/gcc-4.6.0-pure64_specs-1.patch > /dev/null
  210. patch -Np1 -i ${SRC}/gcc-4.6.0-mips_fix-1.patch > /dev/null
  211. echo -en "#undef STANDARD_INCLUDE_DIR\n#define STANDARD_INCLUDE_DIR \"${SYS_ROOT}/tools/include/\"\n\n" >> gcc/config/linux.h
  212. echo -en "\n#undef STANDARD_STARTFILE_PREFIX_1\n#define STANDARD_STARTFILE_PREFIX_1 \"${SYS_ROOT}/lib/\"\n" >> gcc/config/linux.h
  213. echo -en '\n#undef STANDARD_STARTFILE_PREFIX_2\n#define STANDARD_STARTFILE_PREFIX_2 ""\n' >> gcc/config/linux.h
  214. echo -en "\n#undef CROSS_INCLUDE_DIR\n#define CROSS_INCLUDE_DIR \"${SYS_ROOT}/tools/include\"\n" >> gcc/config/linux.h
  215. fi
  216. rm -rf ${BUILD}/gcc-build/*
  217. cd ${BUILD}/gcc-build
  218. AR=ar LDFLAGS="-Wl,-rpath,${SYS_ROOT}/cross-tools/lib" \
  219. ../gcc-4.6.0/configure --prefix=${SYS_ROOT}/cross-tools \
  220. --build=${CLFS_HOST} --target=${CLFS_TARGET} --host=${CLFS_HOST} \
  221. --with-sysroot=/ --with-local-prefix=${SYS_ROOT}/tools --disable-nls \
  222. --enable-shared --enable-languages=c,c++ --enable-__cxa_atexit \
  223. --with-mpfr=${SYS_ROOT}/cross-tools --with-gmp=${SYS_ROOT}/cross-tools --enable-c99 \
  224. --with-ppl=${SYS_ROOT}/cross-tools --with-cloog=${SYS_ROOT}/cross-tools \
  225. --enable-long-long --enable-threads=posix --disable-multilib > /dev/null || die "configure"
  226. make AS_FOR_TARGET="${CLFS_TARGET}-as" \
  227. LD_FOR_TARGET="${CLFS_TARGET}-ld" -j${J} > /dev/null || die "make gcc (2)"
  228. make install > /dev/null || die "install gcc (2)"


  229. bar 'done'
  230. echo -e "\033[35m ALL DONE \033[0m"


阅读(3516) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~