#!/bin/sh

if [ $# -ne 1 ]
then
	echo "usage: updateMake <LINK src directory name>"
	echo "   ex: updateMake basic"
	exit 1
fi

if [ "$LINK_BASE" = "" ]
then
        echo "error: LINK_BASE environment variable not set"
	exit 1
fi

cd $LINK_BASE/src/$1

mkfl_name="Make.$1"

cd templateWrappers

t_files=`ls *.cc|sed s%\.cc%\.o%` 
t_files=`echo  $t_files | sed 's% %\\\\ %g'`

cd ../autogenSTkMethods

a_files=`ls *.cc|sed s%\.cc%\.o%` 
a_files=`echo  $a_files | sed 's% %\\\\ %g'`

cd ../manualSTkMethods

m_files=`ls *.cc|sed s%\.cc%\.o%` 
m_files=`echo  $m_files | sed 's% %\\\\ %g'`

cd ..

all_files=`ls templateWrappers/*.cc autogenSTkMethods/*.cc manualSTkMethods/*.cc | sed s%\.cc%\.o%`
all_files=`echo  $all_files | sed 's% %\\\\ %g'`


sed -e "s%^T_OBJECTS.*$%T_OBJECTS = $t_files%" $mkfl_name > /tmp/d
mv /tmp/d $mkfl_name
sed -e "s%^A_OBJECTS.*$%A_OBJECTS = $a_files%" $mkfl_name > /tmp/d
mv /tmp/d $mkfl_name
sed -e "s%^M_OBJECTS.*$%M_OBJECTS = $m_files%" $mkfl_name > /tmp/d
mv /tmp/d $mkfl_name

sed -e "s%^EXTRA_OBJECTS.*$%EXTRA_OBJECTS = $all_files%" $mkfl_name > /tmp/d
mv /tmp/d $mkfl_name
