Skip to content

Instantly share code, notes, and snippets.

@edwardstock
Last active March 1, 2019 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardstock/38672a09a947e9d9a4bfe1f208376eb6 to your computer and use it in GitHub Desktop.
Save edwardstock/38672a09a947e9d9a4bfe1f208376eb6 to your computer and use it in GitHub Desktop.
GNU GCC 8.1 automated build script
#!/usr/bin/env bash
### Download this things:
## 1. MPC http://www.multiprecision.org/mpc/download.html
## 2. MPFR http://www.mpfr.org/mpfr-current/#download
## 3. GMP https://gmplib.org/download/gmp/gmp-6.1.2.tar.lz ATTENTION!! extract first this archive via lzip and make just *.tar acrchive
## 4. ISL ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
SYSROOT_PREFIX=/opt/gcc81
BIN_SUFFIX=""
LANGS="c,c++"
GCC_VERS="8.1.0"
CONFIGURE_EXTRA_FLAGS=""
function usage()
{
echo "GNU GCC Compile script"
echo ""
echo "./build_gcc.sh"
echo -e " -h --help | This help"
echo -e " --gcc-version=${GCC_VERS} | Which GCC version compile"
echo -e " --prefix=${SYSROOT_PREFIX} | Build and install prefix (sysroot)"
echo -e " --program-suffix= | Target binary suffix (/opt/gcc81/bin/g++-8.1 : \"-8.1\" is a suffix"
echo -e " --languages=${LANGS} | Compiled languages (see configure manual https://gcc.gnu.org/install/configure.html)"
echo -e " --extra-flags | Extra gcc configure flags (don't forget to wrap flags in quotes \" ! )"
echo ""
}
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case ${PARAM} in
-h | --help)
usage
exit
;;
--gcc-version)
GCC_VERS=${VALUE}
;;
--prefix)
SYSROOT_PREFIX=${VALUE}
;;
--program-suffix)
BIN_SUFFIX=${VALUE}
;;
--languages)
LANGS=${VALUE}
;;
--extra-flags)
CONFIGURE_EXTRA_FLAGS=${VALUE}
;;
*)
echo "ERROR: unknown parameter \"$PARAM\""
usage
exit 1
;;
esac
shift
done
rm -rf
mkdir -p ${SYSROOT_PREFIX}
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${SYSROOT_PREFIX}/lib:${SYSROOT_PREFIX}/lib32:${SYSROOT_PREFIX}/lib64
if [ ! -d "build_gmp" ]
then
echo "Unpacking GMP"
mkdir -p build_gmp && tar -C build_gmp -xvf gmp-*.tar*
fi
if [ ! -d "build_isl" ]
then
echo "Unpacking ISL"
mkdir -p build_isl && tar -C build_isl -xvf isl-*.tar*
fi
if [ ! -d "build_mpc" ]
then
echo "Unpacking MPC"
mkdir -p build_mpc && tar -C build_mpc -xvf mpc-*.tar*
fi
if [ ! -d "build_mpfr" ]
then
echo "Unpacking MPFR"
mkdir -p build_mpfr && tar -C build_mpfr -xvf mpfr-*.tar*
fi
if [ ! -d "build_gcc" ]
then
if [ ! -f "gcc-${GCC_VERS}.tar.gz" ]
then
wget ftp://ftp.gwdg.de/pub/misc/gcc/releases/gcc-${GCC_VERS}/gcc-${GCC_VERS}.tar.gz
fi
mkdir -p build_gcc && tar -C build_gcc -xvf gcc-*.tar*
fi
rootDir=`pwd`
if [ `uname` == "Darwin" ]
then
threadCount=`sysctl -a machdep.cpu | grep thread_count | awk '{print $2}'`
else
cpusCnt=`lscpu | grep -E '^CPU\(' | awk '{print $2}'` # cpus count
tpcpu=`lscpu | grep -E '^Thread' | awk '{print $4}'` # threads per core
threadCount=$((cpusCnt * tpcpu))
fi
## GMP
BUILT_GMP_LIB=`ls ${SYSROOT_PREFIX}/lib/libgmp* >/dev/null 2>&1 && echo "1" || echo "0"`
if [ "${BUILT_GMP_LIB}" == "0" ]
then
echo "\n > Make GMP"
cd ${rootDir}/build_gmp/*/ && mkdir -p build && cd build
../configure --prefix=${SYSROOT_PREFIX} --enable-cxx
make -j ${threadCount}
make install
fi
## MPFR
BUILT_MPFR_LIB=`ls ${SYSROOT_PREFIX}/lib/libmpfr* >/dev/null 2>&1 && echo "1" || echo "0"`
if [ "${BUILT_MPFR_LIB}" == "0" ]
then
echo "\n > Make MPFR"
cd ${rootDir}/build_mpfr/*/ && mkdir -p build && cd build
../configure --prefix=${SYSROOT_PREFIX} --with-gmp=${SYSROOT_PREFIX}
make -j ${threadCount}
make install
fi
## MPC
BUILT_MPC_LIB=`ls ${SYSROOT_PREFIX}/lib/libmpc* >/dev/null 2>&1 && echo "1" || echo "0"`
if [ "${BUILT_MPC_LIB}" == "0" ]
then
echo "\n > Make MPC"
cd ${rootDir}/build_mpc/*/ && mkdir -p build && cd build
../configure --prefix=${SYSROOT_PREFIX} --with-gmp=${SYSROOT_PREFIX} --with-mpfr=${SYSROOT_PREFIX}
make -j ${threadCount}
make install
fi
## ISL graphite loop optimizations
BUILT_ISL_LIB=`ls ${SYSROOT_PREFIX}/lib/libisl* >/dev/null 2>&1 && echo "1" || echo "0"`
if [ "${BUILT_ISL_LIB}" == "0" ]
then
echo "\n > Make ISL"
cd ${rootDir}/build_isl/*/ && mkdir -p build && cd build
../configure --prefix=${SYSROOT_PREFIX} --with-gmp-prefix=${SYSROOT_PREFIX}
make -j ${threadCount}
make install
fi
HAVE_GCC_BUILD_DIR=`ls ${rootDir}/build_gcc/*/build >/dev/null 2>&1 && echo "1" || echo "0"`
if [ "${HAVE_GCC_BUILD_DIR}" == "1" ]
then
rm -rf "${rootDir}/build_gcc/*/build"
fi
cd ${rootDir}/build_gcc/*/ && mkdir -p build && cd build
echo "\n > Configure GCC"
../configure --prefix=${SYSROOT_PREFIX} \
--enable-threads=posix \
--enable-checking=release \
--enable-languages=c,c++ \
--program-suffix=${BIN_SUFFIX} \
--with-gmp=${SYSROOT_PREFIX} \
--with-mpc=${SYSROOT_PREFIX} \
--with-mpfr=${SYSROOT_PREFIX} \
--with-isl=${SYSROOT_PREFIX} \
${CONFIGURE_EXTRA_FLAGS}
if (("$?" > 0))
then
echo "Can't configure"
exit 1
fi
echo "\n > Make GCC"
make -j ${threadCount}
if (("$?" > 0))
then
echo "Can't build"
exit 1
fi
echo "\n > Install GCC"
make install
rm -rf ${rootDir}/build_gcc
rm -rf ${rootDir}/build_mpc
rm -rf ${rootDir}/build_mpfr
rm -rf ${rootDir}/build_isl
echo ""
echo ""
echo "Build complete! See result in ${SYSROOT_PREFIX}"
echo "Also you can add PATH for this binaries: PATH=\$PATH:${SYSROOT_PREFIX}/bin"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment