#!/bin/sh
#
# Utility for compressing source files into 1 directory via links.
#
#   Usage:    flatten [directory]
#
#        If directory is ommited, this creates a directory called 'Obj'.
#
# Note: The makefile associated with the resulting flattened directory
#       uses `depends.ml'. This file assumes that the source code is
#       in a directory 'Obj'. If there is no such directory, things don't
#       work. Thus, the first time this utility should be run without
#       specifying a directory. Subsequent invocations can then be used
#       to create additional Obj directories.
#
DEST=Obj_$1
if test `expr $DEST` = `expr Obj_`
   then
   DEST=Obj
fi
echo flatten into $DEST
DIRECTORIES="Coarsen Comm FEGrid Krylov Main Operator Smoother Utils"
mkdir ../$DEST
cd ../$DEST
for i in $DIRECTORIES
do
   echo $i
   for j in ../src/$i/*.*[ch]
   do
     FILE=`echo $j | sed "s,.*/,,"`
     ln -s $j $FILE
   done

   CURRDIR="../src/$i/*.cpp"
   for j in $CURRDIR
   do
     temp="xx${j}xx"
     SRC=`echo $temp | sed "s/\.\.\/src\/$i\/\*\.cpp//"`
     if test `expr ${SRC}` != 'xxxx'
     then
        FILE=`echo $j | sed "s,.*/,,"`
        ln -s $j $FILE
     fi
   done
done
ln -s ../src/Include/ml_include.h ml_include.h
ln -s ../src/Include/ml_defs.h ml_defs.h
ln -s ../src/Include/ml_common.h ml_common.h
ln -s ../etc/flat_Makefile classicMakefile
