Skip to content

Instantly share code, notes, and snippets.

@doubleotoo
Created September 25, 2013 19:11
Show Gist options
  • Save doubleotoo/6704513 to your computer and use it in GitHub Desktop.
Save doubleotoo/6704513 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
#-------------------------------------------------------------------------------
# Default values
#-------------------------------------------------------------------------------
: ${HDF5_VERSION:=$1}
echo "[INFO] hdf5 '$HDF5_VERSION'"
: ${GCC_HOME:=}
if [ -z "${GCC_HOME}" ]; then
echo "[FATAL] \$GCC_HOME is not set"
exit 1
fi
GCC_VERSION="$(gcc -dumpversion)"
: ${DESTDIR:=$(pwd)}
: ${PREFIX:=${DESTDIR}/${HDF5_VERSION}/gcc/${GCC_VERSION}}
: ${WORKSPACE:=${PREFIX}/workspace}
#-------------------------------------------------------------------------------
# Sanity Checks
#-------------------------------------------------------------------------------
if [ -z "${HDF5_VERSION}" ]; then
echo "Usage: $0 <version: x.x.x.x>"
exit 1
fi
#-------------------------------------------------------------------------------
# Meta Information
#-------------------------------------------------------------------------------
HDF5_SRCDIR="${WORKSPACE}/hdf5-${HDF5_VERSION}"
HDF5_TARBALL="hdf5-${HDF5_VERSION}.tar.gz"
HDF5_DOWNLOAD_URL="http://www.hdfgroup.org/ftp/HDF5/current/src/${HDF5_TARBALL}"
#-------------------------------------------------------------------------------
# Workspace
#-------------------------------------------------------------------------------
mkdir -p "${WORKSPACE}" || exit 1
pushd "${WORKSPACE}" || exit 1
#-------------------------------------------------------------------------------
# [LLVM] Download and unpack
#-------------------------------------------------------------------------------
if [ ! -f "$HDF5_TARBALL" ]; then
echo "[INFO] Downloading HDF5 '$HDF5_DOWNLOAD_URL'"
wget --no-check-certificate "$HDF5_DOWNLOAD_URL" || exit 1
else
echo "[INFO] [SKIP] hdf5 tarball already exists: '$HDF5_TARBALL'"
fi
if [ ! -d "$HDF5_SRCDIR" ]; then
echo "[INFO] Unpacking hdf5 tarball: '$HDF5_TARBALL'"
tar xvzf "$HDF5_TARBALL" || exit 1
else
echo "[INFO] [SKIP] hdf5 source code already exists: '$HDF5_SRCDIR'"
fi
#-------------------------------------------------------------------------------
# Build and install
#-------------------------------------------------------------------------------
cd "${HDF5_SRCDIR}"
if [ ! -e "${PREFIX}/bin" ]; then
echo "[INFO] Configuring hdf5"
echo "[INFO] Installing to '$PREFIX'"
echo "[INFO] \$GCC_HOME='${GCC_HOME}'"
"${HDF5_SRCDIR}/configure" --prefix="$PREFIX" || exit 1
make -j all || exit 1
make -j install || exit 1
# TODO: Make generic (in fact, extract into separate install script)
# Install SZIP
pushd "${WORKSPACE}"
wget "http://www.hdfgroup.org/ftp/lib-external/szip/2.1/src/szip-2.1.tar.gz" || exit 1
tar xzvf szip-2.1.tar.gz || exit 1
cd szip-2.1 || exit 1
./configure --prefix="${PREFIX}" || exit 1
make -j
make -j install
popd
# Install lapack
pushd "${WORKSPACE}"
wget "http://www.netlib.org/lapack/lapack-3.4.2.tgz" || exit 1
tar xzvf lapack-3.4.2.tgz || exit 1
cd lapack-3.4.2 || exit 1
mkdir build || exit 1
cd build || exit 1
cmake ../ -DCMAKE_INSTALL_PREFIX:PATH="${PREFIX}" || exit 1
make -j || exit 1
make -j install || exit 1
popd
echo "[INFO] Creating hdf5 environment setup file"
cat > "${PREFIX}/setup.sh" <<-EOF
#!/bin/bash
#
# Automatically generated by $0 on $(date)
export HDF5_HOME="${PREFIX}"
export PATH="\${HDF5_HOME}/bin:\${PATH}"
export HDF5_GCC_HOME="${GCC_HOME}"
EOF
#-----------------------------------------------
# Set Permissions
#-----------------------------------------------
echo "[INFO] Setting group permissions of '${PREFIX}'"
chmod -R g+r "${PREFIX}"
find "${PREFIX}" -type d -exec chmod g+x {} \;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment