#! /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_p4mpd."
    exit 1
fi
if [ -z "${MAKE}" ] ; then MAKE=make ; fi
#
if [ -s mpid/server/Makefile ] ; then 
    ( cd mpid/server ; $MAKE serv_p4 ; )
fi
cp util/tstmachines ${binbuild_dir}/tstmachines
/bin/rm -f ${binbuild_dir}/mpirun

MPIRUNLIST=`cat ${srcdir}/mpid/ch_p4/mpirun.lst`
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
