Last active
October 12, 2015 02:08
-
-
Save doubleotoo/3955176 to your computer and use it in GitHub Desktop.
GCC installation script (with pre-installed prerequisites)
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 -e | |
#------------------------------------------------------------------------------- | |
# Default values | |
#------------------------------------------------------------------------------- | |
: ${GCC_VERSION:=$1} | |
: ${LANGUAGES:=c,c++,fortran} | |
: ${MPFR_HOME:=} | |
: ${GMP_HOME:=} | |
: ${MPC_HOME:=} | |
: ${DESTDIR:=$(pwd)} | |
: ${PREFIX:=${DESTDIR}/${GCC_VERSION}} | |
: ${WORKSPACE:=${PREFIX}/workspace} | |
: ${BUILDDIR:=${WORKSPACE}/build} | |
#------------------------------------------------------------------------------- | |
# Sanity Checks | |
#------------------------------------------------------------------------------- | |
if [ -z "${GCC_VERSION}" ]; then | |
echo "Usage: $0 <version: 4.7.2>" | |
exit 1 | |
fi | |
if [ -z "${MPFR_HOME}" -o ! -d "${MPFR_HOME}" ]; then | |
echo "[FATAL] \$MPFR_HOME is not set or does not exist" | |
exit 1 | |
fi | |
if [ -z "${GMP_HOME}" -o ! -d "${GMP_HOME}" ]; then | |
echo "[FATAL] \$GMP_HOME is not set or does not exist" | |
exit 1 | |
fi | |
if [ -z "${MPC_HOME}" -o ! -d "${MPC_HOME}" ]; then | |
echo "[FATAL] \$MPC_HOME is not set or does not exist" | |
exit 1 | |
fi | |
#------------------------------------------------------------------------------- | |
# Meta Information | |
#------------------------------------------------------------------------------- | |
TARBALL="gcc-${GCC_VERSION}.tar.gz" | |
DOWNLOAD_URL="http://www.netgull.com/gcc/releases/gcc-${GCC_VERSION}/${TARBALL}" | |
# Alternate mirror in St. Louis: "http://gcc.petsads.us/releases/gcc-${GCC_VERSION}/${TARBALL}" | |
echo "[INFO] GCC '$GCC_VERSION'" | |
#------------------------------------------------------------------------------- | |
# Workspace | |
#------------------------------------------------------------------------------- | |
mkdir -p "${WORKSPACE}" || exit 1 | |
pushd "${WORKSPACE}" || exit 1 | |
SRCDIR="${WORKSPACE}/gcc-$VERSION" | |
#------------------------------------------------------------------------------- | |
# Download and unpack | |
#------------------------------------------------------------------------------- | |
if [ ! -f "$TARBALL" ]; then | |
echo "[INFO] Downloading '$DOWNLOAD_URL'" | |
wget --no-check-certificate "$DOWNLOAD_URL" || exit 1 | |
else | |
echo "[INFO] '$TARBALL' already exists. Skipping..." | |
fi | |
if [ ! -d "$SRCDIR" ]; then | |
echo "[INFO] Unpacking '$TARBALL'" | |
tar xzf "$TARBALL" || exit 1 | |
else | |
echo "[INFO] '$SRCDIR' already exists. Skipping..." | |
fi | |
#------------------------------------------------------------------------------- | |
# Build and install | |
#------------------------------------------------------------------------------- | |
mkdir -p "${BUILDDIR}" || exit 1 | |
pushd "${BUILDDIR}" || exit 1 | |
if [ ! -e "${PREFIX}/bin" ]; then | |
echo "[INFO] Configuring GCC" | |
echo "[INFO] Installing to '$PREFIX'" | |
echo "[INFO] Building GCC with support for '${LANGUAGES}'" | |
echo "[INFO] \$GMP_HOME='${GMP_HOME}'" | |
echo "[INFO] \$MPFR_HOME='${MPFR_HOME}'" | |
echo "[INFO] \$MPC_HOME='${MPC_HOME}'" | |
"${SOURCE}/configure" \ | |
--prefix="$PREFIX" \ | |
--enable-languages="${LANGUAGES}" \ | |
--with-gmp="${GMP_HOME}" \ | |
--with-mpfr="${MPFR_HOME}" \ | |
--with-mpc="${MPC_HOME}" || exit 1 | |
make -j || exit 1 | |
make -j install || exit 1 | |
if [ "$(uname --machine)" = "x86_64" ]; then | |
export LIBDIR="lib64" | |
else | |
export LIBDIR="lib" | |
fi | |
echo "[INFO] Creating GCC environment setup file" | |
cat > "${PREFIX}/setup.sh" <<-EOF | |
#!/bin/bash | |
# | |
# Automatically generated by $0 on $(date) | |
export GCC_HOME="${PREFIX}" | |
export PATH="\${GCC_HOME}/bin:\${PATH}" | |
export LD_LIBRARY_PATH="\${GCC_HOME}/${LIBDIR}:\${LD_LIBRARY_PATH}" | |
export GMP_HOME="${GMP_HOME}" | |
export LD_LIBRARY_PATH="\${GMP_HOME}/lib:\${LD_LIBRARY_PATH}" | |
export MPC_HOME="${MPC_HOME}" | |
export LD_LIBRARY_PATH="\${MPC_HOME}/lib:\${LD_LIBRARY_PATH}" | |
export MPFR_HOME="${MPFR_HOME}" | |
export LD_LIBRARY_PATH="\${MPFR_HOME}/lib:\${LD_LIBRARY_PATH}" | |
EOF | |
#----------------------------------------------- | |
# Set Permissions | |
#----------------------------------------------- | |
chmod -R g+r "${PREFIX}" | |
chmod -R g+x "${PREFIX}/bin" | |
find "${PREFIX}" -type d -exec chmod g+x {} \; | |
echo "[INFO] Successfully installed GCC version '${GCC_VERSION}' with support for '${LANGUAGES}'" | |
echo "[INFO] \$GMP_HOME='${GMP_HOME}'" | |
echo "[INFO] \$MPFR_HOME='${MPFR_HOME}'" | |
echo "[INFO] \$MPC_HOME='${MPC_HOME}'" | |
echo "[INFO] \$PREFIX='${PREFIX}'" | |
echo "[INFO] | |
else | |
echo "[INFO] Installation already exists in '$PREFIX'. Skipping..." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment