#! /bin/csh

echo NORMA installation started

echo Refal building...
cd refal/src
make install
if ( $status != "0" ) then
    echo Error building refal
    exit 1
endif

setenv REFAL_HOME `pwd`
if ( $status != "0" ) then
    echo Error set REFAL_HOME
    exit 1
endif

cd ../..

echo Norma compiler building...
cd norma
make
if ( $status != "0" ) then
    echo Error building Norma compiler
    exit 1
endif

mkdir ../bin
mv norma ../bin
cd ..

echo Norma configurator building...
cd conf
make
if ( $status != "0" ) then
    echo Error building Norma configurator
    exit 1
endif

mv normacnf ../bin
mv normalib.c ../bin
mv normalib.for ../bin
cd ..

echo Norma debugger building...
cd debugger
make
if ( $status != "0" ) then
    echo Error building Norma configurator
    exit 1
endif

mv monitor ../bin
mv gated ../bin
mkdir ../lib
mv libndebug.a ../lib
mkdir ../include
cp MonitorConnect.h ../include
cp CommonMonitorDefs.h ../include
cd ..

#echo Intermedia files deleting... 
#rm -Rf refal
#rm -Rf norma
#rm -Rf conf
#rm -Rf debugger

echo Norma installation is complete successfuly!
echo "Do you want to run the Norma test (y/n)?"

if ( $< == "y" ) then
cd test
../bin/norma summa.hop mpi
if ( $status != "0" ) then
    echo Error Compiling test!
    exit 1
endif

../bin/normacnf summa.fmp /mpi
if ( $status != "0" ) then
    echo Error Configuring test!
    exit 1
endif

echo Test build successfully. You may compile and run the MPI program test/summa.f
cd ..
endif #testing

exit 0
