Created
August 25, 2015 22:29
-
-
Save rosecompiler/117e626a80d4865aaafb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 -x | |
#------------------------------------------------------------------------------- | |
# Set defaults | |
#------------------------------------------------------------------------------- | |
: ${MPC_VERSION:=$1} | |
: ${MPFR_HOME:=} | |
: ${MPFR_VERSION:=} | |
: ${GMP_HOME:=} | |
: ${GMP_VERSION:=} | |
: ${DESTDIR:=$(pwd)} | |
: ${PREFIX:=${DESTDIR}/${MPC_VERSION}/mpfr/${MPFR_VERSION}/gmp/${GMP_VERSION}} | |
: ${WORKSPACE:=${PREFIX}/workspace} | |
#------------------------------------------------------------------------------- | |
# Sanity Checks | |
#------------------------------------------------------------------------------- | |
if [ -z "${MPC_VERSION}" ]; then | |
echo "[FATAL] Please specify the \$MPC_VERSION to install" | |
echo "[INFO] Usage: MPC_VERSION=<version> $0" | |
exit 1 | |
fi | |
REQUIRED_TOOL="GMP MPFR" | |
for tool in $REQUIRED_TOOL; do | |
TOOL_HOME="$(eval "echo \${$(echo ${tool}_HOME)}")" | |
if [ -z "$TOOL_HOME" -o ! -d "${TOOL_HOME}" ]; then | |
echo "[FATAL] \$${tool}_HOME not set or does not exist" | |
echo "[INFO] Usage: \$$tool=</path/to/${tool}/installation> $0" | |
exit 1 | |
fi | |
if [ ! -f "${TOOL_HOME}/setup.sh" ]; then | |
echo "[FATAL] '${TOOL_HOME}/setup.sh' does not exist" | |
exit 1 | |
else | |
source "${TOOL_HOME}/setup.sh" || exit 1 | |
fi | |
TOOL_VERSION="$(eval "echo \${$(echo ${tool}_VERSION)}")" | |
if test -z "${TOOL_VERSION}"; then | |
echo "[FATAL] \$${tool}_VERSION required variable is undefined" | |
exit 1 | |
fi | |
done | |
#------------------------------------------------------------------------------- | |
# Meta Information | |
#------------------------------------------------------------------------------- | |
MPC_SRCDIR="${WORKSPACE}/mpc-${MPC_VERSION}" | |
MPC_TARBALL="mpc-${MPC_VERSION}.tar.gz" | |
MPC_DOWNLOAD_URL="http://www.multiprecision.org/mpc/download/${MPC_TARBALL}" | |
#------------------------------------------------------------------------------- | |
# Use separate workspace | |
#------------------------------------------------------------------------------- | |
mkdir -p "${WORKSPACE}" || exit 1 | |
pushd "${WORKSPACE}" || exit 1 | |
#------------------------------------------------------------------------------- | |
# Download and unpack | |
#------------------------------------------------------------------------------- | |
if [ ! -f "$MPC_TARBALL" ]; then | |
echo "[INFO] Downloading MPFR '$MPC_DOWNLOAD_URL'" | |
wget --no-check-certificate "$MPC_DOWNLOAD_URL" || exit 1 | |
else | |
echo "[INFO] [SKIP] MPFR tarball already exists: '$MPC_TARBALL'" | |
fi | |
if [ ! -d "$MPC_SRCDIR" ]; then | |
echo "[INFO] Unpacking MPFR tarball: '$MPC_TARBALL'" | |
tar xzvf "${MPC_TARBALL}" | |
else | |
echo "[INFO] [SKIP] MPFR source code already exists: '$MPC_SRCDIR'" | |
fi | |
#------------------------------------------------------------------------------- | |
# Setup build tree | |
#------------------------------------------------------------------------------- | |
cd "${MPC_SRCDIR}" || exit 1 | |
SRCDIR="$(pwd)" | |
#------------------------------------------------------------------------------- | |
# Install | |
#------------------------------------------------------------------------------- | |
if [ ! -e "${PREFIX}/lib" ]; then | |
echo "[INFO] Configuring MPFR" | |
echo "[INFO] Installing to '$PREFIX'" | |
"${MPC_SRCDIR}/configure" \ | |
--prefix="${PREFIX}" \ | |
--with-gmp="${GMP_HOME}" \ | |
--with-mpfr="${MPFR_HOME}" || exit 1 | |
make -j || exit 1 | |
make install -j || exit 1 | |
fi | |
#------------------------------------------------------------------------------- | |
# Create environment-setup file | |
#------------------------------------------------------------------------------- | |
cat > "${PREFIX}/setup.sh" <<-EOF | |
# Automatically generated by '$USER'@'$(hostname)' on '$(date)' | |
source "${GMP_HOME}/setup.sh" | |
source "${MPFR_HOME}/setup.sh" | |
export MPC_VERSION="${MPC_VERSION}" | |
export MPC_HOME="${PREFIX}" | |
export LD_LIBRARY_PATH="\${MPC_HOME}/lib:\${LD_LIBRARY_PATH}" | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment