#! /bin/sh
#set -x
#
# This script is invoked from the topdir (not top_srcdir in a VPATH build)
# by mpich/Makefile to create the mpirun program.  The install script
# specific to the device must know how to install the resulting mpirun.
#
if [ -z "${binbuild_dir}" ] ; then
    echo "The variable binbuild_dir must contain the directory "
    echo "in which to install the mpirun programs for ch_gm."
    exit 1
fi

cp util/tstmachines ${binbuild_dir}/tstmachines
/bin/rm -f ${binbuild_dir}/mpirun

MPIRUNLIST=${srcdir}/mpid/ch_gm/mpirun.ch_gm
MPIRUNLIST="$MPIRUNLIST ${srcdir}/mpid/ch_gm/mpirun.ch_gm.pl"
for file in util/mpirun.args.in $MPIRUNLIST ; do 
    bfile=`basename $file .in` 
    /bin/rm -f ${binbuild_dir}/$bfile
    if test -f $file ; then 
      cp $file ${binbuild_dir}/$bfile
    else 
      cp ${srcdir}/$file ${binbuild_dir}/$bfile
    fi
    chmod 775 ${binbuild_dir}/$bfile
done
#for file in ${srcdir}/util/mpirun_dbg.* ; do 
#    bfile=`basename $file .in` 
#    /bin/rm -f ${binbuild_dir}/$bfile
#    cp $file  ${binbuild_dir}/$bfile
#    chmod 775 ${binbuild_dir}/$bfile
#done
cp util/mpirun ${binbuild_dir}
if [ ! -x ${binbuild_dir}/tarch ] ; then
    cp ${top_srcdir}/bin/tarch ${binbuild_dir}
    cp ${top_srcdir}/bin/tdevice ${binbuild_dir}
fi

#mpd
/bin/rm -f ${binbuild_dir}/mpirun.mpd
/bin/rm -f ${binbuild_dir}/startdaemons
MAKE=${MAKE-make}
if [ -d mpid/mpd ] ; then 
    if [ ! -f mpid/mpd/mpdcon ] ; then 
        ( cd mpid/mpd ; ${MAKE} mpdcon )
    fi
    cp mpid/mpd/mpdcon ${binbuild_dir}/mpirun.mpd
    cp mpid/mpd/startdaemons ${binbuild_dir}/startdaemons
fi
