Last active
January 15, 2019 12:00
-
-
Save pmalek/5da2e947a51aa773da80 to your computer and use it in GitHub Desktop.
gcc installation script for Centos6.6 (probably can be used for other distributions).
It also installs dependencies like mpc, mpfr and gmp !NOTE:
As of now this only works for installations with PREFIX=/usr/local
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOGFILE=/tmp/gcc_install.log | |
# $1 - package name | |
errorIf(){ | |
if [ $? -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%/} # get rid of '/' at the end of SOURCE_DIR | |
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 and have gmp, mpgr, mpc downloaded (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 && \ | |
make && make check && make install | |
) >$LOGFILE 2>&1 | |
errorIf gmp | |
echo "gmp Installed!:)" | |
#mpfr | |
( | |
cd mpfr && \ | |
./configure --enable-shared --enable-static --prefix=/usr/local --with-gmp=/usr/local && \ | |
make && make check && make install | |
) >$LOGFILE 2>&1 | |
errorIf mpfr | |
echo "mpfr Installed!:)" | |
#mpc | |
( | |
cd mpc && \ | |
./configure --enable-shared --enable-static --prefix=/usr/local --with-gmp=/usr/local --with-mpfr=/usr/local && \ | |
make && make check && make install | |
) >$LOGFILE 2>&1 | |
errorIf mpc | |
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 --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 && \ | |
make && make install && \ | |
find /usr/local/lib64 -iname "*.py" -exec mv {} /usr/share/gdb/auto-load/usr/lib/ \; && \ | |
ldconfig | |
) >$LOGFILE 2>&1 | |
echo "gcc from $SOURCE_DIR_NAME Installed!:)" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# as a parameter to this script please input the build directory (where Makefile resides) | |
TEMP_INSTALL_DIR=/tmp/gccinst | |
LOGFILE=/tmp/gcc_uninstall.log | |
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 build directory as argument (where Makefile resides)" | |
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" | |
[ -d $TEMP_INSTALL_DIR ] && rm -rf $TEMP_INSTALL_DIR && mkdir $TEMP_INSTALL_DIR | |
echo "Installing gcc in temp dir: $TEMP_INSTALL_DIR (to check which files have to be removed from the system)" | |
( | |
cd $SOURCE_DIR && \ | |
make install DESTDIR=$TEMP_INSTALL_DIR && \ | |
find $TEMP_INSTALL_DIR -type f | sed -e s,$TEMP_INSTALL_DIR,, | (while read F; do rm "$F"; done) && \ | |
# the next line will remove dead symlinks in /usr/local/lib64 | |
find /usr/local/lib64 | xargs -I {} bash -c "[ ! -e {} ] && rm -f {}" && \ | |
rm -rf $TEMP_INSTALL_DIR && \ | |
ldconfig | |
) >$LOGFILE 2>&1 | |
echo "Done :)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment