#!/bin/sh
if [ $# -ne 1 ]
then
	echo "usage: genInitFiles <LINK src directory name>"
	echo "   ex: genInitFiles basic"
	exit 1
fi
if [ "$LINK_BASE" = "" ]
then
        echo "error: LINK_BASE environment variable not set"
	exit 1
fi
dir=$LINK_BASE/src/$1
ccfile=$LINK_BASE/src/wrappers/${1}STkInit.cpp
hfile=$LINK_BASE/include/LINK/wrappers/${1}STkInit.h
if [ -f $hfile ]
then
	rm $hfile
fi
if [ -f $ccfile ]
then
	rm $ccfile
fi
echo "#ifndef ${1}STK_INIT_H" >> $hfile
echo "#define ${1}STK_INIT_H" >> $hfile
echo >> $hfile
echo "#include<stk.h>" >> $hfile
echo >> $hfile
echo "void STk_${1}_init(void);" >> $hfile
echo "void STk_${1}_cleanup(void);" >> $hfile
echo >> $hfile
echo "#endif" >> $hfile
echo "#include<LINK/wrappers/${1}STkInit.h>" >> $ccfile
echo "#include<iostream.h>" >> $ccfile
echo >> $ccfile
cd $LINK_BASE/bin
a_files=`cat ${1}InitFileOrder`

#a_files=`ls _*STkInit.cpp|sed s%STkInit\.cpp%%` 
# had to dump the above due to changes in ls between linux versions!


for i in $a_files
do
	echo "PRIMITIVE STk_init_${i}();" >> $ccfile
done
for i in $a_files
do
	echo "PRIMITIVE STk_init_methods_${i}();" >> $ccfile
done
echo >> $ccfile
echo "void STk_${1}_init(void)" >> $ccfile
echo "{" >> $ccfile
for i in $a_files
do
	echo "	STk_init_${i}();" >> $ccfile
done
for i in $a_files
do
	echo "	STk_init_methods_${i}();" >> $ccfile
done
echo "}" >> $ccfile
echo  >> $ccfile
echo "void STk_${1}_cleanup(void)" >> $ccfile
echo "{" >> $ccfile
echo "}" >> $ccfile
