gcc编译(一)download_prerequisites

 根据网络上,一说编译gcc,第一道程序就是./download_prerequisites,然后一大堆安装流程,可是里面的道道,却被有关专家不扯淡,总有种云里雾里的感觉,我还是觉得看看它的代码比较好,打开它的代码,vi ./download_prerequisites

#! /bin/sh

# Download some prerequisites needed by gcc.
# Run this from the top level of the gcc source tree and the gcc
# build will do the right thing.
#
# (C) 2010 Free Software Foundation
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.

# If you want to disable Graphite loop optimizations while building GCC,
# DO NOT set GRAPHITE_LOOP_OPT as yes so that the ISL package will not
# be downloaded.
GRAPHITE_LOOP_OPT=yes

if [ ! -e gcc/BASE-VER ] ; then
	echo "You must run this script in the top level GCC source directory."
	exit 1
fi

# Necessary to build GCC.
MPFR=mpfr-2.4.2
GMP=gmp-4.3.2
MPC=mpc-0.8.1

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPFR.tar.bz2 || exit 1
tar xjf $MPFR.tar.bz2 || exit 1
ln -sf $MPFR mpfr || exit 1

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$GMP.tar.bz2 || exit 1
tar xjf $GMP.tar.bz2  || exit 1
ln -sf $GMP gmp || exit 1

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPC.tar.gz || exit 1
tar xzf $MPC.tar.gz || exit 1
ln -sf $MPC mpc || exit 1

# Necessary to build GCC with the Graphite loop optimizations.
if [ "$GRAPHITE_LOOP_OPT" = "yes" ] ; then
  ISL=isl-0.14

  wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$ISL.tar.bz2 || exit 1
  tar xjf $ISL.tar.bz2  || exit 1
  ln -sf $ISL isl || exit 1
fi

根据代码分析,可以分成以下几个方面

(一)要编译gcc,需要三个库(下面三个库的版本适用于部分gcc版本,比如4.9.3--5.4.0,我目前试过的两个版本)

# Necessary to build GCC.
MPFR=mpfr-2.4.2
GMP=gmp-4.3.2
MPC=mpc-0.8.1

(二)下载库,解压缩,并软链接

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$GMP.tar.bz2 || exit 1
tar xjf $GMP.tar.bz2  || exit 1
ln -sf $GMP gmp || exit 1

如果我已经下载了库怎么办?可以这样处理

#wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$GMP.tar.bz2 || exit 1
tar xjf $GMP.tar.bz2  || exit 1
ln -sf $GMP gmp || exit 1

直接解压缩和软连接就可以,当然,如果直接都已经解压缩好了,当然还是可以按上面的方法处理,只剩下软链接就可以了,当然这是适用于使用./contrib/download_prerequisites用法的

(三)条件判断后,进行需求下载,解压缩,软链接

GRAPHITE_LOOP_OPT=yes
# Necessary to build GCC with the Graphite loop optimizations.
if [ "$GRAPHITE_LOOP_OPT" = "yes" ] ; then
  ISL=isl-0.14

  wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$ISL.tar.bz2 || exit 1
  tar xjf $ISL.tar.bz2  || exit 1
  ln -sf $ISL isl || exit 1
fi

(四)如果连接gnu下载不稳定怎么办,可以想办法在wget 后面的网址设定为国内的镜像站地址,下载稳定快速。

比如:https://mirrors.tuna.tsinghua.edu.cn/gnu/gmp/$GMP.tar.bz2来替代

wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gmp/$GMP.tar.bz2 || exit 1
tar xjf $GMP.tar.bz2  || exit 1
ln -sf $GMP gmp || exit 1

希望我写的东西对读者有所帮助,哪怕有一丝帮助解惑,我还是觉得欣慰的。读代码识真相,掌握代码后改进。

你可能感兴趣的:(GCC)