#! /bin/sh
#
# This script derives the meiko routines from the Chameleon ones.  Some editing 
# of the files may be required after this process, but the goal is to 
# fully automate this process.
#
#/bin/cp ../chameleon/*.c .
sed -e '/#define DEVICE_CHAMELEON/d' \
    -e 's/MPID_CH/MPID_MEIKO/g' \
    -e 's/"Chameleon"/"Intel MEIKO"/g' \
    -e 's%/\* #MEIKO DECLARATION# \*/%#include <sys/types.h>\
#include <signal.h>%g' ../chameleon/dmch.h > dmmeiko.h
sed -e 's/MPID_CH/MPID_MEIKO/g' ../chameleon/mpid_bind.h > mpid_bind.h
sed -e 's/MPID_CH/MPID_MEIKO/g' ../chameleon/packets.h > packets.h
sed -e 's/MPID_CH/MPID_MEIKO/g' ../chameleon/channel.h > channel.h
sed -e 's/MPID_CH/MPID_MEIKO/g' ../chameleon/mpiddebug.h > mpiddebug.h
sed -e 's/MPID_CH/MPID_MEIKO/g' ../chameleon/mpidstat.h > mpidstat.h
../chameleon/rmhetero ../chameleon/chevent.c > meikoevent.c
../chameleon/rmhetero ../chameleon/chrecv.c  > meikorecv.c
../chameleon/rmhetero ../chameleon/chsend.c  > meikosend.c
../chameleon/rmhetero ../chameleon/chinit.c  > meikoinit.c
../chameleon/rmhetero ../chameleon/chprobe.c > meikoprobe.c
../chameleon/rmhetero ../chameleon/chsync.c  > meikosync.c
../chameleon/rmhetero ../chameleon/chrndv.c  > meikorndv.c
../chameleon/rmhetero ../chameleon/chdebug.c > meikodebug.c
chmod ug+w *.[ch]
/home/gropp/tools.n/bin/inlinecomm -main -quiet -meiko meikoinit.c
for file in meikoevent.c meikorecv.c meikosend.c meikoprobe.c meikosync.c \
	meikorndv.c meikodebug.c dmmeiko.h \
	packets.h channel.h ; do
    /home/gropp/tools.n/bin/inlinecomm -quiet -meiko $file
done
#
# Change the names MPID_CH to MPID_MEIKO
/bin/rm -f .tmp
for file in *.c ; do
    sed -e 's/MPID_CH/MPID_MEIKO/g' $file > .tmp
    mv .tmp $file
done
#
# Replace dclock with MPID_get_nsec_clock
/bin/rm -f .tmp
sed -e 's/dclock/MPID_get_nsec_clock/g' meikoinit.c > .tmp
/bin/mv .tmp meikoinit.c
