#!/bin/bash

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 ..."; \
	/usr/bin/clang -O3 -I/opt/local/include -L/opt/local/lib -I/opt/local/include -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk -pipe -Os -I/opt/local/libexec/sundials2/include -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk -arch arm64 -L/opt/local/lib -Wl,-headerpad_max_install_names -L/opt/local/libexec/sundials2/lib -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk -arch arm64 model.c -lmcsim -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"; \
	echo; \

fi;
