public
Last active — forked from mtholder/build_gcc_4.7_on_mac.sh

Script to download and build gcc 4.7 and its dependencies on mac - it took about 40 minutes on my machine (and the "make check" in the gcc build failed for lack of an "autogen" script"), but the compiler seems to work.

  • Download Gist
build_gcc_4.7_on_mac.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
#!/bin/sh
# You might want to modify the first line to specify your own install location.
# In theory the rest should not need tweaking...
export GCC_PREFIX="$HOME/gcc4.7"
 
# Hopefully, you can tweak these as they get out of date, but the download URL's
# may not be stable to text substitution.
GMP_DOWNLOAD_VERSION=gmp-5.0.5
MPFR_DOWNLOAD_VERSION=mpfr-3.1.0
MPC_DOWNLOAD_VERSION=mpc-0.8.2
GCC_DOWNLOAD_VERSION=gcc-4.7.1-RC-20120606
 
# Downloads, builds, then install gmp, mpfr, mpc, and gcc 4.7 to GCC_PREFIX
 
set -x
echo "Thanks to http://solarianprogrammer.com/2012/02/20/living-on-the-edge-building-gcc-4-7-on-mac-osx-lion/ !"
 
 
export PATH="${GCC_PREFIX}/bin:${PATH}"
export LD_LIBRARY_PATH="${GCC_PREFIX}/lib:${LD_LIBRARY_PATH}"
export DYLD_LIBRARY_PATH="${GCC_PREFIX}/lib:${DYLD_LIBRARY_PATH}"
 
 
if ! test -d "${GMP_DOWNLOAD_VERSION}"
then
if ! test -f "${GMP_DOWNLOAD_VERSION}.tar.bz2"
then
wget "ftp://ftp.gmplib.org/pub/$GMP_DOWNLOAD_VERSION/${GMP_DOWNLOAD_VERSION}.tar.bz2" || exit
tar xfjv "${GMP_DOWNLOAD_VERSION}.tar.bz2" || exit
fi
fi
mkdir "${GMP_DOWNLOAD_VERSION}/build"
cd "${GMP_DOWNLOAD_VERSION}/build" || exit
 
../configure --prefix="${GCC_PREFIX}" || exit
make -j4 || exit
make check || exit
make install || exit
cd -
 
if ! test -d "${MPFR_DOWNLOAD_VERSION}"
then
if ! test -f "${MPFR_DOWNLOAD_VERSION}.tar.gz"
then
wget "http://www.mpfr.org/mpfr-current/${MPFR_DOWNLOAD_VERSION}.tar.gz" || exit
tar xfvz "${MPFR_DOWNLOAD_VERSION}.tar.gz" || exit
fi
fi
mkdir "${MPFR_DOWNLOAD_VERSION}/build"
cd "${MPFR_DOWNLOAD_VERSION}/build" || exit
 
../configure --prefix="${GCC_PREFIX}" --with-gmp="${GCC_PREFIX}" || exit
make -j4 || exit
make check || exit
make install || exit
cd -
 
if ! test -d "${MPC_DOWNLOAD_VERSION}"
then
if ! test -f "${MPC_DOWNLOAD_VERSION}.tar.gz"
then
wget "http://www.multiprecision.org/mpc/download/${MPC_DOWNLOAD_VERSION}.tar.gz" || exit
tar xfvz "${MPC_DOWNLOAD_VERSION}.tar.gz" || exit
fi
fi
mkdir "${MPC_DOWNLOAD_VERSION}/build"
cd "${MPC_DOWNLOAD_VERSION}/build" || exit
 
../configure --prefix="${GCC_PREFIX}" --with-gmp="${GCC_PREFIX}" --with-mpfr="${GCC_PREFIX}" || exit
make -j4 || exit
make check || exit
make install || exit
cd -
 
if ! test -d "${GCC_DOWNLOAD_VERSION}"
then
if ! test -f "${GCC_DOWNLOAD_VERSION}.tar.bz2"
then
wget "wget http://gcc.petsads.us/snapshots/4.7.1-RC-20120606/${GCC_DOWNLOAD_VERSION}.tar.bz2" || exit
tar xfvj "${GCC_DOWNLOAD_VERSION}.tar.gz" || exit
fi
fi
mkdir "${GCC_DOWNLOAD_VERSION}/build"
cd "${GCC_DOWNLOAD_VERSION}/build" || exit
 
../configure --prefix="${GCC_PREFIX}" --with-gmp="${GCC_PREFIX}" --with-mpfr="${GCC_PREFIX}" --with-mpc="${GCC_PREFIX}" --enable-checking=release --enable-languages=c,c++,fortran || exit
make -j4 || exit
make check || exit
make install || exit
cd -

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.