#!/bin/bash

. /usr/local/tools/dotkit/init.sh
use mvapich2-gnu

set -x

mpifileutils=mpifileutils-0.8

topdir=`pwd`
installdir=$topdir/install

export PATH="${topdir}/autotools/install/bin:$PATH"

./autogen.sh

rm -rf build
mkdir -p build
cd build

export PKG_CONFIG_PATH="${installdir}/lib/pkgconfig"

# TODO: avoid this step
# necessary so configure test of dtcmp links with MPI
export CC=mpicc

# hack to get things to build after common library
export CFLAGS="-I${topdir}/src/common -DDCOPY_USE_XATTRS"
export LDFLAGS="-Wl,-rpath,${topdir}/install/lib -L${topdir}/install/lib -lcircle"

../configure \
  --prefix=/usr/local/mpifileutils \
  --enable-experimental \
  --enable-lustre \
  --with-libdtcmp=$installdir && \
make dist
if [ $? -ne 0 ] ; then
  echo "failed to make dist file utils"
  exit 1
fi
make distcheck
if [ $? -ne 0 ] ; then
  echo "failed to make distcheck file utils"
  exit 1
fi

cp mpifileutils*.tar.gz ../.
exit 0

rm -rf ${mpifileutils}
tar -zxf ${mpifileutils}.tar.gz
cd ${mpifileutils}

mkdir build
cd build

../configure \
  --prefix=$installdir \
  --disable-silent-rules \
  --enable-experimental \
  --with-libdtcmp=$installdir && \
make VERBOSE=1 && \
make VERBOSE=1 install
if [ $? -ne 0 ] ; then
  echo "failed to configure, build, or install file utils"
  exit 1
fi
