#! /bin/sh
#
# For "inplace" usage of config.status, we need srcdir to be "."
# Hmmmm
top_srcdir=/usr/ports/net/mpich/work/mpich-1.2.3
PREFIX=/usr/local/mpich
bindir=/usr/local/mpich/bin
binbuild_dir=/usr/local/mpich/bin
MPIR_HOME=/usr/local/mpich
#
CONFIG_FILES=""
destpair=""
for arg 
do
    if [ -s $arg.in ] ; then 
        CONFIG_FILES="$CONFIG_FILES $arg" 
    elif [ -s ${top_srcdir}/$arg.in ] ; then
        CONFIG_FILES="$CONFIG_FILES ${top_srcdir}/$arg" 
	destpair="$destpair ${top_srcdir}/$arg::$arg"
    else
        echo "Cannot find file $arg"
	exit 1
    fi
done
export CONFIG_FILES
#
# I once made a suggestion to do
#if [ -n "$PREFIX" ] ; then 
#    /bin/rm -f .t1 
#    cat $file | sed -e "s%@INSTALL_DIR@%$PREFIX%g" > .t1
#    mv .t1 $file
#fi
# 
# but I've lost the example that made me suggest this.
# 
# First, try the device/architecture specific config.status
# Our first try is for the mpireconfig.dat in the same directory as this script
# came from if it is specifically set.
mydir=`echo $0 | sed 's%/[^/][^/]*$%%'`
if [ -x $mydir/mpireconfig.dat ] ; then
    CONFIG_HEADERS=""
    export CONFIG_HEADERS
    $mydir/mpireconfig.dat 
elif [ -x ${bindir}/mpireconfig.dat ] ; then
    CONFIG_HEADERS=""
    export CONFIG_HEADERS
    ${bindir}/mpireconfig.dat 
elif [ -x ${binbuild_dir}/mpireconfig.dat ] ; then
    CONFIG_HEADERS=""
    export CONFIG_HEADERS
    ${binbuild_dir}/mpireconfig.dat 
elif [ -x ${MPIR_HOME}/config.status ] ; then
    # Export the location of mpichconf.h.in
    #CONFIG_HEADERS="${MPIR_HOME}/mpichconf.h"
    CONFIG_HEADERS=""
    export CONFIG_HEADERS
    ${MPIR_HOME}/config.status
else
    echo "An mpireconfig.dat file is needed to perform a reconfig of a file"
    exit 1
fi
if [ -n "$destpair" ] ; then
    # Move created files to their final places
    for pair in $destpair ; do
	stmt=`echo "$pair" | sed 's/::/ /'`
        eval mv $stmt
    done
fi
