-
-
Save bmmalone/b3590b678dab6732cc3347528072239f to your computer and use it in GitHub Desktop.
Build and Install GCC Suite from Scratch
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 | |
GCC_VERSION="10.1.0" | |
WORKDIR="$HOME/gcc/src/" | |
INSTALLDIR="/$HOME/gcc/install/gcc-${GCC_VERSION}" | |
set +h | |
unset LIBRARY_PATH CPATH C_INCLUDE_PATH PKG_CONFIG_PATH CPLUS_INCLUDE_PATH INCLUDE LD_LIBRARY_PATH | |
## NOTE: XCode must be installed (through App Store) and the following run to install command-line tools. | |
## THIS IS IMPORTANT! Among other things, it creates '/usr/include' and installs the system header files. | |
# xcode-select --install | |
# get the source code | |
mkdir -p $WORKDIR | |
cd $WORKDIR | |
wget http://www.netgull.com/gcc/releases/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz | |
tar -xf gcc-${GCC_VERSION}.tar.gz | |
# download the prerequisites | |
cd gcc-${GCC_VERSION} | |
./contrib/download_prerequisites | |
# create the build directory | |
cd .. | |
mkdir gcc-${GCC_VERSION}-build | |
cd gcc-${GCC_VERSION}-build | |
# build | |
../gcc-${GCC_VERSION}/configure \ | |
--prefix=${INSTALLDIR} \ | |
--enable-shared \ | |
--enable-threads=posix \ | |
--enable-__cxa_atexit \ | |
--enable-clocale=gnu \ | |
--enable-languages=all \ | |
--disable-multilib | |
make | |
make install | |
# Notes | |
# | |
# --enable-shared --enable-threads=posix --enable-__cxa_atexit: | |
# These parameters are required to build the C++ libraries to published standards. | |
# | |
# --enable-clocale=gnu: | |
# This parameter is a failsafe for incomplete locale data. | |
# | |
# --disable-multilib: | |
# This parameter ensures that files are created for the specific | |
# architecture of your computer. | |
# This will disable building 32-bit support on 64-bit systems where the | |
# 32 bit version of libc is not installed and you do not want to go | |
# through the trouble of building it. Diagnosis: "Compiler build fails | |
# with fatal error: gnu/stubs-32.h: No such file or directory" | |
# | |
# --with-system-zlib: | |
# Uses the system zlib instead of the bundled one. zlib is used for | |
# compressing and uncompressing GCC's intermediate language in LTO (Link | |
# Time Optimization) object files. | |
# | |
# --enable-languages=all | |
# --enable-languages=c,c++,fortran,go,objc,obj-c++: | |
# This command identifies which languages to build. You may modify this | |
# command to remove undesired language | |
############################################################ | |
# Clean up & set Environment | |
############################################################ | |
set -h | |
cd $INSTALLDIR/bin && ln -s gcc cc | |
echo -e "\n\n# Local build of gcc" >> $HOME/.bashrc | |
echo export PATH="${INSTALLDIR}/bin:\$PATH" >> $HOME/.bashrc | |
echo export CPPFLAGS="-I$INSTALLDIR/include \$CPPFLAGS" >> $HOME/.bashrc | |
echo export LDFLAGS="-L$INSTALLDIR/lib64 -L$INSTALLDIR/lib \$LDFLAGS" >> $HOME/.bashrc | |
echo export LD_LIBRARY_PATH="$INSTALLDIR/lib64:$INSTALLDIR/lib:\$LD_LIBRARY_PATH" >> $HOME/.bashrc | |
echo export LIBRARY_PATH=\$LD_LIBRARY_PATH >> $HOME/.bashrc |
N.B. On some versions of Debian, the lines added to .bashrc at the end of the script are not written exactly correctly and may need manual correction.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This also borrows a little bit of clean up code from "ryans" here: https://community.webfaction.com/questions/20158/installing-gcc-54