I have written this script to install gcc (here in version 4.9.2) on Centos6.6. I am only interested in C and C++ support.
Please comment if this is any good and can I make it better before I get the packages for those.
#!/bin/bash
LOGFILE=/tmp/gcc_install.log
# $1 - package name
# $2 - status
errorIf(){
if [ $2 -ne 0 ]; then
echo "Something was wrong with $1"
exit 1
fi
}
################################################################################
################################# SCRIPT START #################################
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# only one param - gcc's source directory absolute location
if [ $# -ne 1 ]; then
echo "Please give the gcc source directory as argument"
exit 1
fi
if [ ! -d "$1" ]; then
echo "gcc's source directory that you have passed doesn't exist!"
exit 1
fi
SOURCE_DIR="$1"
SOURCE_DIR_NAME="${SOURCE_DIR##*/}"
cd "$SOURCE_DIR"/contrib/
################################################################################
################################# gmp, mpgr, mpc ##############################
# this script assumes that you have ran download_prerequisites from gcc's contrib dir
# contrib with downloaded gmp, mpgr, mpc (used download_prerequisites)
if [ ! -d gmp ] || [ ! -d mpfr ] || [ ! -d mpc ]; then
echo "There is no gmp or mpfr or mpc directory in `pwd`. Please run download_prerequisites."
exit 1
fi
echo "Installing gcc and dependencies. You can check the status and results in $LOGFILE"
#gmp
cd gmp && ./configure --enable-shared --enable-static --prefix=/usr/local >$LOGFILE 2>&1 && make >$LOGFILE 2>&1 && make check >$LOGFILE 2>&1 && make install >$LOGFILE 2>&1 && cd ..
ret="$?"
errorIf gmp $ret
echo "gmp Installed!:)"
#mpfr
cd mpfr && ./configure --enable-shared --enable-static --prefix=/usr/local --with-gmp=/usr/local >$LOGFILE 2>&1 && make >$LOGFILE 2>&1 && make check >$LOGFILE 2>&1 && make install >$LOGFILE 2>&1 && cd ..
ret="$?"
errorIf mpfr $ret
echo "mpfr Installed!:)"
#mpc
cd mpc && ./configure --enable-shared --enable-static --prefix=/usr/local --with-gmp=/usr/local --with-mpfr=/usr/local >$LOGFILE 2>&1 && make >$LOGFILE 2>&1 && make check >$LOGFILE 2>&1 && make install >$LOGFILE 2>&1 && cd ..
ret="$?"
errorIf mpc $ret
echo "mpc Installed!:)"
echo /usr/local/lib/ >> /etc/ld.so.conf
echo /usr/local/lib64/ >> /etc/ld.so.conf
ldconfig
cd ../../
ulimit -s 32768 # for gcc tests
mkdir -p /usr/share/gdb/auto-load/usr/lib
mkdir -p gcc-build
cd gcc-build
# find mv .py command is due to this ldconfig error (gcc copies some .py files into /usr/local/lib64/)
# ldconfig: /usr/local/lib/../lib64/libstdc++.so.6.0.20-gdb.py is not an ELF file - it has the wrong magic bytes at the start.
../$SOURCE_DIR_NAME/configure --enable-shared --disable-bootstrap --with-system-zlib --enable-languages=c,c++ --enable-libgomp --enable-threads=posix --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local --with-fpmath=sse --disable-multilib >$LOGFILE 2>&1 && make >$LOGFILE 2>&1 && make install >$LOGFILE 2>&1 && find /usr/local/lib64 -iname "*.py" -exec mv {} /usr/share/gdb/auto-load/usr/lib/ \; >$LOGFILE 2>&1 && ldconfig >$LOGFILE 2>&1
echo "gcc from $SOURCE_DIR_NAME Installed!:)"