Skip to content

Instantly share code, notes, and snippets.

@cwsmith
Last active October 12, 2015 06:07
Show Gist options
  • Save cwsmith/3982059 to your computer and use it in GitHub Desktop.
Save cwsmith/3982059 to your computer and use it in GitHub Desktop.
Bash functions for installing SCOREC software
#!/bin/bash
#This is a build script for the SCOREC software stack.
#users should first modify the CC, CXX, and FC variables below:
#set the C and C++ compilers to point at MPI compiler wrappers
export CC="not set"
export CXX="not set"
export FC="not set"
PREFIX="not set"
DEBUG='-g '
BUILD_DIR="not set"
#SCOREC's redmine server URL
#the prefix for all svn checkout commands
#change this if you want to use anonsv
REDMINE=http://redmine.scorec.rpi.edu/svn
SVN_USER=" "
#DROOT becomes the root directory of the downloaded components
DROOT=$PWD
#common setup required after checkout
#make an m4 directory, autoreconf
setupf()
{
#make a symbolic link to the external m4 directory
#this is a SCOREC quirk that could be (and has been in some cases)
#fixed by using SVN externals
if [ ! -e m4 ]; then
ln -s ../m4 m4
fi
#our SVN repositories do not store generated configure scripts,
#so autoreconf must be run first
autoreconf -i
if [ ! -d $BUILD_DIR ]; then
mkdir $BUILD_DIR
fi
}
#wraps around the common compile command
installf()
{
#some packages (FMDB) are worth building in parallel
#4 cores is a decent estimate, this can be changed
make install -j 4
}
uninstallf()
{
make clean
make uninstall
}
print_usage()
{
echo "Usage: $0 <function>"
echo "available functions:"
echo "checkout_all - checkout from svn"
echo "setup_all - setup before build"
echo "install_all - build and install"
echo "uninstall_all - uninstall"
echo "download_and_build_zoltan - download, build, and install zoltan"
}
#the active code begins now, we use `set -e` to stop
#at the first error since many of these functions
#take a long time
set -e
#check for the common mistake of not setting compilers or install target
if [ "$CC" = "not set" ]; then
echo 'please edit this script to provide CC'
exit 1
fi
if [ "$CXX" = "not set" ]; then
echo 'please edit this script to provide CXX'
exit 1
fi
if [ "$FC" = "not set" ]; then
echo 'please edit this script to provide FC'
exit 1
fi
if [ "$PREFIX" = "not set" ]; then
echo 'please edit this script to provide PREFIX'
exit 1
fi
if [ "$BUILD_DIR" = "not set" ]; then
echo 'please edit this script to provide BUILD_DIR'
exit 1
fi
#this is the main case statement. it delegates
#to each function based on the first argument
case "$1" in
#uses SVN to checkout all SCOREC software up to FMDB
checkout_all)
svn co $SVN_USER $REDMINE/ipcomman/trunk ipcomman
svn co $SVN_USER $REDMINE/gmi/trunk gmi
svn co $SVN_USER $REDMINE/fmdb/software/trunk/SCORECUtil/SCORECUtil scorecutil
svn co $SVN_USER $REDMINE/fmdb/software/trunk/FMDB/FMDB fmdb
svn co $SVN_USER $REDMINE/parutil/software/trunk pcu
svn co $SVN_USER $REDMINE/buildutil/trunk/GNUautoTools/m4Macros m4
;;
#uses the setupf above on all SCOREC software
setup_all)
cd ipcomman
setupf
cd ../pcu
setupf
cd ../gmi
setupf
cd ../scorecutil
setupf
cd ../fmdb
setupf
cd ..
;;
#configures, compiles, and installs all the SCOREC software
install_all)
set -ex
SHARED='--disable-shared'
if [ "x$2" = "x1" ]; then
echo "enabling shared libraries"
SHARED='--enable-shared'
fi
cd ipcomman/$BUILD_DIR
../configure --prefix=$PREFIX --with-mpi=yes $SHARED CXXFLAGS="$DEBUG" CFLAGS="$DEBUG"
installf
cd ../../pcu/$BUILD_DIR
../configure --prefix=$PREFIX MPI_INSTALL=yes $SHARED CXXFLAGS="$DEBUG" CFLAGS="$DEBUG"
installf
cd ../../gmi/$BUILD_DIR
../configure --prefix=$PREFIX --with-scorecutil=$DROOT/scorecutil --enable-meshmodel --with-fmdb=$DROOT/fmdb $SHARED CXXFLAGS="$DEBUG" CFLAGS="$DEBUG"
installf
cd ../../scorecutil/$BUILD_DIR
../configure --prefix=$PREFIX CXXFLAGS='-DFMDB_PARALLEL ' --with-fmdb=$DROOT/fmdb --with-gmi=$PREFIX $SHARED CXXFLAGS="$DEBUG" CFLAGS="$DEBUG"
installf
cd ../../fmdb/$BUILD_DIR
../configure --prefix=$PREFIX --enable-parallel MPI_INSTALL=yes PARMETIS_DIR=$PREFIX ZOLTAN_DIR=$PREFIX PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig $SHARED CXXFLAGS="$DEBUG" CFLAGS="$DEBUG"
installf
cd ../..
set +ex
;;
uninstall_all)
cd ipcomman/$BUILD_DIR
uninstallf
cd ../../pcu/$BUILD_DIR
uninstallf
cd ../../gmi/$BUILD_DIR
uninstallf
cd ../../scorecutil/$BUILD_DIR
uninstallf
cd ../../fmdb/$BUILD_DIR
uninstallf
cd ../..
;;
download_and_build_zoltan)
SCRIPT_HOME=$PWD
PARMETIS_HOME=$PREFIX
echo "Creating a directory for Zoltan"
#preemptively making some directories
if [ ! -d $PREFIX ]; then
mkdir -p $PREFIX
fi
cd $PREFIX
mkdir -p lib
mkdir -p include
cd -
tarball=""
if [ $2 ] && [ -f $2 ]; then
tarball=$2
else
if [ ! -e zoltan ]; then
mkdir zoltan
cd zoltan
set +e
echo "Downloading Zoltan"
wget -T 20 http://www.cs.sandia.gov/~kddevin/Zoltan_Distributions/zoltan_distrib_v3.1.tar.gz
if [ ! -f zoltan_distrib_v3.1.tar.gz ]; then
wget http://www.scorec.rpi.edu/~cwsmith/zoltan/zoltan_distrib_v3.1.tar.gz
if [ ! -f zoltan_distrib_v3.1.tar.gz ]; then
echo 'failed to download zoltan'
return 1
fi
fi
else
cd zoltan
fi
tarball="zoltan_distrib_v3.1.tar.gz"
set -e
fi
tar -xzf $tarball
echo "Building ParMETIS"
cd ParMETIS3_1/METISLib
make -j4 CC=$CC LD=$CC
cd ../ParMETISLib
make -j4 CC=$CC LD=$CC
cd ..
cp libparmetis.a $PREFIX/lib/
cp libmetis.a $PREFIX/lib/
cp parmetis.h $PREFIX/include/
cp METISLib/metis.h $PREFIX/include/
if [ ! -e $BUILD_DIR ]; then
mkdir $BUILD_DIR
fi
cp libparmetis.a libmetis.a $BUILD_DIR/.
echo "Building Zoltan"
cd ../Zoltan_v3.1
if [ ! -e $BUILD_DIR ]; then
mkdir $BUILD_DIR
fi
cd $BUILD_DIR
../configure $SHARED_LIBS --enable-mpi --disable-examples --with-gnumake --with-parmetis --with-parmetis-libdir=$PARMETIS_HOME/lib --with-parmetis-incdir=$PARMETIS_HOME/include --prefix=$PREFIX
make everything
make install
;;
*)
echo "$1 not supported"
print_usage
;;
esac
#undoes the set -e a the start of this block
set +e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment