#!/bin/bash

if test ;
 then echo; \
      echo "Building for parallel computing:"; \
      echo;    
 else echo "Package was built without MPI support: Exiting."; \
 exit 1;
fi; 
   
rm -f model.c
rm -f $2

echo "Creating model.c file from $1 ..."
mod $1

shopt -s extglob

if test $2; 
 then target=$2;
 else target=mcsim.${1%.mod?('el')};
fi;

if test -f model.c; then \

	echo; \
	echo "Compiling and linking model with MPI..."; \
	 -DUSEMPI -O3 -w -I/opt/local/include model.c /opt/local/share/mcsim/sim/*.c -o $target -lm -lgsl -lgslcblas -lsundials_cvodes -lsundials_nvecserial -llapack  -Wall; \

fi;

if test -f $target; then \

	echo "Cleaning up ..."; \
	rm -f model.c; \

	echo "Created executable $target with MPI support."; \
	echo; \

fi;
