#! /bin/sh
#
# Simple script to report information about the MPICH2 installation. This 
# script will likely be replaced with a program closer to 
# that found in MPICH1 once the library contains information on patches 
# applied, etc.
#

print_usage()
{
    echo ""
    echo "usage: mpich2version [-v|--version] [-d|--device] [-c|--configure] [-b|--compilers] [-h|--help]"
    echo ""
    echo "    --version - Show the version number for this installation of MPICH2"
    echo "    --device - Show the device used by this installation"
    echo "    --configure - Show the configure options used to build this installation"
    echo "    --compilers - Show the compilers used to build this installation"
    echo ""
}

if test $# -eq 0 ; then
    include_version=true
    include_device=true
    include_config_opts=true
    include_compilers=true
elif test $# -eq 1 ; then
    arg=$1
    case $arg in
	-v|--version)
	echo "mvapich2-1.0"
	;;

	-d|--device)
	echo "osu_ch3:mrail"
	;;

	-c|--configure)
	echo "'--prefix=/usr/lib/mpi/gcc/mvapich2' '--libdir=/usr/lib/mpi/gcc/mvapich2/lib' '--mandir=/usr/lib/mpi/gcc/mvapich2/share/man' '--sysconfdir=/etc' '--with-device=osu_ch3:mrail' '--with-rdma=gen2' '--with-pm=mpd' '--enable-sharedlibs=gcc' '--without-mpe' 'CFLAGS=-O2 -march=i586 -mtune=i686 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -DUSE_HEADER_CACHING -DONE_SIDED -DMPID_USE_SEQUENCE_NUMBERS -D_SHMEM_COLL_ -DRDMA_CM -DDISABLE_PTMALLOC -DMPIDI_CH3_CHANNEL_RNDV'"
	;;

	-b|--compiler)
	echo "gcc -O2 -march=i586 -mtune=i686 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -DUSE_HEADER_CACHING -DONE_SIDED -DMPID_USE_SEQUENCE_NUMBERS -D_SHMEM_COLL_ -DRDMA_CM -DDISABLE_PTMALLOC -DMPIDI_CH3_CHANNEL_RNDV"
	echo "c++ "
	echo "gfortran "
	echo "gfortran "
	;;

	-h|--help)
	print_usage
	exit 0
	;;

	*)
	echo ""
	echo "Invalid option: $arg"
	print usage
	exit 1
	;;
    esac
else
    include_version=false
    include_device=false
    include_config_opts=false

    for arg ; do
	case $arg in
	    -v|--version)
	    include_version=true
	    ;;

	    -d|--device)
	    include_device=true
	    ;;

	    -c|--configure)
	    include_config_opts=true
	    ;;

	    -b|--compiler)
	    include_compilers=true
	    ;;

	    -h|--help)
	    print_usage
	    exit 0
	    ;;

	    *)
	    echo ""
	    echo "Invalid option: $arg"
	    print usage
	    exit 1
	    ;;
	esac
    done
fi

if test "$include_version" = "true" ; then
    echo "Version:           mvapich2-1.0"
fi
if test "$include_device" = "true" ; then
    echo "Device:            osu_ch3:mrail"
fi
if test "$include_config_opts" = "true" ; then
    echo "Configure Options: '--prefix=/usr/lib/mpi/gcc/mvapich2' '--libdir=/usr/lib/mpi/gcc/mvapich2/lib' '--mandir=/usr/lib/mpi/gcc/mvapich2/share/man' '--sysconfdir=/etc' '--with-device=osu_ch3:mrail' '--with-rdma=gen2' '--with-pm=mpd' '--enable-sharedlibs=gcc' '--without-mpe' 'CFLAGS=-O2 -march=i586 -mtune=i686 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -DUSE_HEADER_CACHING -DONE_SIDED -DMPID_USE_SEQUENCE_NUMBERS -D_SHMEM_COLL_ -DRDMA_CM -DDISABLE_PTMALLOC -DMPIDI_CH3_CHANNEL_RNDV'"
fi
if test "$include_compilers" = true ; then
    echo "CC:  gcc -O2 -march=i586 -mtune=i686 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -DUSE_HEADER_CACHING -DONE_SIDED -DMPID_USE_SEQUENCE_NUMBERS -D_SHMEM_COLL_ -DRDMA_CM -DDISABLE_PTMALLOC -DMPIDI_CH3_CHANNEL_RNDV"
    echo "CXX: c++ "
    echo "F77: gfortran "
    echo "F90: gfortran "
fi


exit 0
