#!/bin/csh -f 
# Instructions on creating a new device from the ch2 version (bugs 
# are fixed in the ADI-2 version in directory mpid/ch2; the 
# device instantiations are derived from that code by file system 
# symbolic links).
#
set dev = $1
set model = nx
while ($#argv > 0) 
    switch ($1)
    case -echo:
    set echo
    shift
    breaksw

    case -help:
    echo "NewDevice name"
    echo "Make a new device.  The name of the new device will be"
    echo "ch_<name>.  That is, 'NewDevice foo' will create a ch_foo"
    echo "directory with an initial set of files."
    echo "-model name takes information from an existing device."
    exit 1
    breaksw

    case -model:
    shift
    set model = $1
    shift
    breaksw

    default:
    echo "Building new device $1"
    set dev = $1
    shift
    breaksw
    endsw
end
# We use the NX version as the source for chdef.h because that version 
# MAY be different from the Chameleon version (with -model override);
umask 2
if (! -d ch_$dev) mkdir ch_$dev
chmod g+ws ch_$dev
cd ch_$dev
set Upcase = `echo $dev | tr '[a-z]' '[A-Z]'`
sed "s/${model}priv/${dev}priv/g" ../ch_$model/Makefile.in > Makefile.in
cat >chconfig.h <<EOF
#ifndef CHCONFIG
#define CHCONFIG
/* Special configuration information goes here */

/* See ch_p4 for definitions for heterogeneity */
#define MPID_CommInit(oldcomm,newcomm) MPI_SUCCESS
#define MPID_CommFree(comm)            MPI_SUCCESS

/* See ch_mpl for definitions for limited buffering */
#endif
EOF
cp ../ch_$model/chdef.h .
cp ../ch_$model/mpid_time.h .
ln -s ../ch2/mpiddevbase.h mpiddev.h
ln -s ../util/mprerr.c mprerr.c
cat <<EOF
You should modify ch_$dev/Makefile.in to use the correct ch files (for
example, choosing blocking eager (chbeager) over nonblocking eager
(chneager)).  Modify ch_$dev/mpid_time.h to use the correct time routines
for this device.  Modify ch_$dev/chconfig.h and chdef.h for the correct
Channel device definitions.

If you are NOT using the channel device, you can delete chdef.h and you
MUST replace mpiddev.h (which is a link to mpid/ch2/mpiddevbase.h).

You will probably need a ${dev}priv.c file.

You can add your new device to mpirun by creating an mpirun.$dev.in file
in mpich/util .

You may find that some routines are missing.  Look for them in mpid/ch2;
it may be that you need to establish links to them.  NewDevice simply
creates a copy of ch_$model; each device has a different set of requirements.
Shared memory versions should consider ch_shmem or ch_lfshmem.
EOF
