Chinaunix首页 | 论坛 | 博客
  • 博客访问: 523256
  • 博文数量: 80
  • 博客积分: 1496
  • 博客等级: 上尉
  • 技术积分: 1292
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-18 11:24
个人简介

IT码农一个~

文章分类

全部博文(80)

文章存档

2020年(3)

2019年(7)

2017年(1)

2016年(2)

2015年(2)

2014年(26)

2013年(26)

2012年(2)

2011年(1)

2010年(1)

2008年(9)

我的朋友

分类: LINUX

2014-06-26 17:49:45

直接贴代码,有英文注释,
里面很多地方的选项可以根据情况打开
默认会安装在/usr/local/bin下
如果想安装其他版本,只需要改变第5行中的version字段即可。
下载、编译、环境变量设置 一条龙。


点击(此处)折叠或打开

  1. #! /bin/bash

  2. # this script make it easy for user to update or install a new version gcc

  3. GCC_V='4.9.0'
  4. INSTALL_DIR=/usr/local

  5. # install some basic utils
  6. sudo yum install -y binutils glibc-static libstdc++-static;

  7. # wget http://ftp.gnu.org/gnu/gcc/gcc-${GCC_V}/gcc-${GCC_V}.tar.bz2 -O gcc-${GCC_V}.tar.bz2
  8. wget http://mirror.bjtu.edu.cn/gnu/gcc/gcc-${GCC_V}/gcc-${GCC_V}.tar.bz2

  9. #wget http://mirrors.ustc.edu.cn/gnu/gcc/gcc-${GCC_V}/gcc-${GCC_V}.tar.bz2
  10. tar jxf gcc-${GCC_V}.tar.bz2
  11. cd gcc-${GCC_V}

  12. # let the gcc download it's need
  13. ./contrib/download_prerequisites
  14. cd ..

  15. # build in a separate dir
  16. mkdir build_gcc${GCC_V}
  17. cd build_gcc${GCC_V}

  18. # these options are refer to the system built-in gcc-4.4.7 options
  19. # you can change it as you need
  20. ../gcc-${GCC_V}/configure --prefix=${INSTALL_DIR} --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++ --disable-dssi --disable-multilib --enable-libgcj-multifile --with-ppl --with-cloog --with-tune=generic

  21. # this number can change , which N may from 2 ~ 64 ,depend on your core numbers
  22. # usually it use N = 2 * Core
  23. make -j2
  24. sudo make install

  25. #if you want to install in a different dir
  26. # or you want install it to other same platform os, you can use
  27. # mkdir /home/xxx/gcc-${GCC_V}-install
  28. # make DESTDIR=/home/xxx/gcc-${GCC_V}-install install
  29. # tar jcf gcc-${GCC_V}-install.tar.bz2 /home/xxx/gcc-${GCC_V}-install
  30. # once you've copied this bz2 to the dest os, you can
  31. # tar jxvf gcc-${GCC_V}-install.tar.bz2
  32. # cd gcc-${GCC_V}-install
  33. # sudo cp -rH usr / # this will copy the bins and libs to the root dir


  34. cd ..

  35. echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${INSTALL_DIR}/lib64:${INSTALL_DIR}/lib" >> ~/.bash_profile
  36. echo "export LD_LIBRARY_PATH" >> ~/.bash_profile
  37. . ~/.bash_profile

  38. # if you want to install gcc for all users
  39. # you may add LD_LIBRARY_PATH to /etc/ld.so.conf.d/gcc.conf
  40. # echo "${INSTALL_DIR}/lib64" >> /etc/ld.so.conf.d/gcc.conf
  41. # echo "${INSTALL_DIR}/lib" >> /etc/ld.so.conf.d/gcc.conf

  42. sudo ldconfig

  43. #rm -rf build_gcc${GCC_V} gcc-${GCC_V}

#! /bin/bash

# this script make it easy for user to update or install a new version gcc
GCC_V='4.9.0'
INSTALL_DIR=/usr/local

# install some basic utils
sudo yum install -y binutils glibc-static libstdc++-static;

# wget {GCC_V}/gcc-${GCC_V}.tar.bz2 -O gcc-${GCC_V}.tar.bz2
wget {GCC_V}/gcc-${GCC_V}.tar.bz2
#wget {GCC_V}/gcc-${GCC_V}.tar.bz2
tar jxf gcc-${GCC_V}.tar.bz2
cd gcc-${GCC_V}

# let the gcc download it's need
./contrib/download_prerequisites
cd ..

# build in a separate dir
mkdir build_gcc${GCC_V}
cd build_gcc${GCC_V}

# these options are refer to the system built-in gcc-4.4.7 options
# you can change it as you need
../gcc-${GCC_V}/configure --prefix=${INSTALL_DIR} --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++ --disable-dssi --disable-multilib --enable-libgcj-multifile --with-ppl --with-cloog --with-tune=generic

# this number can change , which N may from 2 ~ 64 ,depend on your core numbers
# usually it use N = 2 * Core 
make -j2
sudo make install

#if you want to install in a different dir
# or you want install it to other same platform os, you can use 
# mkdir /home/xxx/gcc-${GCC_V}-install
# make DESTDIR=/home/xxx/gcc-${GCC_V}-install install
# tar jcf gcc-${GCC_V}-install.tar.bz2 /home/xxx/gcc-${GCC_V}-install
# once you've copied this bz2 to the dest os, you can 
# tar jxvf gcc-${GCC_V}-install.tar.bz2
# cd gcc-${GCC_V}-install
# sudo cp -rH usr /      # this will copy the bins and libs to the root dir

cd ..

echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${INSTALL_DIR}/lib64:${INSTALL_DIR}/lib" >> ~/.bash_profile
echo "export LD_LIBRARY_PATH" >> ~/.bash_profile
. ~/.bash_profile

# if you want to install gcc for all users 
# you may add LD_LIBRARY_PATH to /etc/ld.so.conf.d/gcc.conf
# echo "${INSTALL_DIR}/lib64" >> /etc/ld.so.conf.d/gcc.conf
# echo "${INSTALL_DIR}/lib" >> /etc/ld.so.conf.d/gcc.conf

sudo ldconfig

#rm -rf build_gcc${GCC_V} gcc-${GCC_V}


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

zsszss00002014-07-29 13:01:03

您编译的脚本适合于什么样的操作系统