Skip to content

Instantly share code, notes, and snippets.

@doubleotoo
Last active October 13, 2015 02:48
Show Gist options
  • Save doubleotoo/4127700 to your computer and use it in GitHub Desktop.
Save doubleotoo/4127700 to your computer and use it in GitHub Desktop.
Quick and dirty script to automate the installation of GMP
#!/bin/bash -x
#-------------------------------------------------------------------------------
# Set defaults
#-------------------------------------------------------------------------------
: ${GMP_VERSION:=$1}
: ${DESTDIR:=$(pwd)}
: ${PREFIX:=${DESTDIR}/${GMP_VERSION}}
: ${SRCDIR:=}
: ${WORKSPACE:=${PREFIX}/workspace}
: ${BUILDDIR:=${WORKSPACE}/build}
if [ -z "$GMP_VERSION" ]; then
echo "[FATAL] \$GMP_VERSION not set"
echo "[INFO] Usage: GMP_VERSION=<version> $0"
exit 1
fi
#-------------------------------------------------------------------------------
# Use separate workspace
#-------------------------------------------------------------------------------
mkdir -p "${WORKSPACE}" || exit 1
pushd "${WORKSPACE}" || exit 1
#-------------------------------------------------------------------------------
# Download and unpack software
#-------------------------------------------------------------------------------
TARBALL="gmp-${GMP_VERSION}.tar.bz2"
if ! test -e "${TARBALL}"; then
wget "ftp://ftp.gnu.org/gnu/gmp/${TARBALL}" || exit 1
fi
if ! test -e "gmp-${GMP_VERSION}"; then
tar jxvf "${TARBALL}" || exit 1
fi
#-------------------------------------------------------------------------------
# Setup build tree
#-------------------------------------------------------------------------------
pushd "gmp-${GMP_VERSION}" || exit 1
SRCDIR="$(pwd)"
mkdir -p "$BUILDDIR" || exit 1
pushd "$BUILDDIR" || exit 1
#-------------------------------------------------------------------------------
# Install
#-------------------------------------------------------------------------------
"${SRCDIR}/configure" --prefix="${PREFIX}" || exit 1
make install -j || exit 1
#-------------------------------------------------------------------------------
# Create environment-setup file
#-------------------------------------------------------------------------------
cat > "${PREFIX}/setup.sh" <<-EOF
export GMP_HOME="${PREFIX}"
export LD_LIBRARY_PATH="\${GMP_HOME}/lib:\${LD_LIBRARY_PATH}"
EOF
#-------------------------------------------------------------------------------
# Setup permissions
#-------------------------------------------------------------------------------
chmod -R g+r "${PREFIX}" || exit 1
find "${PREFIX}" -type d -exec chmod g+x {} \; || exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment